-
Notifications
You must be signed in to change notification settings - Fork 1
/
encoding.go
57 lines (44 loc) · 1.29 KB
/
encoding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lms
import (
"bytes"
"encoding/gob"
)
// Serialize marshals a prkg into gob bytes
func (prkg *KeyIterator) Serialize() ([]byte, error) {
buf := new(bytes.Buffer)
if err := gob.NewEncoder(buf).Encode(prkg); nil != err {
return nil, err
}
return buf.Bytes(), nil
}
// Deserialize unmarshals the prkg from gob bytes
func (prkg *KeyIterator) Deserialize(data []byte) error {
return gob.NewDecoder(bytes.NewBuffer(data)).Decode(prkg)
}
// Serialize marshals a MerkleSig into gob bytes
func (sig *MerkleSig) Serialize() ([]byte, error) {
buf := new(bytes.Buffer)
enc := gob.NewEncoder(buf)
if err := enc.Encode(sig); nil != err {
return nil, err
}
return buf.Bytes(), nil
}
// Deserialize unmarshals the MerkleSig from gob bytes
func (sig *MerkleSig) Deserialize(data []byte) error {
buf := bytes.NewBuffer(data)
dec := gob.NewDecoder(buf)
return dec.Decode(sig)
}
// Serialize marshals the TreeHashStack as Gob bytes
func (ths *TreeHashStack) Serialize() ([]byte, error) {
buf := new(bytes.Buffer)
if err := gob.NewEncoder(buf).Encode(ths); nil != err {
return nil, err
}
return buf.Bytes(), nil
}
// Deserialize unmarshals the TreeHashStack from the Gob bytes
func (ths *TreeHashStack) Deserialize(data []byte) error {
return gob.NewDecoder(bytes.NewBuffer(data)).Decode(ths)
}