IC4J API Docs
  • Overview
    • Introduction
  • Quick Start
  • License
  • Reference
    • API Reference
      • Install IC4J Libraries
      • Supported Types
      • ReplicaTransport
      • Identity
      • Principal
      • AgentBuilder
      • ProxyBuilder
      • Using IDLArgs
      • QueryBuilder and UpdateBuilder
      • Using Raw Agent Methods
      • Handle Binary Payloads
      • Object Serializers and Deserializers
        • Pojo Serializer and Deserializer
        • JSON Jackson Serializer and Deserializer
        • JSON Gson Serializer and Deserializer
        • XML DOM Serializer and Deserializer
        • XML JAXB Serializer and Deserializer
        • JDBC Serializer
      • Android Development
Powered by GitBook
On this page
  • IDLType
  • IDLValue
  1. Reference
  2. API Reference

Using IDLArgs

PreviousProxyBuilderNextQueryBuilder and UpdateBuilder

Last updated 1 year ago

To create the binary form of Candid data in Java or to convert data from candid binary form to Java use the class.

This is how to create a byte[] array from a List of .

is a wrapped value, consisting of the Java value and the .

List<IDLValue> args = new ArrayList<IDLValue>();
BigInteger intValue = new BigInteger("10000");
args.add(IDLValue.create(intValue));
IDLArgs idlArgs = IDLArgs.create(args);
byte[] payload = idlArgs.toBytes();

To convert data from byte[] array to IDLArgs use the Method fromBytes.

IDLArgs outArgs = IDLArgs.fromBytes(output);

When dealing with Complex Types, consider defining IDLTypes , a useful way for deserialization.

IDLType[] idlTypes = { idlValue.getIDLType() };
IDLArgs outArgs = IDLArgs.fromBytes(output, idlTypes);

IDLType

class is a wrapper for Candid type definition. Use createType method to create a Java object.

For simple Candid types use only the argument.

IDLType idlType = IDLType.createType(Type.INT);

When creating VEC or OPT Candid types, the inner type needs to be defined.

The inner type can also have nested types.

IDLType idlArrayType = IDLType.createType(Type.VEC,Type.INT);
IDLType idlOptionalType = IDLType.createType(Type.OPT,Type.INT);

When creating the RECORD or VARIANT Candid types, the Type Map needs to be defined.

Type Map can also have nested types.

Map<Label, Object> typesMap = new HashMap<Label, Object>();
mapValue.put(Label.createNamedLabel("foo"), IDLType.createType(Type.INT));
IDLType idlType = IDLType.createType(Type.RECORD,typesMap);

These will automatically identify the default Candid type for Java class or object.

IDLType idlType = IDLType.createType(Integer.class);
BigInteger value = new BigInteger("100000000");
IDLType idlType = IDLType.createType(value);

To override default type use this variant.

IDLType idlType = IDLType.createType(value, Type.NAT);

IDLValue

To create the IDLValue Java object use the Method Create functon.

This method has several variants, in if the explicit type definition is required.

To get the Java object value from IDLValue use the Method getValue function.

BigInteger value = idlValue.getValue();

The key in Type Map is the type. Label can be Named, Unnamed or Id type.

To create the directly from Java class or object use the helper methods.

IDLArgs
IDLValue
IDLValue
IDLType
IDLType
Type
Label
IDLType