github.com/protolambda/zssz@v0.1.5/types/ssz_typ.go (about) 1 package types 2 3 import ( 4 . "github.com/protolambda/zssz/dec" 5 . "github.com/protolambda/zssz/enc" 6 . "github.com/protolambda/zssz/htr" 7 . "github.com/protolambda/zssz/pretty" 8 "unsafe" 9 ) 10 11 // Note: when this is changed, 12 // don't forget to change the ReadOffset/WriteOffset calls that handle the length value in this allocated space. 13 const BYTES_PER_LENGTH_OFFSET = 4 14 15 type ChangeMode byte 16 17 const ( 18 Equal = iota 19 Modified 20 Added 21 Deleted 22 ) 23 24 type Change struct { 25 Path string 26 Mode ChangeMode 27 Description string 28 } 29 30 type SSZFuzzInfo interface { 31 // The minimum length to read the object from fuzzing mode 32 FuzzMinLen() uint64 33 // The maximum length to read the object from fuzzing mode 34 FuzzMaxLen() uint64 35 } 36 37 type SSZInfo interface { 38 // The minimum length of the object. 39 // If the object is fixed-len, this should equal FixedLen() 40 MinLen() uint64 41 // The maximum length of the object. 42 // If the object is fixed-len, this should equal FixedLen() 43 MaxLen() uint64 44 // The length of the fixed-size part 45 FixedLen() uint64 46 // If the type is fixed-size 47 IsFixed() bool 48 // Check the format of serialized data, without decoding the contents into memory 49 DryCheck(dr *DecodingReader) error 50 } 51 52 type SSZMemory interface { 53 // Gets the encoded size of the data under the given pointer. 54 SizeOf(p unsafe.Pointer) uint64 55 // Reads object data from pointer, writes ssz-encoded data to EncodingWriter 56 // Returns (n, err), forwarded from the io.Writer being encoded into. 57 Encode(eb *EncodingWriter, p unsafe.Pointer) error 58 // Reads from input, populates object with read data 59 Decode(dr *DecodingReader, p unsafe.Pointer) error 60 // Hashes the object read at the given pointer 61 HashTreeRoot(h MerkleFn, pointer unsafe.Pointer) [32]byte 62 // Pretty print 63 Pretty(indent uint32, w *PrettyWriter, p unsafe.Pointer) 64 //// Diff two objects 65 //Diff(a unsafe.Pointer, b unsafe.Pointer) []Change 66 } 67 68 type SSZ interface { 69 SSZFuzzInfo 70 SSZInfo 71 SSZMemory 72 } 73 74 // SSZ definitions may also provide a way to compute a special hash-tree-root, for self-signed objects. 75 type SignedSSZ interface { 76 SSZ 77 SigningRoot(h MerkleFn, p unsafe.Pointer) [32]byte 78 }