All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hedera.hapi.node.state.token.codec.AccountProtoCodec Maven / Gradle / Ivy

There is a newer version: 0.54.0
Show newest version
package com.hedera.hapi.node.state.token.codec;

import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.EOFException;
import java.io.IOException;
import java.nio.*;
import java.nio.charset.*;
import java.util.*;
import edu.umd.cs.findbugs.annotations.NonNull;

import com.hedera.hapi.node.state.token.Account;

import com.hedera.hapi.node.base.*;
import com.hedera.hapi.node.base.codec.*;
import com.hedera.hapi.node.state.token.*;
import com.hedera.hapi.node.state.token.schema.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.buffer.*;
import java.util.*;

import static com.hedera.hapi.node.state.token.schema.AccountSchema.*;
import static com.hedera.pbj.runtime.ProtoWriterTools.*;
import static com.hedera.pbj.runtime.ProtoParserTools.*;
import static com.hedera.pbj.runtime.ProtoConstants.*;

/**
 * Protobuf Codec for Account model object. Generated based on protobuf schema.
 */
public final class AccountProtoCodec implements Codec {
    
    /** Constant for an unset oneof for staked_id */
    public static final OneOf STAKED_ID_UNSET = new OneOf<>(Account.StakedIdOneOfType.UNSET,null);

        /**
     * Parses a Account object from ProtoBuf bytes in a {@link ReadableSequentialData}. Throws if in strict mode ONLY.
     *
     * @param input The data input to parse data from, it is assumed to be in a state ready to read with position at start
     *              of data to read and limit set at the end of data to read. The data inputs limit will be changed by this
     *              method. If there are no bytes remaining in the data input,
     *              then the method also returns immediately.
     * @param strictMode when {@code true}, the parser errors out on unknown fields; otherwise they'll be simply skipped.
     * @param maxDepth a ParseException will be thrown if the depth of nested messages exceeds the maxDepth value.
     * @return Parsed Account model object or null if data input was null or empty
     * @throws ParseException If parsing fails
     */
    public @NonNull Account parse(
            @NonNull final ReadableSequentialData input,
            final boolean strictMode,
            final int maxDepth) throws ParseException {
        if (maxDepth < 0) {
            throw new ParseException("Reached maximum allowed depth of nested messages");
        }
        try {
            // -- TEMP STATE FIELDS --------------------------------------
                AccountID temp_account_id = null;
        Bytes temp_alias = Bytes.EMPTY;
        Key temp_key = null;
        long temp_expiration_second = 0;
        long temp_tinybar_balance = 0;
        String temp_memo = "";
        boolean temp_deleted = false;
        long temp_staked_to_me = 0;
        long temp_stake_period_start = 0;
        OneOf temp_staked_id = STAKED_ID_UNSET;
        boolean temp_decline_reward = false;
        boolean temp_receiver_sig_required = false;
        TokenID temp_head_token_id = null;
        NftID temp_head_nft_id = null;
        long temp_head_nft_serial_number = 0;
        long temp_number_owned_nfts = 0;
        int temp_max_auto_associations = 0;
        int temp_used_auto_associations = 0;
        int temp_number_associations = 0;
        boolean temp_smart_contract = false;
        int temp_number_positive_balances = 0;
        long temp_ethereum_nonce = 0;
        long temp_stake_at_start_of_last_rewarded_period = 0;
        AccountID temp_auto_renew_account_id = null;
        long temp_auto_renew_seconds = 0;
        int temp_contract_kv_pairs_number = 0;
        List temp_crypto_allowances = Collections.emptyList();
        List temp_approve_for_all_nft_allowances = Collections.emptyList();
        List temp_token_allowances = Collections.emptyList();
        int temp_number_treasury_titles = 0;
        boolean temp_expired_and_pending_removal = false;
        Bytes temp_first_contract_storage_key = Bytes.EMPTY;
        PendingAirdropId temp_head_pending_airdrop_id = null;
        long temp_number_pending_airdrops = 0;
    
                        // -- PARSE LOOP ---------------------------------------------
                // Continue to parse bytes out of the input stream until we get to the end.
                while (input.hasRemaining()) {
                    // Note: ReadableStreamingData.hasRemaining() won't flip to false
                    // until the end of stream is actually hit with a read operation.
                    // So we catch this exception here and **only** here, because an EOFException
                    // anywhere else suggests that we're processing malformed data and so
                    // we must re-throw the exception then.
                    final int tag;
                    try {
                        // Read the "tag" byte which gives us the field number for the next field to read
                        // and the wire type (way it is encoded on the wire).
                        tag = input.readVarInt(false);
                    } catch (EOFException e) {
                        // There's no more fields. Stop the parsing loop.
                        break;
                    }
        
                    // The field is the top 5 bits of the byte. Read this off
                    final int field = tag >>> TAG_FIELD_OFFSET;
        
                    // Ask the Schema to inform us what field this represents.
                    final var f = getField(field);
        
                    // Given the wire type and the field type, parse the field
                    switch (tag) {
                        case 10 /* type=2 [MESSAGE] field=1 [account_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountID value;
                            if (messageLength == 0) {
                            	value = AccountID.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("account_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountID.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_account_id = value;
                        }
                        case 18 /* type=2 [BYTES] field=2 [alias] */ -> {
                            final var value = readBytes(input, 2097152);
                            temp_alias = value;
                        }
                        case 26 /* type=2 [MESSAGE] field=3 [key] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final Key value;
                            if (messageLength == 0) {
                            	value = Key.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("key size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = Key.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_key = value;
                        }
                        case 32 /* type=0 [INT64] field=4 [expiration_second] */ -> {
                            final var value = readInt64(input);
                            temp_expiration_second = value;
                        }
                        case 40 /* type=0 [INT64] field=5 [tinybar_balance] */ -> {
                            final var value = readInt64(input);
                            temp_tinybar_balance = value;
                        }
                        case 50 /* type=2 [STRING] field=6 [memo] */ -> {
                            final var value = readString(input, 2097152);
                            temp_memo = value;
                        }
                        case 56 /* type=0 [BOOL] field=7 [deleted] */ -> {
                            final var value = readBool(input);
                            temp_deleted = value;
                        }
                        case 64 /* type=0 [INT64] field=8 [staked_to_me] */ -> {
                            final var value = readInt64(input);
                            temp_staked_to_me = value;
                        }
                        case 72 /* type=0 [INT64] field=9 [stake_period_start] */ -> {
                            final var value = readInt64(input);
                            temp_stake_period_start = value;
                        }
                        case 82 /* type=2 [MESSAGE] field=10 [staked_account_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountID value;
                            if (messageLength == 0) {
                            	value = AccountID.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("staked_account_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountID.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_staked_id =  new OneOf<>(Account.StakedIdOneOfType.STAKED_ACCOUNT_ID, value);
                        }
                        case 88 /* type=0 [INT64] field=11 [staked_node_id] */ -> {
                            final var value = readInt64(input);
                            temp_staked_id =  new OneOf<>(Account.StakedIdOneOfType.STAKED_NODE_ID, value);
                        }
                        case 96 /* type=0 [BOOL] field=12 [decline_reward] */ -> {
                            final var value = readBool(input);
                            temp_decline_reward = value;
                        }
                        case 104 /* type=0 [BOOL] field=13 [receiver_sig_required] */ -> {
                            final var value = readBool(input);
                            temp_receiver_sig_required = value;
                        }
                        case 114 /* type=2 [MESSAGE] field=14 [head_token_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final TokenID value;
                            if (messageLength == 0) {
                            	value = TokenID.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("head_token_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = TokenID.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_head_token_id = value;
                        }
                        case 122 /* type=2 [MESSAGE] field=15 [head_nft_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final NftID value;
                            if (messageLength == 0) {
                            	value = NftID.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("head_nft_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = NftID.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_head_nft_id = value;
                        }
                        case 128 /* type=0 [INT64] field=16 [head_nft_serial_number] */ -> {
                            final var value = readInt64(input);
                            temp_head_nft_serial_number = value;
                        }
                        case 136 /* type=0 [INT64] field=17 [number_owned_nfts] */ -> {
                            final var value = readInt64(input);
                            temp_number_owned_nfts = value;
                        }
                        case 144 /* type=0 [INT32] field=18 [max_auto_associations] */ -> {
                            final var value = readInt32(input);
                            temp_max_auto_associations = value;
                        }
                        case 152 /* type=0 [INT32] field=19 [used_auto_associations] */ -> {
                            final var value = readInt32(input);
                            temp_used_auto_associations = value;
                        }
                        case 160 /* type=0 [INT32] field=20 [number_associations] */ -> {
                            final var value = readInt32(input);
                            temp_number_associations = value;
                        }
                        case 168 /* type=0 [BOOL] field=21 [smart_contract] */ -> {
                            final var value = readBool(input);
                            temp_smart_contract = value;
                        }
                        case 176 /* type=0 [INT32] field=22 [number_positive_balances] */ -> {
                            final var value = readInt32(input);
                            temp_number_positive_balances = value;
                        }
                        case 184 /* type=0 [INT64] field=23 [ethereum_nonce] */ -> {
                            final var value = readInt64(input);
                            temp_ethereum_nonce = value;
                        }
                        case 192 /* type=0 [INT64] field=24 [stake_at_start_of_last_rewarded_period] */ -> {
                            final var value = readInt64(input);
                            temp_stake_at_start_of_last_rewarded_period = value;
                        }
                        case 202 /* type=2 [MESSAGE] field=25 [auto_renew_account_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountID value;
                            if (messageLength == 0) {
                            	value = AccountID.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("auto_renew_account_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountID.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_auto_renew_account_id = value;
                        }
                        case 208 /* type=0 [INT64] field=26 [auto_renew_seconds] */ -> {
                            final var value = readInt64(input);
                            temp_auto_renew_seconds = value;
                        }
                        case 216 /* type=0 [INT32] field=27 [contract_kv_pairs_number] */ -> {
                            final var value = readInt32(input);
                            temp_contract_kv_pairs_number = value;
                        }
                        case 226 /* type=2 [MESSAGE] field=28 [crypto_allowances] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountCryptoAllowance value;
                            if (messageLength == 0) {
                            	value = AccountCryptoAllowance.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("crypto_allowances size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountCryptoAllowance.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            if (temp_crypto_allowances.size() >= 2097152) {
                        		throw new ParseException("crypto_allowances size " + temp_crypto_allowances.size() + " is greater than max " + 2097152);
                        	}
                        	temp_crypto_allowances = addToList(temp_crypto_allowances,value);
                        }
                        case 234 /* type=2 [MESSAGE] field=29 [approve_for_all_nft_allowances] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountApprovalForAllAllowance value;
                            if (messageLength == 0) {
                            	value = AccountApprovalForAllAllowance.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("approve_for_all_nft_allowances size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountApprovalForAllAllowance.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            if (temp_approve_for_all_nft_allowances.size() >= 2097152) {
                        		throw new ParseException("approve_for_all_nft_allowances size " + temp_approve_for_all_nft_allowances.size() + " is greater than max " + 2097152);
                        	}
                        	temp_approve_for_all_nft_allowances = addToList(temp_approve_for_all_nft_allowances,value);
                        }
                        case 242 /* type=2 [MESSAGE] field=30 [token_allowances] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final AccountFungibleTokenAllowance value;
                            if (messageLength == 0) {
                            	value = AccountFungibleTokenAllowance.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("token_allowances size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = AccountFungibleTokenAllowance.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            if (temp_token_allowances.size() >= 2097152) {
                        		throw new ParseException("token_allowances size " + temp_token_allowances.size() + " is greater than max " + 2097152);
                        	}
                        	temp_token_allowances = addToList(temp_token_allowances,value);
                        }
                        case 248 /* type=0 [UINT32] field=31 [number_treasury_titles] */ -> {
                            final var value = readUint32(input);
                            temp_number_treasury_titles = value;
                        }
                        case 256 /* type=0 [BOOL] field=32 [expired_and_pending_removal] */ -> {
                            final var value = readBool(input);
                            temp_expired_and_pending_removal = value;
                        }
                        case 266 /* type=2 [BYTES] field=33 [first_contract_storage_key] */ -> {
                            final var value = readBytes(input, 2097152);
                            temp_first_contract_storage_key = value;
                        }
                        case 274 /* type=2 [MESSAGE] field=34 [head_pending_airdrop_id] */ -> {
                            final var messageLength = input.readVarInt(false);
                            final PendingAirdropId value;
                            if (messageLength == 0) {
                            	value = PendingAirdropId.DEFAULT;
                            } else {
                            	if (messageLength > 2097152) {
                            		throw new ParseException("head_pending_airdrop_id size " + messageLength + " is greater than max " + 2097152);
                            	}
                            	final var limitBefore = input.limit();
                            	// Make sure that we have enough bytes in the message
                            	// to read the subObject.
                            	// If the buffer is truncated on the boundary of a subObject,
                            	// we will not throw.
                            	final var startPos = input.position();
                            	try {
                            		if ((startPos + messageLength) > limitBefore) {
                            			throw new BufferUnderflowException();
                            		}
                            		input.limit(startPos + messageLength);
                            		value = PendingAirdropId.PROTOBUF.parse(input, strictMode, maxDepth - 1);
                            		// Make sure we read the full number of bytes. for the types
                            		if ((startPos + messageLength) != input.position()) {
                            			throw new BufferOverflowException();
                            		}
                            	} finally {
                            		input.limit(limitBefore);
                            	}
                            }
                            temp_head_pending_airdrop_id = value;
                        }
                        case 280 /* type=0 [UINT64] field=35 [number_pending_airdrops] */ -> {
                            final var value = readUint64(input);
                            temp_number_pending_airdrops = value;
                        }
        
                        default -> {
                            // The wire type is the bottom 3 bits of the byte. Read that off
                            final int wireType = tag & TAG_WIRE_TYPE_MASK;
                            // handle error cases here, so we do not do if statements in normal loop
                            // Validate the field number is valid (must be > 0)
                            if (field == 0) {
                                throw new IOException("Bad protobuf encoding. We read a field value of "
                                    + field);
                            }
                            // Validate the wire type is valid (must be >=0 && <= 5).
                            // Otherwise we cannot parse this.
                            // Note: it is always >= 0 at this point (see code above where it is defined).
                            if (wireType > 5) {
                                throw new IOException("Cannot understand wire_type of " + wireType);
                            }
                            // It may be that the parser subclass doesn't know about this field
                            if (f == null) {
                                if (strictMode) {
                                    // Since we are parsing is strict mode, this is an exceptional condition.
                                    throw new UnknownFieldException(field);
                                } else {
                                    // We just need to read off the bytes for this field to skip it
                                    // and move on to the next one.
                                    skipField(input, ProtoConstants.get(wireType), 2097152);
                                }
                            } else {
                                throw new IOException("Bad tag [" + tag + "], field [" + field
                                        + "] wireType [" + wireType + "]");
                            }
                        }
                    }
                }
    
            return new Account(temp_account_id, temp_alias, temp_key, temp_expiration_second, temp_tinybar_balance, temp_memo, temp_deleted, temp_staked_to_me, temp_stake_period_start, temp_staked_id, temp_decline_reward, temp_receiver_sig_required, temp_head_token_id, temp_head_nft_id, temp_head_nft_serial_number, temp_number_owned_nfts, temp_max_auto_associations, temp_used_auto_associations, temp_number_associations, temp_smart_contract, temp_number_positive_balances, temp_ethereum_nonce, temp_stake_at_start_of_last_rewarded_period, temp_auto_renew_account_id, temp_auto_renew_seconds, temp_contract_kv_pairs_number, temp_crypto_allowances, temp_approve_for_all_nft_allowances, temp_token_allowances, temp_number_treasury_titles, temp_expired_and_pending_removal, temp_first_contract_storage_key, temp_head_pending_airdrop_id, temp_number_pending_airdrops);
        } catch (final Exception anyException) {
            if (anyException instanceof ParseException parseException) {
                throw parseException;
            }
            throw new ParseException(anyException);
        }
    }

        /**
     * Write out a Account model to output stream in protobuf format.
     *
     * @param data The input model data to write
     * @param out The output stream to write to
     * @throws IOException If there is a problem writing
     */
    public void write(@NonNull Account data, @NonNull final WritableSequentialData out) throws IOException {
            // [1] - account_id
        writeMessage(out, ACCOUNT_ID, data.accountId(), com.hedera.hapi.node.base.AccountID.PROTOBUF::write, com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [2] - alias
        writeBytes(out, ALIAS, data.alias(), true);
        // [3] - key
        writeMessage(out, KEY, data.key(), com.hedera.hapi.node.base.Key.PROTOBUF::write, com.hedera.hapi.node.base.Key.PROTOBUF::measureRecord);
        // [4] - expiration_second
        writeLong(out, EXPIRATION_SECOND, data.expirationSecond(), true);
        // [5] - tinybar_balance
        writeLong(out, TINYBAR_BALANCE, data.tinybarBalance(), true);
        // [6] - memo
        writeString(out, MEMO, data.memo(), true);
        // [7] - deleted
        writeBoolean(out, DELETED, data.deleted(), true);
        // [8] - staked_to_me
        writeLong(out, STAKED_TO_ME, data.stakedToMe(), true);
        // [9] - stake_period_start
        writeLong(out, STAKE_PERIOD_START, data.stakePeriodStart(), true);
        // [10] - staked_account_id
        if (data.stakedId().kind() == Account.StakedIdOneOfType.STAKED_ACCOUNT_ID)
        writeMessage(out, STAKED_ACCOUNT_ID, data.stakedId().as(), com.hedera.hapi.node.base.AccountID.PROTOBUF::write, com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [11] - staked_node_id
        if (data.stakedId().kind() == Account.StakedIdOneOfType.STAKED_NODE_ID)
        writeLong(out, STAKED_NODE_ID, data.stakedId().as(), true);
        // [12] - decline_reward
        writeBoolean(out, DECLINE_REWARD, data.declineReward(), true);
        // [13] - receiver_sig_required
        writeBoolean(out, RECEIVER_SIG_REQUIRED, data.receiverSigRequired(), true);
        // [14] - head_token_id
        writeMessage(out, HEAD_TOKEN_ID, data.headTokenId(), com.hedera.hapi.node.base.TokenID.PROTOBUF::write, com.hedera.hapi.node.base.TokenID.PROTOBUF::measureRecord);
        // [15] - head_nft_id
        writeMessage(out, HEAD_NFT_ID, data.headNftId(), com.hedera.hapi.node.base.NftID.PROTOBUF::write, com.hedera.hapi.node.base.NftID.PROTOBUF::measureRecord);
        // [16] - head_nft_serial_number
        writeLong(out, HEAD_NFT_SERIAL_NUMBER, data.headNftSerialNumber(), true);
        // [17] - number_owned_nfts
        writeLong(out, NUMBER_OWNED_NFTS, data.numberOwnedNfts(), true);
        // [18] - max_auto_associations
        writeInteger(out, MAX_AUTO_ASSOCIATIONS, data.maxAutoAssociations(), true);
        // [19] - used_auto_associations
        writeInteger(out, USED_AUTO_ASSOCIATIONS, data.usedAutoAssociations(), true);
        // [20] - number_associations
        writeInteger(out, NUMBER_ASSOCIATIONS, data.numberAssociations(), true);
        // [21] - smart_contract
        writeBoolean(out, SMART_CONTRACT, data.smartContract(), true);
        // [22] - number_positive_balances
        writeInteger(out, NUMBER_POSITIVE_BALANCES, data.numberPositiveBalances(), true);
        // [23] - ethereum_nonce
        writeLong(out, ETHEREUM_NONCE, data.ethereumNonce(), true);
        // [24] - stake_at_start_of_last_rewarded_period
        writeLong(out, STAKE_AT_START_OF_LAST_REWARDED_PERIOD, data.stakeAtStartOfLastRewardedPeriod(), true);
        // [25] - auto_renew_account_id
        writeMessage(out, AUTO_RENEW_ACCOUNT_ID, data.autoRenewAccountId(), com.hedera.hapi.node.base.AccountID.PROTOBUF::write, com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [26] - auto_renew_seconds
        writeLong(out, AUTO_RENEW_SECONDS, data.autoRenewSeconds(), true);
        // [27] - contract_kv_pairs_number
        writeInteger(out, CONTRACT_KV_PAIRS_NUMBER, data.contractKvPairsNumber(), true);
        // [28] - crypto_allowances
        writeMessageList(out, CRYPTO_ALLOWANCES, data.cryptoAllowances(), com.hedera.hapi.node.state.token.AccountCryptoAllowance.PROTOBUF::write, com.hedera.hapi.node.state.token.AccountCryptoAllowance.PROTOBUF::measureRecord);
        // [29] - approve_for_all_nft_allowances
        writeMessageList(out, APPROVE_FOR_ALL_NFT_ALLOWANCES, data.approveForAllNftAllowances(), com.hedera.hapi.node.state.token.AccountApprovalForAllAllowance.PROTOBUF::write, com.hedera.hapi.node.state.token.AccountApprovalForAllAllowance.PROTOBUF::measureRecord);
        // [30] - token_allowances
        writeMessageList(out, TOKEN_ALLOWANCES, data.tokenAllowances(), com.hedera.hapi.node.state.token.AccountFungibleTokenAllowance.PROTOBUF::write, com.hedera.hapi.node.state.token.AccountFungibleTokenAllowance.PROTOBUF::measureRecord);
        // [31] - number_treasury_titles
        writeInteger(out, NUMBER_TREASURY_TITLES, data.numberTreasuryTitles(), true);
        // [32] - expired_and_pending_removal
        writeBoolean(out, EXPIRED_AND_PENDING_REMOVAL, data.expiredAndPendingRemoval(), true);
        // [33] - first_contract_storage_key
        writeBytes(out, FIRST_CONTRACT_STORAGE_KEY, data.firstContractStorageKey(), true);
        // [34] - head_pending_airdrop_id
        writeMessage(out, HEAD_PENDING_AIRDROP_ID, data.headPendingAirdropId(), com.hedera.hapi.node.base.PendingAirdropId.PROTOBUF::write, com.hedera.hapi.node.base.PendingAirdropId.PROTOBUF::measureRecord);
        // [35] - number_pending_airdrops
        writeLong(out, NUMBER_PENDING_AIRDROPS, data.numberPendingAirdrops(), true);
    
    }

        /**
     * Reads from this data input the length of the data within the input. The implementation may
     * read all the data, or just some special serialized data, as needed to find out the length of
     * the data.
     *
     * @param input The input to use
     * @return The length of the data item in the input
     * @throws ParseException If parsing fails
     */
    public int measure(@NonNull final ReadableSequentialData input) throws ParseException {
        final var start = input.position();
        parse(input);
        final var end = input.position();
        return (int)(end - start);
    }

        /**
     * Compute number of bytes that would be written when calling {@code write()} method.
     *
     * @param data The input model data to measure write bytes for
     * @return The length in bytes that would be written
     */
    public int measureRecord(Account data) {
        int size = 0;
            // [1] - account_id
        size += sizeOfMessage(ACCOUNT_ID, data.accountId(), com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [2] - alias
        size += sizeOfBytes(ALIAS, data.alias(), true);
        // [3] - key
        size += sizeOfMessage(KEY, data.key(), com.hedera.hapi.node.base.Key.PROTOBUF::measureRecord);
        // [4] - expiration_second
        size += sizeOfLong(EXPIRATION_SECOND, data.expirationSecond(), true);
        // [5] - tinybar_balance
        size += sizeOfLong(TINYBAR_BALANCE, data.tinybarBalance(), true);
        // [6] - memo
        size += sizeOfString(MEMO, data.memo(), true);
        // [7] - deleted
        size += sizeOfBoolean(DELETED, data.deleted(), true);
        // [8] - staked_to_me
        size += sizeOfLong(STAKED_TO_ME, data.stakedToMe(), true);
        // [9] - stake_period_start
        size += sizeOfLong(STAKE_PERIOD_START, data.stakePeriodStart(), true);
        // [10] - staked_account_id
        if (data.stakedId().kind() == Account.StakedIdOneOfType.STAKED_ACCOUNT_ID)
        size += sizeOfMessage(STAKED_ACCOUNT_ID, data.stakedId().as(), com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [11] - staked_node_id
        if (data.stakedId().kind() == Account.StakedIdOneOfType.STAKED_NODE_ID)
        size += sizeOfLong(STAKED_NODE_ID, data.stakedId().as(), true);
        // [12] - decline_reward
        size += sizeOfBoolean(DECLINE_REWARD, data.declineReward(), true);
        // [13] - receiver_sig_required
        size += sizeOfBoolean(RECEIVER_SIG_REQUIRED, data.receiverSigRequired(), true);
        // [14] - head_token_id
        size += sizeOfMessage(HEAD_TOKEN_ID, data.headTokenId(), com.hedera.hapi.node.base.TokenID.PROTOBUF::measureRecord);
        // [15] - head_nft_id
        size += sizeOfMessage(HEAD_NFT_ID, data.headNftId(), com.hedera.hapi.node.base.NftID.PROTOBUF::measureRecord);
        // [16] - head_nft_serial_number
        size += sizeOfLong(HEAD_NFT_SERIAL_NUMBER, data.headNftSerialNumber(), true);
        // [17] - number_owned_nfts
        size += sizeOfLong(NUMBER_OWNED_NFTS, data.numberOwnedNfts(), true);
        // [18] - max_auto_associations
        size += sizeOfInteger(MAX_AUTO_ASSOCIATIONS, data.maxAutoAssociations(), true);
        // [19] - used_auto_associations
        size += sizeOfInteger(USED_AUTO_ASSOCIATIONS, data.usedAutoAssociations(), true);
        // [20] - number_associations
        size += sizeOfInteger(NUMBER_ASSOCIATIONS, data.numberAssociations(), true);
        // [21] - smart_contract
        size += sizeOfBoolean(SMART_CONTRACT, data.smartContract(), true);
        // [22] - number_positive_balances
        size += sizeOfInteger(NUMBER_POSITIVE_BALANCES, data.numberPositiveBalances(), true);
        // [23] - ethereum_nonce
        size += sizeOfLong(ETHEREUM_NONCE, data.ethereumNonce(), true);
        // [24] - stake_at_start_of_last_rewarded_period
        size += sizeOfLong(STAKE_AT_START_OF_LAST_REWARDED_PERIOD, data.stakeAtStartOfLastRewardedPeriod(), true);
        // [25] - auto_renew_account_id
        size += sizeOfMessage(AUTO_RENEW_ACCOUNT_ID, data.autoRenewAccountId(), com.hedera.hapi.node.base.AccountID.PROTOBUF::measureRecord);
        // [26] - auto_renew_seconds
        size += sizeOfLong(AUTO_RENEW_SECONDS, data.autoRenewSeconds(), true);
        // [27] - contract_kv_pairs_number
        size += sizeOfInteger(CONTRACT_KV_PAIRS_NUMBER, data.contractKvPairsNumber(), true);
        // [28] - crypto_allowances
        size += sizeOfMessageList(CRYPTO_ALLOWANCES, data.cryptoAllowances(), com.hedera.hapi.node.state.token.AccountCryptoAllowance.PROTOBUF::measureRecord);
        // [29] - approve_for_all_nft_allowances
        size += sizeOfMessageList(APPROVE_FOR_ALL_NFT_ALLOWANCES, data.approveForAllNftAllowances(), com.hedera.hapi.node.state.token.AccountApprovalForAllAllowance.PROTOBUF::measureRecord);
        // [30] - token_allowances
        size += sizeOfMessageList(TOKEN_ALLOWANCES, data.tokenAllowances(), com.hedera.hapi.node.state.token.AccountFungibleTokenAllowance.PROTOBUF::measureRecord);
        // [31] - number_treasury_titles
        size += sizeOfInteger(NUMBER_TREASURY_TITLES, data.numberTreasuryTitles(), true);
        // [32] - expired_and_pending_removal
        size += sizeOfBoolean(EXPIRED_AND_PENDING_REMOVAL, data.expiredAndPendingRemoval(), true);
        // [33] - first_contract_storage_key
        size += sizeOfBytes(FIRST_CONTRACT_STORAGE_KEY, data.firstContractStorageKey(), true);
        // [34] - head_pending_airdrop_id
        size += sizeOfMessage(HEAD_PENDING_AIRDROP_ID, data.headPendingAirdropId(), com.hedera.hapi.node.base.PendingAirdropId.PROTOBUF::measureRecord);
        // [35] - number_pending_airdrops
        size += sizeOfLong(NUMBER_PENDING_AIRDROPS, data.numberPendingAirdrops(), true);
    
        return size;
    }

        /**
     * Compares the given item with the bytes in the input, and returns false if it determines that
     * the bytes in the input could not be equal to the given item. Sometimes we need to compare an
     * item in memory with serialized bytes and don't want to incur the cost of deserializing the
     * entire object, when we could have determined the bytes do not represent the same object very
     * cheaply and quickly.
     *
     * @param item The item to compare. Cannot be null.
     * @param input The input with the bytes to compare
     * @return true if the bytes represent the item, false otherwise.
     * @throws ParseException If parsing fails
     */
    public boolean fastEquals(@NonNull Account item, @NonNull final ReadableSequentialData input) throws ParseException {
        return item.equals(parse(input));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy