From a5519a7d3b5c0b675026a2daef9477f06ae795a6 Mon Sep 17 00:00:00 2001 From: Jannik Luhn Date: Tue, 22 Jan 2019 17:14:25 +0100 Subject: [PATCH 1/2] SSZ: List serialization with variable element size Fix #232 --- specs/simple-serialize.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 8630c47c6..cca2969e6 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -143,9 +143,9 @@ Lists are a collection of elements of the same homogeneous type. | Length of serialized list fits into 4 bytes | ``len(serialized) < 2**32`` | -1. Get the number of raw bytes to serialize: it is ``len(list) * sizeof(element)``. - * Encode that as a `4-byte` **little endian** `uint32`. -2. Append the elements in a packed manner. +1. Serialize all list elements individually and concatenate them. + +2. Prefix the concatenation with its length encoded as a `4-byte` **little-endian** unsigned integer. * *Note on efficiency*: consider using a container that does not need to iterate over all elements to get its length. For example Python lists, C++ vectors or Rust Vec. From f8670e80692c02a1de4be41bdf9b9ca94948419f Mon Sep 17 00:00:00 2001 From: Jannik Luhn Date: Tue, 22 Jan 2019 17:16:37 +0100 Subject: [PATCH 2/2] SSZ: Remove note on efficiency --- specs/simple-serialize.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index cca2969e6..eff65f49e 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -147,8 +147,6 @@ Lists are a collection of elements of the same homogeneous type. 2. Prefix the concatenation with its length encoded as a `4-byte` **little-endian** unsigned integer. -* *Note on efficiency*: consider using a container that does not need to iterate over all elements to get its length. For example Python lists, C++ vectors or Rust Vec. - **Example in Python** ```python