import { ByteCursor } from './binary.js';
export function decodeAccountData(raw, decodeInner) {
    if (raw.length === 0)
        return { initialized: false, data: null };
    const cursor = new ByteCursor(raw);
    const initialized = cursor.readBool();
    if (!initialized) {
        return { initialized: false, data: null };
    }
    return { initialized: true, data: decodeInner(cursor) };
}
export function decodeDiscriminatorPrefixed(cursor, expectedDiscriminator, decodeInner) {
    const discriminator = cursor.readBytes(expectedDiscriminator.length);
    const mismatch = discriminator.some((value, i) => value !== expectedDiscriminator[i]);
    if (mismatch) {
        throw new Error('Invalid discriminator');
    }
    return decodeInner(cursor);
}
//# sourceMappingURL=account-data.js.map