Enum concordium_contracts_common::schema::Type
source · pub enum Type {
Show 32 variants
Unit,
Bool,
U8,
U16,
U32,
U64,
U128,
I8,
I16,
I32,
I64,
I128,
Amount,
AccountAddress,
ContractAddress,
Timestamp,
Duration,
Pair(Box<Type>, Box<Type>),
List(SizeLength, Box<Type>),
Set(SizeLength, Box<Type>),
Map(SizeLength, Box<Type>, Box<Type>),
Array(u32, Box<Type>),
Struct(Fields),
Enum(Vec<(String, Fields)>),
String(SizeLength),
ContractName(SizeLength),
ReceiveName(SizeLength),
ULeb128(u32),
ILeb128(u32),
ByteList(SizeLength),
ByteArray(u32),
TaggedEnum(BTreeMap<u8, (String, Fields)>),
}
Expand description
Schema type used to describe the different types in a smart contract, their serialization and how to represent the types in JSON.
Variants§
Unit
A type with no serialization.
Bool
Boolean. Serialized as a byte, where the value 0 is false and 1 is true.
U8
Unsigned 8-bit integer.
U16
Unsigned 16-bit integer. Serialized as little endian.
U32
Unsigned 32-bit integer. Serialized as little endian.
U64
Unsigned 64-bit integer. Serialized as little endian.
U128
Unsigned 128-bit integer. Serialized as little endian.
I8
Signed 8-bit integer. Serialized as little endian.
I16
Signed 16-bit integer. Serialized as little endian.
I32
Signed 32-bit integer. Serialized as little endian.
I64
Signed 64-bit integer. Serialized as little endian.
I128
Signed 128-bit integer. Serialized as little endian.
Amount
An amount of CCD. Serialized as 64-bit unsigned integer little endian.
AccountAddress
An account address.
ContractAddress
A contract address.
Timestamp
A timestamp. Represented as milliseconds since Unix epoch. Serialized as a 64-bit unsigned integer little endian.
Duration
A duration of milliseconds, cannot be negative. Serialized as a 64-bit unsigned integer little endian.
Pair(Box<Type>, Box<Type>)
A pair.
List(SizeLength, Box<Type>)
A list. It is serialized with the length first followed by the list items.
Set(SizeLength, Box<Type>)
A Set. It is serialized with the length first followed by the list items.
Map(SizeLength, Box<Type>, Box<Type>)
A Map. It is serialized with the length first followed by key-value pairs of the entries.
Array(u32, Box<Type>)
A fixed sized list.
Struct(Fields)
A structure type with fields.
Enum(Vec<(String, Fields)>)
A sum type.
String(SizeLength)
A UTF8 String. It is serialized with the length first followed by the encoding of the string.
ContractName(SizeLength)
A smart contract name. It is serialized with the length first followed by the ASCII encoding of the name.
ReceiveName(SizeLength)
A smart contract receive function name. It is serialized with the length first followed by the ASCII encoding of the name.
ULeb128(u32)
An unsigned integer encoded using LEB128 with the addition of a constraint on the maximum number of bytes to use for an encoding.
ILeb128(u32)
A signed integer encoded using LEB128 with the addition of a constraint on the maximum number of bytes to use for an encoding.
ByteList(SizeLength)
A list of bytes. It is serialized with the length first followed by the bytes.
ByteArray(u32)
A fixed sized list of bytes.
TaggedEnum(BTreeMap<u8, (String, Fields)>)
An enum with a tag.
Implementations§
source§impl Type
impl Type
sourcepub fn serial_value(&self, json: &Value) -> Result<Vec<u8>, JsonError>
pub fn serial_value(&self, json: &Value) -> Result<Vec<u8>, JsonError>
Serialize the given JSON value into the binary format represented by the schema. If the JSON value does not match the schema an error will be returned.
sourcepub fn serial_value_into(
&self,
json: &Value,
out: &mut impl Write
) -> Result<(), JsonError>
pub fn serial_value_into( &self, json: &Value, out: &mut impl Write ) -> Result<(), JsonError>
Serialize the given JSON value into the binary format represented by the schema. The resulting byte array is written into the provided sink. If the JSON value does not match the schema an error will be returned.
sourcepub fn write_bytes_from_json_schema_type<W: Write>(
schema: &Type,
json: &Value,
out: &mut W
) -> Result<(), JsonError>
👎Deprecated since 5.2.0: Use the more ergonomic serial_value_into
instead.
pub fn write_bytes_from_json_schema_type<W: Write>( schema: &Type, json: &Value, out: &mut W ) -> Result<(), JsonError>
serial_value_into
instead.Uses the schema to parse JSON into bytes It is assumed the array of values for Map and Set are already ordered.
sourcepub fn to_json_template(&self) -> Value
pub fn to_json_template(&self) -> Value
Displays a template of the JSON to be used for the SchemaType
.
source§impl Type
impl Type
sourcepub fn to_json_string_pretty(&self, bytes: &[u8]) -> Result<String, ToJsonError>
pub fn to_json_string_pretty(&self, bytes: &[u8]) -> Result<String, ToJsonError>
Uses the schema to deserialize bytes into pretty json