Serialization Primitives
Avalanche uses a simple, uniform, and elegant representation for all internal data. This document describes how primitive types are encoded on the Avalanche platform. Transactions are encoded in terms of these basic primitive types.
Byte
Bytes are packed as-is into the message payload.
Example:
Short
Shorts are packed in BigEndian format into the message payload.
Example:
Integer
Integers are 32-bit values packed in BigEndian format into the message payload.
Example:
Long Integers
Long integers are 64-bit values packed in BigEndian format into the message payload.
Example:
IP Addresses
IP addresses are represented as 16-byte IPv6 format, with the port appended into the message payload as a Short. IPv4 addresses are padded with 12 bytes of leading 0x00s.
IPv4 example:
IPv6 example:
Fixed-Length Array
Fixed-length arrays, whose length is known ahead of time and by context, are packed in order.
Byte array example:
Integer array example:
Variable Length Array
The length of the array is prefixed in Integer format, followed by the packing of the array contents in Fixed Length Array format.
Byte array example:
Int array example:
String
A String is packed similarly to a variable-length byte array. However, the length prefix is a short rather than an int. Strings are encoded in UTF-8 format.
Example:
Last updated on