8 // A SOffsetT stores a signed offset into arbitrary data.
10 // A UOffsetT stores an unsigned offset into vector data.
12 // A VOffsetT stores an unsigned offset in a vtable.
17 // VtableMetadataFields is the count of metadata fields in each vtable.
18 VtableMetadataFields = 2
21 // GetByte decodes a little-endian byte from a byte slice.
22 func GetByte(buf []byte) byte {
23 return byte(GetUint8(buf))
26 // GetBool decodes a little-endian bool from a byte slice.
27 func GetBool(buf []byte) bool {
31 // GetUint8 decodes a little-endian uint8 from a byte slice.
32 func GetUint8(buf []byte) (n uint8) {
37 // GetUint16 decodes a little-endian uint16 from a byte slice.
38 func GetUint16(buf []byte) (n uint16) {
39 _ = buf[1] // Force one bounds check. See: golang.org/issue/14808
41 n |= uint16(buf[1]) << 8
45 // GetUint32 decodes a little-endian uint32 from a byte slice.
46 func GetUint32(buf []byte) (n uint32) {
47 _ = buf[3] // Force one bounds check. See: golang.org/issue/14808
49 n |= uint32(buf[1]) << 8
50 n |= uint32(buf[2]) << 16
51 n |= uint32(buf[3]) << 24
55 // GetUint64 decodes a little-endian uint64 from a byte slice.
56 func GetUint64(buf []byte) (n uint64) {
57 _ = buf[7] // Force one bounds check. See: golang.org/issue/14808
59 n |= uint64(buf[1]) << 8
60 n |= uint64(buf[2]) << 16
61 n |= uint64(buf[3]) << 24
62 n |= uint64(buf[4]) << 32
63 n |= uint64(buf[5]) << 40
64 n |= uint64(buf[6]) << 48
65 n |= uint64(buf[7]) << 56
69 // GetInt8 decodes a little-endian int8 from a byte slice.
70 func GetInt8(buf []byte) (n int8) {
75 // GetInt16 decodes a little-endian int16 from a byte slice.
76 func GetInt16(buf []byte) (n int16) {
77 _ = buf[1] // Force one bounds check. See: golang.org/issue/14808
79 n |= int16(buf[1]) << 8
83 // GetInt32 decodes a little-endian int32 from a byte slice.
84 func GetInt32(buf []byte) (n int32) {
85 _ = buf[3] // Force one bounds check. See: golang.org/issue/14808
87 n |= int32(buf[1]) << 8
88 n |= int32(buf[2]) << 16
89 n |= int32(buf[3]) << 24
93 // GetInt64 decodes a little-endian int64 from a byte slice.
94 func GetInt64(buf []byte) (n int64) {
95 _ = buf[7] // Force one bounds check. See: golang.org/issue/14808
97 n |= int64(buf[1]) << 8
98 n |= int64(buf[2]) << 16
99 n |= int64(buf[3]) << 24
100 n |= int64(buf[4]) << 32
101 n |= int64(buf[5]) << 40
102 n |= int64(buf[6]) << 48
103 n |= int64(buf[7]) << 56
107 // GetFloat32 decodes a little-endian float32 from a byte slice.
108 func GetFloat32(buf []byte) float32 {
110 return math.Float32frombits(x)
113 // GetFloat64 decodes a little-endian float64 from a byte slice.
114 func GetFloat64(buf []byte) float64 {
116 return math.Float64frombits(x)
119 // GetUOffsetT decodes a little-endian UOffsetT from a byte slice.
120 func GetUOffsetT(buf []byte) UOffsetT {
121 return UOffsetT(GetUint32(buf))
124 // GetSOffsetT decodes a little-endian SOffsetT from a byte slice.
125 func GetSOffsetT(buf []byte) SOffsetT {
126 return SOffsetT(GetInt32(buf))
129 // GetVOffsetT decodes a little-endian VOffsetT from a byte slice.
130 func GetVOffsetT(buf []byte) VOffsetT {
131 return VOffsetT(GetUint16(buf))
134 // WriteByte encodes a little-endian uint8 into a byte slice.
135 func WriteByte(buf []byte, n byte) {
136 WriteUint8(buf, uint8(n))
139 // WriteBool encodes a little-endian bool into a byte slice.
140 func WriteBool(buf []byte, b bool) {
147 // WriteUint8 encodes a little-endian uint8 into a byte slice.
148 func WriteUint8(buf []byte, n uint8) {
152 // WriteUint16 encodes a little-endian uint16 into a byte slice.
153 func WriteUint16(buf []byte, n uint16) {
154 _ = buf[1] // Force one bounds check. See: golang.org/issue/14808
156 buf[1] = byte(n >> 8)
159 // WriteUint32 encodes a little-endian uint32 into a byte slice.
160 func WriteUint32(buf []byte, n uint32) {
161 _ = buf[3] // Force one bounds check. See: golang.org/issue/14808
163 buf[1] = byte(n >> 8)
164 buf[2] = byte(n >> 16)
165 buf[3] = byte(n >> 24)
168 // WriteUint64 encodes a little-endian uint64 into a byte slice.
169 func WriteUint64(buf []byte, n uint64) {
170 _ = buf[7] // Force one bounds check. See: golang.org/issue/14808
172 buf[1] = byte(n >> 8)
173 buf[2] = byte(n >> 16)
174 buf[3] = byte(n >> 24)
175 buf[4] = byte(n >> 32)
176 buf[5] = byte(n >> 40)
177 buf[6] = byte(n >> 48)
178 buf[7] = byte(n >> 56)
181 // WriteInt8 encodes a little-endian int8 into a byte slice.
182 func WriteInt8(buf []byte, n int8) {
186 // WriteInt16 encodes a little-endian int16 into a byte slice.
187 func WriteInt16(buf []byte, n int16) {
188 _ = buf[1] // Force one bounds check. See: golang.org/issue/14808
190 buf[1] = byte(n >> 8)
193 // WriteInt32 encodes a little-endian int32 into a byte slice.
194 func WriteInt32(buf []byte, n int32) {
195 _ = buf[3] // Force one bounds check. See: golang.org/issue/14808
197 buf[1] = byte(n >> 8)
198 buf[2] = byte(n >> 16)
199 buf[3] = byte(n >> 24)
202 // WriteInt64 encodes a little-endian int64 into a byte slice.
203 func WriteInt64(buf []byte, n int64) {
204 _ = buf[7] // Force one bounds check. See: golang.org/issue/14808
206 buf[1] = byte(n >> 8)
207 buf[2] = byte(n >> 16)
208 buf[3] = byte(n >> 24)
209 buf[4] = byte(n >> 32)
210 buf[5] = byte(n >> 40)
211 buf[6] = byte(n >> 48)
212 buf[7] = byte(n >> 56)
215 // WriteFloat32 encodes a little-endian float32 into a byte slice.
216 func WriteFloat32(buf []byte, n float32) {
217 WriteUint32(buf, math.Float32bits(n))
220 // WriteFloat64 encodes a little-endian float64 into a byte slice.
221 func WriteFloat64(buf []byte, n float64) {
222 WriteUint64(buf, math.Float64bits(n))
225 // WriteVOffsetT encodes a little-endian VOffsetT into a byte slice.
226 func WriteVOffsetT(buf []byte, n VOffsetT) {
227 WriteUint16(buf, uint16(n))
230 // WriteSOffsetT encodes a little-endian SOffsetT into a byte slice.
231 func WriteSOffsetT(buf []byte, n SOffsetT) {
232 WriteInt32(buf, int32(n))
235 // WriteUOffsetT encodes a little-endian UOffsetT into a byte slice.
236 func WriteUOffsetT(buf []byte, n UOffsetT) {
237 WriteUint32(buf, uint32(n))