Update simple-serialize.md

This commit is contained in:
Justin 2019-04-13 23:55:08 +10:00 committed by GitHub
parent 35a6311208
commit 80bd4a381b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ This is a **work in progress** describing typing, serialization and Merkleizatio
| Name | Value | Description | | Name | Value | Description |
|-|-|-| |-|-|-|
| `BYTES_PER_CHUNK` | `32` | Number of bytes per chunk. | | `BYTES_PER_CHUNK` | `32` | Number of bytes per chunk. |
| `BYTES_PER_LENGTH_PREFIX` | `4` | Number of bytes per serialized length prefix. | | `BYTES_PER_LENGTH_OFFSET` | `4` | Number of bytes per serialized length prefix. |
| `BITS_PER_BYTE` | `8` | Number of bits per byte. | | `BITS_PER_BYTE` | `8` | Number of bits per byte. |
## Typing ## Typing
@ -79,9 +79,9 @@ fixed_parts = [serialize(element) if is_fixed_size(element) else None for elemen
variable_parts = [serialize(element) if is_variable_size(element) else None for element in value] variable_parts = [serialize(element) if is_variable_size(element) else None for element in value]
# Compute and check lengths # Compute and check lengths
fixed_lengths = [len(part) if part != None else BYTES_PER_LENGTH_PREFIX for part in fixed_parts] fixed_lengths = [len(part) if part != None else BYTES_PER_LENGTH_OFFSET for part in fixed_parts]
variable_lengths = [len(part) if part != None else 0 for part in variable_parts] variable_lengths = [len(part) if part != None else 0 for part in variable_parts]
assert sum(fixed_lengths + variable_lengths) < 2**(BYTES_PER_LENGTH_PREFIX * BITS_PER_BYTE) assert sum(fixed_lengths + variable_lengths) < 2**(BYTES_PER_LENGTH_OFFSET * BITS_PER_BYTE)
# Compute offsets of variable-size elements, and interleave with fixed parts # Compute offsets of variable-size elements, and interleave with fixed parts
offsets = [sum(fixed_lengths) + sum(variable_lengths[:i]) for i in range(len(value))] offsets = [sum(fixed_lengths) + sum(variable_lengths[:i]) for i in range(len(value))]