Skip to content

Commit 840cd2b

Browse files
authored
Merge pull request #95 from casper-network/kara/revert-serialization-changes
Revert the serialization changes in 2.0.1 temporarily
2 parents 1dbb073 + 260acdf commit 840cd2b

File tree

5 files changed

+39
-751
lines changed

5 files changed

+39
-751
lines changed

versioned_docs/version-2.0.0/concepts/serialization/calltable-serialization.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ As mentioned before, the `calltable serialization approach` requires serializing
99
- `fields` - field which is an ordered collection of [Field](#field). This collection is serialized as a Vec<Field> in the "regular" `Binary Serialization Standard` schema. The invariants for `fields` are:
1010
- for each f<sub>i</sub>, f<sub>j</sub> given `i` < `j` implies f<sub>i</sub>.index < f<sub>j</sub>.index
1111
- for each f<sub>i</sub>, f<sub>j</sub> given `i` < `j` implies f<sub>i</sub>.offset < f<sub>j</sub>.offset
12-
- `bytes` - field which is an amorphous blob of bytes serialized as `Bytes` in the "regular" `Binary Serialization Standard` schema. Bear in mind that this field will be serialized by appending first a `u32` integer (number of bytes) than the raw bytes payload.
12+
- `bytes` - field which is an amorphous blob of bytes serialized as `Bytes` in the "regular" `Binary Serialization Standard` schema.
1313

1414
A <span id="field">`Field`</span> consists of:
1515

@@ -79,9 +79,6 @@ Once we have the `fields` and `bytes` we can proceed to serialize those in the "
7979
for i in range(0, len(fields)):
8080
bytes_arr += fields[i]["index"].to_bytes(2, byteorder = 'little')
8181
bytes_arr += fields[i]["offset"].to_bytes(4, byteorder = 'little')
82-
concatenated_serialized_fields_len = len(concatenated_serialized_fields)
83-
print(f"{concatenated_serialized_fields_len}")
84-
bytes_arr += concatenated_serialized_fields_len.to_bytes(4, byteorder = 'little')
8582
bytes_arr += concatenated_serialized_fields
8683
return bytes_arr
8784
```
@@ -91,23 +88,23 @@ and once we have all that we can apply the scripts to example:
9188
```python
9289
I = [0, 1, 3, 5]
9390
B = [bytes([0, 1, 255]), bytes([55, 12, 110, 60, 15]), bytes([7, 149, 1]), bytes([55])]
94-
envelope = build_calltable_data(I, B)
91+
envelope = buildCalltableData(I, B)
9592
serialized_calltable_representation = serialize_calltable_representation(envelope["fields"], envelope["bytes"])
9693
print(f"{serialized_calltable_representation.hex()}")
9794
```
9895

9996
which produces:
10097

10198
```
102-
0400000000000000000001000300000003000800000005000b0000000c0000000001ff370c6e3c0f07950137
99+
0400000000000000000001000300000003000800000005000b0000000001ff370c6e3c0f07950137
103100
```
104101

105102
In the above hex:
106-
| Serialized length of `fields` collection | field[0].index | field[0].offset | field[1].index | field[1].offset | field[2].index | field[2].offset | field[3].index | field[3].offset | number of bytes in `bytes` field | raw bytes of `bytes` field |
107-
| ---------------------------------------- | -------------- | --------------- | -------------- | --------------- | -------------- | --------------- | -------------- | --------------- | ----- | -- |
108-
| 04000000 | 0000 | 00000000 | 0100 | 03000000 | 0300 | 08000000 | 0500 | 0b000000 | 0c000000 | 0001ff370c6e3c0f07950137
103+
| Serialized length of `fields` collection | field[0].index | field[0].offset | field[1].index | field[1].offset | field[2].index | field[2].offset | field[3].index | field[3].offset | bytes |
104+
| ---------------------------------------- | -------------- | --------------- | -------------- | --------------- | -------------- | --------------- | -------------- | --------------- | ----- |
105+
| 04000000 | 0000 | 00000000 | 0100 | 03000000 | 0300 | 08000000 | 0500 | 0b000000 | 0001ff370c6e3c0f07950137
109106

110-
This concludes how we construct and byte-serialize an `envelope`. In the next paragraphs we will explain what are the assumptions and conventions when dealing with `struct`s and `tagged-union`s.
107+
This concludes how we construct and byte-serialize an `envelope`. In the next paragraphs we will explain what are the assumptions and conventions when dealing with `struct`s and `enum`s.
111108

112109
## Serializing uniform data structures
113110

@@ -123,15 +120,15 @@ struct A {
123120

124121
In the above example we could assign `a` index `0`, `b` index `1` and `c` index `2`. Knowing this and assuming that we know how to byte-serialize `OtherStruct` we should be able to create an `envelope` for this struct and serialize it in the `calltable` scheme.
125122

126-
## Serializing tagged-unions
123+
## Serializing enums
127124

128-
By `tagged-union` we understand polymorphic, but limited (an instance of an tagged-union can be only one of N known `variants`) data structures that are unions of structures and/or other tagged-unions. An tagged-union variant can be:
125+
By `enums` we understand polymorphic, but limited (an instance of an enum can be only one of N known `variants`) data structures that are unions of structures and/or other enums. An enum variant can be:
129126

130127
- empty (tag variant)
131128
- a struct
132-
- a nested tagged-union
129+
- a nested enum
133130

134-
As mentioned, there is a polymorphic aspect to these kinds of tagged-union and we handle them by convention - `serialization index` `0` is always reserved for a 1 byte discriminator number which defines which tagged-union variant is being serialized. The value of this specific pseudo-field will be called `variant discriminator`. Subsequent indices are used to serialize the fields of specific variants (for empty tag variants there will be no more indices). So, given an example tagged-union (implemented in rust, rust equivalent of tagged-union is `enum`):
131+
As mentioned, there is a polymorphic aspect to these kinds of enums and we handle them by convention - `serialization index` `0` is always reserved for a 1 byte discriminator number which defines which enum variant is being serialized, the next indices are used to serialize the fields of specific variants (for empty tag variants there will be no more indices). So, given an enum:
135132

136133
```rust
137134
enum X {
@@ -141,13 +138,13 @@ As mentioned, there is a polymorphic aspect to these kinds of tagged-union and w
141138
}
142139
```
143140

144-
First we need to chose variant discriminator values for each of the tagged-union variants, let's select:
141+
First we need to chose variant discriminator values for each of the enum variants, let's select:
145142

146143
- if variant `A` - the variant discriminator will be `0`
147144
- if variant `B` - the variant discriminator will be `1`
148145
- if variant `C` - the variant discriminator will be `2`
149146

150-
Again, as with fields in `Serializing tagged-unions` the variant discriminator values does not need to start from `0` and does not need to be contiguous, but that is our convention and any "discontinuities" in the value set for variant disciminator would indicate a retired tagged-union variant or variants.
147+
Again, as with fields in `Serializing enums` the variant discriminator values don't need to start from `0` and don't need to be contiguous, but that is our convention and any "holes" in the definition would indicate a retired enum variant.
151148

152149
Next we need to assign field `serialization indices` for each variant:
153150

@@ -160,8 +157,8 @@ Next we need to assign field `serialization indices` for each variant:
160157
- `2` for the second tuple element (of type u32),
161158
- `3` for the second tuple element (of type u64),
162159

163-
As you can see, `serialization indices` for fields need to be unique in scope of a particular tagged-union variant.
164-
Knowing the above, let's see how the `I` and `B` collections would look like for different instances of this tagged-union:
160+
As you can see, `serialization indices` for fields need to be unique in scope of a particular enum variant.
161+
Knowing the above, let's see how the `I` and `B` collections would look like for different instances of this enum:
165162

166163
- when serializing variant `X::A` (assuming python notation):
167164
```python

0 commit comments

Comments
 (0)