-
Notifications
You must be signed in to change notification settings - Fork 0
/
consume.go
117 lines (87 loc) · 2.26 KB
/
consume.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package jq
import "nikand.dev/go/cbor"
type (
Int int
Int64 int64
Uint64 uint64
Float64 float64
Bytes []byte
BytesCopy []byte
BytesAppend []byte
)
func (f *Int) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Int && tag != cbor.Neg {
return None, false, fe(f, off, NewTypeError(tag, cbor.Int, cbor.Neg))
}
*(*int)(f) = br.Int(off)
return None, false, nil
}
func (f *Int64) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Int && tag != cbor.Neg {
return None, false, fe(f, off, NewTypeError(tag, cbor.Int, cbor.Neg))
}
*(*int64)(f) = br.Signed(off)
return None, false, nil
}
func (f *Uint64) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Int {
return None, false, fe(f, off, NewTypeError(tag, cbor.Int))
}
*(*uint64)(f) = br.Unsigned(off)
return None, false, nil
}
func (f *Float64) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Int && tag != cbor.Neg {
return None, false, fe(f, off, NewTypeError(tag, cbor.Int, cbor.Neg))
}
*(*float64)(f) = br.Float(off)
return None, false, nil
}
func (f *Bytes) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Bytes && tag != cbor.String {
return None, false, fe(f, off, NewTypeError(tag, cbor.Bytes, cbor.String))
}
*(*[]byte)(f) = br.Bytes(off)
return None, false, nil
}
func (f *BytesCopy) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
*f = (*f)[:0]
return (*BytesAppend)(f).ApplyTo(b, off, next)
}
func (f *BytesAppend) ApplyTo(b *Buffer, off Off, next bool) (Off, bool, error) {
if next {
return None, false, nil
}
br := b.Reader()
tag := br.Tag(off)
if tag != cbor.Bytes && tag != cbor.String {
return None, false, fe(f, off, NewTypeError(tag, cbor.Bytes, cbor.String))
}
*f = append((*f), br.Bytes(off)...)
return None, false, nil
}