diff --git a/docs/e2store.md b/docs/e2store.md index 10dedbfbf..6dd428cbb 100644 --- a/docs/e2store.md +++ b/docs/e2store.md @@ -17,10 +17,15 @@ The header corresponds to an SSZ object defined as such: ```python class Header(Container): type: Vector[byte, 2] - length: uint48 + length: uint32 + reserved: uint16 ``` -The `length` is the length of the data that follows the header, not including the length of the header itself. For example, the entry with header type `[0x22, 0x32]`, the length `4` and the bytes `[0x01, 0x02, 0x03, 0x04]` will be stored as the byte sequence `[0x22, 0x32, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04]`. +The `length` is the length of the data that follows the header, not including the length of the header itself. + +The `reserved` field must be set to `0`. + +For example, an entry with header type `[0x22, 0x32]`, length `4` and the content `[0x01, 0x02, 0x03, 0x04]` will be stored as the byte sequence `[0x22, 0x32, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04]`. `.e2s` files may freely be concatenated, and may contain out-of-order records. @@ -40,7 +45,7 @@ def read_entry(f): if not header: return None typ = header[0:2] # 2 bytes of type - dlen = struct.unpack(" uint32.high: + return err("entry does not fit 32-bit length") + let start = ? getFilePos(f).mapErr(toString) ? append(f, typ) - ? append(f, toBytesLE(dataLen.uint64).toOpenArray(0, 5)) + ? append(f, toBytesLE(dataLen.uint32)) + ? append(f, [0'u8, 0'u8]) ok(start) @@ -137,9 +142,9 @@ proc readHeader(f: IoHandle): Result[Header, string] = typ: Type discard typ.copyFrom(buf) - # Cast safe because we had only 6 bytes of length data + # Cast safe because we had only 4 bytes of length data let - len = cast[int64](uint64.fromBytesLE(buf.toOpenArray(2, 9))) + len = cast[int64](uint32.fromBytesLE(buf.toOpenArray(2, 5))) # No point reading these.. if len > int.high(): return err("header length exceeds int.high") diff --git a/ncli/e2store.py b/ncli/e2store.py index f7825aa09..dc3109325 100644 --- a/ncli/e2store.py +++ b/ncli/e2store.py @@ -5,7 +5,7 @@ def read_entry(f): if not header: return (None, None) typ = header[0:2] # 2 bytes of type - dlen = struct.unpack("