| Value |
Top-encoding bytes |
Nested encoding bytes |
DayOfWeek::Monday
|
/* nothing */
|
/* discriminant */ 0,
|
DayOfWeek::Tuesday
|
/* discriminant */ 1,
|
EnumWithEverything::Default
|
/* nothing */
|
/* discriminant */ 0,
|
EnumWithEverything::Today(
DayOfWeek::Monday
)
|
/* discriminant */ 1,
/* DayOfWeek discriminant */ 0
|
EnumWithEverything::Today(
DayOfWeek::Friday
)
|
/* discriminant */ 1,
/* DayOfWeek discriminant */ 4
|
EnumWithEverything::Write(
Vec::new(),
0,
)
|
/* discriminant */ 2,
/* vec length */ 0, 0, 0, 0,
/* u16 */ 0, 0,
|
EnumWithEverything::Write(
[1, 2, 3].to_vec(),
4
)
|
/* discriminant */ 2,
/* vec length */ 0, 0, 0, 3,
/* vec contents */ 1, 2, 3,
/* an extra 16 */ 0, 4,
|
EnumWithEverything::Struct (
int: 0x42,
seq: vec![0x1, 0x2, 0x3, 0x4, 0x5],
another_byte: 0x6,
uint_32: 0x12345,
uint_64: 0x123456789,
);
|
/* discriminant */ 3,
/* int */ 0, 0x42,
/* seq length */ 0, 0, 0, 5,
/* seq contents */ 1, 2, 3, 4, 5,
/* another_byte */ 6,
/* uint_32 */ 0x00, 0x01, 0x23, 0x45,
/* uint_64 */ 0x00, 0x00, 0x00, 0x01,
0x23, 0x45, 0x67, 0x89,
|
);
---
### Defaults
Smart contracts occasionally need to interact with uninitialized data. Most notably, whenever a smart contract is deployed, its entire storage will be uninitialized.
Uninitialized storage is indistinguishable from empty storage values, or storage that has been deleted. It always acts like
## Built-in defaults
The serialization format naturally supports defaults for most types.
The default value of a type is the value that we receive when deserializing an empty buffer. The same value will serialize to an empty buffer. We like having easy access to empty serialized buffers, because that way we can easily clear storage and we minimize gas costs in transactions.
For instance, for all numeric types, zero is the default value, because we represent it as an empty buffer.
| Type | Default value |
| ----------------------------------------- | ------------------------------ |
| `u8` | `0` |
| `u16` | `0` |
| `u32` | `0` |
| `u64` | `0` |
| `usize` | `0` |
| `BigUint` | `0` |
| `i8` | `0` |
| `i16` | `0` |
| `i32` | `0` |
| `i64` | `0` |
| `isize` | `0` |
| `BigInt` | `0` |
| `bool` | `false` |
| `Option