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

com.hedera.hapi.node.token.codec.TokenInfoJsonCodec Maven / Gradle / Ivy

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

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

import com.hedera.hapi.node.token.TokenInfo;

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

import com.hedera.pbj.runtime.jsonparser.*;
import static com.hedera.hapi.node.token.schema.TokenInfoSchema.*;
import static com.hedera.pbj.runtime.JsonTools.*;

/**
 * JSON Codec for TokenInfo model object. Generated based on protobuf schema.
 */
public final class TokenInfoJsonCodec implements JsonCodec {
    

        /**
     * Parses a HashObject object from JSON parse tree for object JSONParser.ObjContext.
     * Throws an UnknownFieldException wrapped in a ParseException if in strict mode ONLY.
     *
     * @param root The JSON parsed object tree to parse data from
     * @return Parsed HashObject model object or null if data input was null or empty
     * @throws ParseException If parsing fails
     */
    public @NonNull TokenInfo parse(
            @Nullable final JSONParser.ObjContext root,
            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 --------------------------------------
                TokenID temp_tokenId = null;
        String temp_name = "";
        String temp_symbol = "";
        int temp_decimals = 0;
        long temp_totalSupply = 0;
        AccountID temp_treasury = null;
        Key temp_adminKey = null;
        Key temp_kycKey = null;
        Key temp_freezeKey = null;
        Key temp_wipeKey = null;
        Key temp_supplyKey = null;
        TokenFreezeStatus temp_defaultFreezeStatus = TokenFreezeStatus.fromProtobufOrdinal(0);
        TokenKycStatus temp_defaultKycStatus = TokenKycStatus.fromProtobufOrdinal(0);
        boolean temp_deleted = false;
        AccountID temp_autoRenewAccount = null;
        Duration temp_autoRenewPeriod = null;
        Timestamp temp_expiry = null;
        String temp_memo = "";
        TokenType temp_tokenType = TokenType.fromProtobufOrdinal(0);
        TokenSupplyType temp_supplyType = TokenSupplyType.fromProtobufOrdinal(0);
        long temp_maxSupply = 0;
        Key temp_fee_schedule_key = null;
        List temp_custom_fees = Collections.emptyList();
        Key temp_pause_key = null;
        TokenPauseStatus temp_pause_status = TokenPauseStatus.fromProtobufOrdinal(0);
        Bytes temp_ledger_id = Bytes.EMPTY;
        Bytes temp_metadata = Bytes.EMPTY;
        Key temp_metadata_key = null;
    
            // -- EXTRACT VALUES FROM PARSE TREE ---------------------------------------------
    
            for (JSONParser.PairContext kvPair : root.pair()) {
                switch (kvPair.STRING().getText()) {
                    case "tokenId" /* [1] */ : temp_tokenId = TokenID.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "name" /* [2] */ : temp_name = unescape(kvPair.value().STRING().getText()); break;
    case "symbol" /* [3] */ : temp_symbol = unescape(kvPair.value().STRING().getText()); break;
    case "decimals" /* [4] */ : temp_decimals = parseInteger(kvPair.value()); break;
    case "totalSupply" /* [5] */ : temp_totalSupply = parseLong(kvPair.value()); break;
    case "treasury" /* [6] */ : temp_treasury = AccountID.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "adminKey" /* [7] */ : temp_adminKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "kycKey" /* [8] */ : temp_kycKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "freezeKey" /* [9] */ : temp_freezeKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "wipeKey" /* [10] */ : temp_wipeKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "supplyKey" /* [11] */ : temp_supplyKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "defaultFreezeStatus" /* [12] */ : temp_defaultFreezeStatus = TokenFreezeStatus.fromString(kvPair.value().STRING().getText()); break;
    case "defaultKycStatus" /* [13] */ : temp_defaultKycStatus = TokenKycStatus.fromString(kvPair.value().STRING().getText()); break;
    case "deleted" /* [14] */ : temp_deleted = parseBoolean(kvPair.value()); break;
    case "autoRenewAccount" /* [15] */ : temp_autoRenewAccount = AccountID.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "autoRenewPeriod" /* [16] */ : temp_autoRenewPeriod = Duration.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "expiry" /* [17] */ : temp_expiry = Timestamp.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "memo" /* [18] */ : temp_memo = unescape(kvPair.value().STRING().getText()); break;
    case "tokenType" /* [19] */ : temp_tokenType = TokenType.fromString(kvPair.value().STRING().getText()); break;
    case "supplyType" /* [20] */ : temp_supplyType = TokenSupplyType.fromString(kvPair.value().STRING().getText()); break;
    case "maxSupply" /* [21] */ : temp_maxSupply = parseLong(kvPair.value()); break;
    case "feeScheduleKey" /* [22] */ : temp_fee_schedule_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "customFees" /* [23] */ : temp_custom_fees = parseObjArray(kvPair.value().arr(), CustomFee.JSON, maxDepth - 1); break;
    case "pauseKey" /* [24] */ : temp_pause_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "pauseStatus" /* [25] */ : temp_pause_status = TokenPauseStatus.fromString(kvPair.value().STRING().getText()); break;
    case "ledgerId" /* [26] */ : temp_ledger_id = Bytes.fromBase64(kvPair.value().STRING().getText()); break;
    case "metadata" /* [27] */ : temp_metadata = Bytes.fromBase64(kvPair.value().STRING().getText()); break;
    case "metadataKey" /* [28] */ : temp_metadata_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    
                    default: {
                        if (strictMode) {
                            // Since we are parsing is strict mode, this is an exceptional condition.
                            throw new UnknownFieldException(kvPair.STRING().getText());
                        }
                    }
                }
            }
    
            return new TokenInfo(temp_tokenId, temp_name, temp_symbol, temp_decimals, temp_totalSupply, temp_treasury, temp_adminKey, temp_kycKey, temp_freezeKey, temp_wipeKey, temp_supplyKey, temp_defaultFreezeStatus, temp_defaultKycStatus, temp_deleted, temp_autoRenewAccount, temp_autoRenewPeriod, temp_expiry, temp_memo, temp_tokenType, temp_supplyType, temp_maxSupply, temp_fee_schedule_key, temp_custom_fees, temp_pause_key, temp_pause_status, temp_ledger_id, temp_metadata, temp_metadata_key);
        } catch (Exception ex) {
            throw new ParseException(ex);
        }
    }

        /**
     * Returns JSON string representing an item.
     *
     * @param data      The item to convert. Must not be null.
     * @param indent    The indent to use for pretty printing
     * @param inline    When true the output will start with indent end with a new line otherwise
     *                        it will just be the object "{...}"
     */
    @Override
    public String toJSON(@NonNull TokenInfo data, String indent, boolean inline) {
        StringBuilder sb = new StringBuilder();
        // start
        sb.append(inline ? "{\n" : indent + "{\n");
        final String childIndent = indent + INDENT;
        // collect field lines
        final List fieldLines = new ArrayList<>();
            // [1] - tokenId
        if (data.tokenId() != null) fieldLines.add(field(childIndent, "tokenId", com.hedera.hapi.node.base.TokenID.JSON, data.tokenId()));
        // [2] - name
        if (data.name() != "") fieldLines.add(field("name", data.name()));
        // [3] - symbol
        if (data.symbol() != "") fieldLines.add(field("symbol", data.symbol()));
        // [4] - decimals
        if (data.decimals() != 0) fieldLines.add(field("decimals", data.decimals()));
        // [5] - totalSupply
        if (data.totalSupply() != 0) fieldLines.add(field("totalSupply", data.totalSupply()));
        // [6] - treasury
        if (data.treasury() != null) fieldLines.add(field(childIndent, "treasury", com.hedera.hapi.node.base.AccountID.JSON, data.treasury()));
        // [7] - adminKey
        if (data.adminKey() != null) fieldLines.add(field(childIndent, "adminKey", com.hedera.hapi.node.base.Key.JSON, data.adminKey()));
        // [8] - kycKey
        if (data.kycKey() != null) fieldLines.add(field(childIndent, "kycKey", com.hedera.hapi.node.base.Key.JSON, data.kycKey()));
        // [9] - freezeKey
        if (data.freezeKey() != null) fieldLines.add(field(childIndent, "freezeKey", com.hedera.hapi.node.base.Key.JSON, data.freezeKey()));
        // [10] - wipeKey
        if (data.wipeKey() != null) fieldLines.add(field(childIndent, "wipeKey", com.hedera.hapi.node.base.Key.JSON, data.wipeKey()));
        // [11] - supplyKey
        if (data.supplyKey() != null) fieldLines.add(field(childIndent, "supplyKey", com.hedera.hapi.node.base.Key.JSON, data.supplyKey()));
        // [12] - defaultFreezeStatus
        if (data.defaultFreezeStatus() != TokenFreezeStatus.fromProtobufOrdinal(0)) fieldLines.add(field("defaultFreezeStatus", data.defaultFreezeStatus().protoName()));
        // [13] - defaultKycStatus
        if (data.defaultKycStatus() != TokenKycStatus.fromProtobufOrdinal(0)) fieldLines.add(field("defaultKycStatus", data.defaultKycStatus().protoName()));
        // [14] - deleted
        if (data.deleted() != false) fieldLines.add(field("deleted", data.deleted()));
        // [15] - autoRenewAccount
        if (data.autoRenewAccount() != null) fieldLines.add(field(childIndent, "autoRenewAccount", com.hedera.hapi.node.base.AccountID.JSON, data.autoRenewAccount()));
        // [16] - autoRenewPeriod
        if (data.autoRenewPeriod() != null) fieldLines.add(field(childIndent, "autoRenewPeriod", com.hedera.hapi.node.base.Duration.JSON, data.autoRenewPeriod()));
        // [17] - expiry
        if (data.expiry() != null) fieldLines.add(field(childIndent, "expiry", com.hedera.hapi.node.base.Timestamp.JSON, data.expiry()));
        // [18] - memo
        if (data.memo() != "") fieldLines.add(field("memo", data.memo()));
        // [19] - tokenType
        if (data.tokenType() != TokenType.fromProtobufOrdinal(0)) fieldLines.add(field("tokenType", data.tokenType().protoName()));
        // [20] - supplyType
        if (data.supplyType() != TokenSupplyType.fromProtobufOrdinal(0)) fieldLines.add(field("supplyType", data.supplyType().protoName()));
        // [21] - maxSupply
        if (data.maxSupply() != 0) fieldLines.add(field("maxSupply", data.maxSupply()));
        // [22] - fee_schedule_key
        if (data.feeScheduleKey() != null) fieldLines.add(field(childIndent, "feeScheduleKey", com.hedera.hapi.node.base.Key.JSON, data.feeScheduleKey()));
        // [23] - custom_fees
        if (!data.customFees().isEmpty()) fieldLines.add(arrayField(childIndent, "customFees", com.hedera.hapi.node.transaction.CustomFee.JSON, data.customFees()));
        // [24] - pause_key
        if (data.pauseKey() != null) fieldLines.add(field(childIndent, "pauseKey", com.hedera.hapi.node.base.Key.JSON, data.pauseKey()));
        // [25] - pause_status
        if (data.pauseStatus() != TokenPauseStatus.fromProtobufOrdinal(0)) fieldLines.add(field("pauseStatus", data.pauseStatus().protoName()));
        // [26] - ledger_id
        if (data.ledgerId() != Bytes.EMPTY && data.ledgerId() != null && data.ledgerId().length() > 0) fieldLines.add(field("ledgerId", data.ledgerId()));
        // [27] - metadata
        if (data.metadata() != Bytes.EMPTY && data.metadata() != null && data.metadata().length() > 0) fieldLines.add(field("metadata", data.metadata()));
        // [28] - metadata_key
        if (data.metadataKey() != null) fieldLines.add(field(childIndent, "metadataKey", com.hedera.hapi.node.base.Key.JSON, data.metadataKey()));
    
        // write field lines
        if (!fieldLines.isEmpty()){
            sb.append(childIndent);
            sb.append(String.join(",\n"+childIndent, fieldLines));
            sb.append("\n");
        }
        // end
        sb.append(indent + "}");
        return sb.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy