-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuple.go
More file actions
52 lines (45 loc) · 891 Bytes
/
tuple.go
File metadata and controls
52 lines (45 loc) · 891 Bytes
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
package scale
import "bytes"
type CompactTuple struct {
Val []Compact
}
func (c *CompactTuple) Encode() ([]byte, error) {
var buf bytes.Buffer
for _, v := range c.Val {
res, err := v.Encode()
if err != nil {
return nil, err
}
buf.Write(res)
}
return buf.Bytes(), nil
}
func (c *CompactTuple) Decode(value []byte) (int, error) {
var offset int
for i, v := range c.Val {
if len(value) == 0 {
return 0, nil
}
tempOffset, err := v.Decode(value)
if err != nil {
return 0, err
}
c.Val[i] = v
offset += tempOffset
value = value[tempOffset:]
}
return offset, nil
}
func (c *CompactTuple) GetVal() interface{} {
return c.Val
}
func (c *CompactTuple) GetType() PrimitiveType {
return Tuple
}
func (c *CompactTuple) CloneNew() Compact {
temp := &CompactTuple{}
for _, v := range c.Val {
temp.Val = append(temp.Val, v.CloneNew())
}
return temp
}