forked from linkedin/goavro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_wrappers.go
More file actions
183 lines (163 loc) · 4.79 KB
/
gen_wrappers.go
File metadata and controls
183 lines (163 loc) · 4.79 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package goavro
import (
"fmt"
"math"
"math/big"
"time"
)
func StringNativeFromBinary(buf []byte) (string, []byte, error) {
thing, newBuf, err := stringNativeFromBinary(buf)
if err != nil {
return "", buf, err
}
return thing.(string), newBuf, nil
}
func StringNativePtrFromBinary(buf []byte) (*string, []byte, error) {
thing, newBuf, err := stringNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(string)
return &tmp, newBuf, nil
}
func LongNativeFromBinary(buf []byte) (int64, []byte, error) {
thing, newBuf, err := longNativeFromBinary(buf)
if err != nil {
return 0, buf, err
}
return thing.(int64), newBuf, nil
}
func LongNativePtrFromBinary(buf []byte) (*int64, []byte, error) {
thing, newBuf, err := longNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(int64)
return &tmp, newBuf, nil
}
func IntNativeFromBinary(buf []byte) (int32, []byte, error) {
thing, newBuf, err := intNativeFromBinary(buf)
if err != nil {
return 0, buf, err
}
return thing.(int32), newBuf, nil
}
func IntNativePtrFromBinary(buf []byte) (*int32, []byte, error) {
thing, newBuf, err := intNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(int32)
return &tmp, newBuf, nil
}
func IntEnumNativeFromBinary(buf []byte) (int, []byte, error) {
thing, newBuf, err := longNativeFromBinary(buf)
if err != nil {
return 0, buf, err
}
return int(thing.(int64)), newBuf, nil
}
func IntEnumPtrNativeFromBinary(buf []byte) (*int, []byte, error) {
thing, newBuf, err := longNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := int(thing.(int64))
return &tmp, newBuf, nil
}
func DoubleNativeFromBinary(buf []byte) (float64, []byte, error) {
thing, newBuf, err := doubleNativeFromBinary(buf)
if err != nil {
return 0, buf, err
}
return thing.(float64), newBuf, nil
}
func DoubleNativePtrFromBinary(buf []byte) (*float64, []byte, error) {
thing, newBuf, err := doubleNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(float64)
return &tmp, newBuf, nil
}
func FloatNativeFromBinary(buf []byte) (float32, []byte, error) {
thing, newBuf, err := floatNativeFromBinary(buf)
if err != nil {
return 0, buf, err
}
return thing.(float32), newBuf, nil
}
func FloatNativePtrFromBinary(buf []byte) (*float32, []byte, error) {
thing, newBuf, err := floatNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(float32)
return &tmp, newBuf, nil
}
func BoolNativeFromBinary(buf []byte) (bool, []byte, error) {
thing, newBuf, err := booleanNativeFromBinary(buf)
if err != nil {
return false, buf, err
}
return thing.(bool), newBuf, nil
}
func BoolNativePtrFromBinary(buf []byte) (*bool, []byte, error) {
thing, newBuf, err := booleanNativeFromBinary(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(bool)
return &tmp, newBuf, nil
}
func NativeFromBinaryDecimalBytes(buf []byte, precision int, scale int) (*big.Rat, []byte, error) {
thing, newBuf, err := nativeFromDecimalBytes(bytesNativeFromBinary, precision, scale)(buf)
if err != nil {
return &big.Rat{}, buf, err
}
return thing.(*big.Rat), newBuf, nil
}
func NativeFromBinaryDate(buf []byte) (time.Time, []byte, error) {
thing, newBuf, err := nativeFromDate(intNativeFromBinary)(buf)
if err != nil {
return time.Time{}, buf, err
}
return thing.(time.Time), newBuf, nil
}
func NativePtrFromBinaryDate(buf []byte) (*time.Time, []byte, error) {
thing, newBuf, err := nativeFromDate(intNativeFromBinary)(buf)
if err != nil {
return nil, buf, err
}
tmp := thing.(time.Time)
return &tmp, newBuf, nil
}
func DecodeBlockCount(buf []byte) (int64, []byte, error) {
// block count and block size
var value interface{}
var err error
newBuf := buf
if value, newBuf, err = longNativeFromBinary(newBuf); err != nil {
return 0, buf, fmt.Errorf("cannot decode binary array block count: %s", err)
}
blockCount := value.(int64)
if blockCount < 0 {
// NOTE: A negative block count implies there is a long encoded
// block size following the negative block count. We have no use
// for the block size in this decoder, so we read and discard
// the value.
if blockCount == math.MinInt64 {
// The minimum number for any signed numerical type can never be made positive
return 0, buf, fmt.Errorf("cannot decode binary array with block count: %d", blockCount)
}
blockCount = -blockCount // convert to its positive equivalent
if _, newBuf, err = longNativeFromBinary(newBuf); err != nil {
return 0, buf, fmt.Errorf("cannot decode binary array block size: %s", err)
}
}
// Ensure block count does not exceed some sane value.
if blockCount > MaxBlockCount {
return 0, buf, fmt.Errorf("cannot decode binary array when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount)
}
return blockCount, newBuf, nil
}