From aa676354a049b8a2812c237861b0d7e9c02a83c6 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 27 Feb 2019 17:54:19 +0100 Subject: [PATCH] Update simple-serialize.md --- specs/simple-serialize.md | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 3dc9b0b07..639231b30 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -4,11 +4,9 @@ This is a **work in progress** describing typing, serialization and Merkleizatio ## Table of contents -- [Constants](#constants) - [Typing](#typing) - [Basic types](#basic-types) - [Composite types](#composite-types) - - [Notation](#notation) - [Aliases](#aliases) - [Serialization](#serialization) - [`uintN`](#uintn) @@ -19,31 +17,18 @@ This is a **work in progress** describing typing, serialization and Merkleizatio - [Self-signed containers](#self-signed-containers) - [Implementations](#implementations) -## Constants - -| Name | Value | Description | -|-|-|-| -| `LENGTH_BYTES` | `4` | Number of bytes for the length of variable-length serialized objects. | -| `MAX_LENGTH` | `2**(8 * LENGTH_BYTES)` | Maximum serialization length. | - ## Typing -#### Basic types +### Basic types * `uintN`: `N`-bit unsigned integer (where `N in [8, 16, 32, 64, 128, 256]`) * `bool`: 1-bit unsigned integer -#### Composite types +### Composite types -* **container**: ordered heterogenous collection of values -* **tuple**: ordered fixed-length homogeneous collection of values -* **list**: ordered variable-length homogenous collection of values - -#### Notation - -* **container**: key-pair curly braket notation `{}` (e.g. `{'key1': uint64, 'key2': bool}`) -* **tuple**: angle braket notation `[N]` (e.g. `uint64[N]`) -* **list**: angle braket notation `[]` (e.g. `uint64[]`) +* **container**: ordered heterogenous collection of values (key-pair curly braket notation `{}`, e.g. `{'foo': uint64, 'bar': bool}`) +* **tuple**: ordered fixed-length homogeneous collection of values (angle braket notation `[N]`, e.g. `uint64[N]`) +* **list**: ordered variable-length homogenous collection of values (angle braket notation `[]`, e.g. `uint64[]`) #### Aliases @@ -52,7 +37,6 @@ For convenience we alias: * `byte` to `uint8` * `bytes` to `byte[]` * `bytesN` to `byte[N]` -* `bit` to `bool` ## Serialization @@ -75,8 +59,9 @@ return b'\x01' if value is True else b'\x00' #### Containers, tuples, lists ```python +LENGTH_BYTES = 4 serialized_bytes = ''.join([serialize(element) for element in value]) -assert len(serialized_bytes) < MAX_LENGTH +assert len(serialized_bytes) < 2**(8 * LENGTH_BYTES) serialized_length = len(serialized_bytes).to_bytes(LENGTH_BYTES, 'little') return serialized_length + serialized_bytes ```