Binary Canonical Serialization (BCS) Standard Guide
Overview
Primitive Types
Boolean (bool)
#[test_only]
module supra_example::bcs_examples {
use std::bcs;
use std::from_bcs;
#[test]
fun test_bool_serialization() {
// Serialize
let val: bool = true;
let bytes: vector<u8> = bcs::to_bytes(&val);
assert!(bytes == vector[0x01], 0);
// Deserialize
let val_des = from_bcs::to_bool(bytes);
assert!(val_des == true, 1);
}
}Unsigned Integers
U8 (8-bit unsigned integer)
U16 (16-bit unsigned integer)
U32 (32-bit unsigned integer)
U64 (64-bit unsigned integer)
U128 (128-bit unsigned integer)
U256 (256-bit unsigned integer)
Variable Length Encoding (Uleb128)
Complex Types
Sequences and Fixed Sequences
Strings
Account Addresses
Structs
Option Types
Enums
Maps
BCS Stream Deserialization Module
Deserialization Strategies
Key Features
Important Considerations
Non-Self-Describing Format
Canonical Ordering
Sample Example
Conclusion
Last updated
