Update simple-serialize.md

This commit is contained in:
Justin 2019-04-14 00:10:02 +10:00 committed by GitHub
parent 23c09541e2
commit f6ed1df62b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -76,11 +76,11 @@ return b"\x01" if value is True else b"\x00"
```python ```python
# Reccursively serialize # Reccursively serialize
fixed_parts = [serialize(element) if is_fixed_size(element) else None for element in value] fixed_parts = [serialize(element) if is_fixed_size(element) else None for element in value]
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 "" for element in value]
# Compute and check lengths # Compute and check lengths
fixed_lengths = [len(part) if part != None else BYTES_PER_LENGTH_OFFSET 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) for part in variable_parts]
assert sum(fixed_lengths + variable_lengths) < 2**(BYTES_PER_LENGTH_OFFSET * BITS_PER_BYTE) assert sum(fixed_lengths + variable_lengths) < 2**(BYTES_PER_LENGTH_OFFSET * BITS_PER_BYTE)
# Compute offsets of variable-size parts and interleave offsets with fixed parts # Compute offsets of variable-size parts and interleave offsets with fixed parts