MCPcopy Create free account
hub / github.com/deroproject/derohe / Serialize

Method Serialize

cryptography/crypto/protocol_structures.go:53–92  ·  view source on GitHub ↗
(w *bytes.Buffer)

Source from the content-addressed store, hash-verified

51}
52
53func (s *Statement) Serialize(w *bytes.Buffer) {
54 buf := make([]byte, binary.MaxVarintLen64)
55 //n := binary.PutUvarint(buf, uint64(len(s.Publickeylist)))
56 //w.Write(buf[:n])
57
58 if len(s.Publickeylist_pointers) == 0 {
59 power := byte(GetPowerof2(len(s.Publickeylist))) // len(s.Publickeylist) is always power of 2
60 w.WriteByte(power)
61 w.WriteByte(s.Bytes_per_publickey)
62
63 n := binary.PutUvarint(buf, s.Fees)
64 w.Write(buf[:n])
65
66 w.Write(s.D.EncodeCompressed())
67 s.Publickeylist_pointers = s.Publickeylist_pointers[:0]
68 for i := 0; i < len(s.Publickeylist); i++ {
69 hashed_key := graviton.Sum(s.Publickeylist[i].EncodeCompressed())
70 w.Write(hashed_key[:s.Bytes_per_publickey])
71 s.Publickeylist_pointers = append(s.Publickeylist_pointers, hashed_key[:s.Bytes_per_publickey]...)
72 }
73 } else {
74 power := byte(GetPowerof2(len(s.Publickeylist_pointers) / int(s.Bytes_per_publickey))) // len(s.Publickeylist) is always power of 2
75 w.WriteByte(power)
76 w.WriteByte(s.Bytes_per_publickey)
77 n := binary.PutUvarint(buf, s.Fees)
78 w.Write(buf[:n])
79 w.Write(s.D.EncodeCompressed())
80 w.Write(s.Publickeylist_pointers[:])
81 }
82
83 for i := 0; i < len(s.Publickeylist_pointers)/int(s.Bytes_per_publickey); i++ {
84 // w.Write( s.CLn[i].EncodeCompressed()) /// this is expanded from graviton store
85 // w.Write( s.CRn[i].EncodeCompressed()) /// this is expanded from graviton store
86 //w.Write(s.Publickeylist[i].EncodeCompressed()) /// this is expanded from graviton store
87 w.Write(s.C[i].EncodeCompressed())
88 }
89
90 w.Write(s.Roothash[:])
91
92}
93
94func (s *Statement) Deserialize(r *bytes.Reader) error {
95

Callers

nothing calls this directly

Calls 4

GetPowerof2Function · 0.85
WriteMethod · 0.45
EncodeCompressedMethod · 0.45
SumMethod · 0.45

Tested by

no test coverage detected