async serialize(valueDecoded, typeName) {
          const protobufType =
            this.defaultType || this.root.lookupType(typeName);
          let object = {};
          if (this.bytesConversion) {
            // TODO: format from Buffer to base58/base64 for nested fields
            Object.keys(protobufType.fields).forEach((fieldName) => {
              const { options, name, type } = protobufType.fields[fieldName];
              // No byte conversion
              if (type !== "bytes") {
                object[name] = copyValue(valueDecoded[name]);
                return;
              }
              // Default byte conversion
              if (!options || !options[OP_BYTES]) {
                object[name] = utils_1.decodeBase64(valueDecoded[name]);
                return;
              }
              // Specific byte conversion
              switch (options[OP_BYTES]) {
                case "BASE58":
                case "CONTRACT_ID":
                case "ADDRESS":
                  object[name] = utils_1.decodeBase58(valueDecoded[name]);
                  break;
                case "BASE64":
                  object[name] = utils_1.decodeBase64(valueDecoded[name]);
                  break;
                case "HEX":
                case "BLOCK_ID":
                case "TRANSACTION_ID":
                  object[name] = utils_1.toUint8Array(
                    valueDecoded[name].replace("0x", "")
                  );
                  break;
                default:
                  throw new Error(
                    `unknown koinos_byte_type ${options[OP_BYTES]}`
                  );
              }
            });
          } else {
            object = valueDecoded;
          }
          const message = protobufType.create(object);
          const buffer = protobufType.encode(message).finish();
          return buffer;
        }
/**
         * Function to encode a type using the protobuffer definitions
         * It also prepares the bytes for special cases (base58, hex string)
         * when bytesConversion param is true.
         */
Function to encode a type using the protobuffer definitions
It also prepares the bytes for special cases (base58, hex string)
when bytesConversion param is true.
Function to encode a type using the protobuffer definitions It also prepares the bytes for special cases ( base58 hex string ) when bytesConversion param is true .
async serialize(valueDecoded, typeName) {
          const protobufType =
            this.defaultType || this.root.lookupType(typeName);
          let object = {};
          if (this.bytesConversion) {
            Object.keys(protobufType.fields).forEach((fieldName) => {
              const { options, name, type } = protobufType.fields[fieldName];
              if (type !== "bytes") {
                object[name] = copyValue(valueDecoded[name]);
                return;
              }
              if (!options || !options[OP_BYTES]) {
                object[name] = utils_1.decodeBase64(valueDecoded[name]);
                return;
              }
              switch (options[OP_BYTES]) {
                case "BASE58":
                case "CONTRACT_ID":
                case "ADDRESS":
                  object[name] = utils_1.decodeBase58(valueDecoded[name]);
                  break;
                case "BASE64":
                  object[name] = utils_1.decodeBase64(valueDecoded[name]);
                  break;
                case "HEX":
                case "BLOCK_ID":
                case "TRANSACTION_ID":
                  object[name] = utils_1.toUint8Array(
                    valueDecoded[name].replace("0x", "")
                  );
                  break;
                default:
                  throw new Error(
                    `unknown koinos_byte_type ${options[OP_BYTES]}`
                  );
              }
            });
          } else {
            object = valueDecoded;
          }
          const message = protobufType.create(object);
          const buffer = protobufType.encode(message).finish();
          return buffer;
        }
async serialize ( valueDecoded , typeName ) { const protobufType = this . defaultType || this . root . lookupType ( typeName ) ; let object = { } ; if ( this . bytesConversion ) { Object . keys ( protobufType . fields ) . forEach ( ( fieldName ) => { const { options , name , type } = protobufType . fields [ fieldName ] ; if ( type !== "bytes" ) { object [ name ] = copyValue ( valueDecoded [ name ] ) ; return ; } if ( ! options || ! options [ OP_BYTES ] ) { object [ name ] = utils_1 . decodeBase64 ( valueDecoded [ name ] ) ; return ; } switch ( options [ OP_BYTES ] ) { case "BASE58" : case "CONTRACT_ID" : case "ADDRESS" : object [ name ] = utils_1 . decodeBase58 ( valueDecoded [ name ] ) ; break ; case "BASE64" : object [ name ] = utils_1 . decodeBase64 ( valueDecoded [ name ] ) ; break ; case "HEX" : case "BLOCK_ID" : case "TRANSACTION_ID" : object [ name ] = utils_1 . toUint8Array ( valueDecoded [ name ] . replace ( "0x" , "" ) ) ; break ; default : throw new Error ( ` ${ options [ OP_BYTES ] } ` ) ; } } ) ; } else { object = valueDecoded ; } const message = protobufType . create ( object ) ; const buffer = protobufType . encode ( message ) . finish ( ) ; return buffer ; }
Function to encode a type using the protobuffer definitions
 It also prepares the bytes for special cases (base58, hex string)
 when bytesConversion param is true.
Function to encode a type using the protobuffer definitions It also prepares the bytes for special cases ( base58 hex string ) when bytesConversion param is true .
// TODO: format from Buffer to base58/base64 for nested fields // No byte conversion // Default byte conversion // Specific byte conversion