Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style. |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Code generated by generate-types. DO NOT EDIT. |
| 6 | |
| 7 | package impl |
| 8 | |
| 9 | import ( |
| 10 | "math" |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 11 | "unicode/utf8" |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 12 | |
| 13 | "google.golang.org/protobuf/internal/encoding/wire" |
| 14 | "google.golang.org/protobuf/reflect/protoreflect" |
| 15 | ) |
| 16 | |
| 17 | // sizeBool returns the size of wire encoding a bool pointer as a Bool. |
| 18 | func sizeBool(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 19 | v := *p.Bool() |
| 20 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 21 | } |
| 22 | |
| 23 | // appendBool wire encodes a bool pointer as a Bool. |
| 24 | func appendBool(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 25 | v := *p.Bool() |
| 26 | b = wire.AppendVarint(b, wiretag) |
| 27 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 28 | return b, nil |
| 29 | } |
| 30 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 31 | // consumeBool wire decodes a bool pointer as a Bool. |
| 32 | func consumeBool(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 33 | if wtyp != wire.VarintType { |
| 34 | return 0, errUnknown |
| 35 | } |
| 36 | v, n := wire.ConsumeVarint(b) |
| 37 | if n < 0 { |
| 38 | return 0, wire.ParseError(n) |
| 39 | } |
| 40 | *p.Bool() = wire.DecodeBool(v) |
| 41 | return n, nil |
| 42 | } |
| 43 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 44 | var coderBool = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 45 | size: sizeBool, |
| 46 | marshal: appendBool, |
| 47 | unmarshal: consumeBool, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 50 | // sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 51 | // The zero value is not encoded. |
| 52 | func sizeBoolNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 53 | v := *p.Bool() |
| 54 | if v == false { |
| 55 | return 0 |
| 56 | } |
| 57 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 58 | } |
| 59 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 60 | // appendBoolNoZero wire encodes a bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 61 | // The zero value is not encoded. |
| 62 | func appendBoolNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 63 | v := *p.Bool() |
| 64 | if v == false { |
| 65 | return b, nil |
| 66 | } |
| 67 | b = wire.AppendVarint(b, wiretag) |
| 68 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 69 | return b, nil |
| 70 | } |
| 71 | |
| 72 | var coderBoolNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 73 | size: sizeBoolNoZero, |
| 74 | marshal: appendBoolNoZero, |
| 75 | unmarshal: consumeBool, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool. |
| 79 | // It panics if the pointer is nil. |
| 80 | func sizeBoolPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 81 | v := **p.BoolPtr() |
| 82 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 83 | } |
| 84 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 85 | // appendBoolPtr wire encodes a *bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 86 | // It panics if the pointer is nil. |
| 87 | func appendBoolPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 88 | v := **p.BoolPtr() |
| 89 | b = wire.AppendVarint(b, wiretag) |
| 90 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 91 | return b, nil |
| 92 | } |
| 93 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 94 | // consumeBoolPtr wire decodes a *bool pointer as a Bool. |
| 95 | func consumeBoolPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 96 | if wtyp != wire.VarintType { |
| 97 | return 0, errUnknown |
| 98 | } |
| 99 | v, n := wire.ConsumeVarint(b) |
| 100 | if n < 0 { |
| 101 | return 0, wire.ParseError(n) |
| 102 | } |
| 103 | vp := p.BoolPtr() |
| 104 | if *vp == nil { |
| 105 | *vp = new(bool) |
| 106 | } |
| 107 | **vp = wire.DecodeBool(v) |
| 108 | return n, nil |
| 109 | } |
| 110 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 111 | var coderBoolPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 112 | size: sizeBoolPtr, |
| 113 | marshal: appendBoolPtr, |
| 114 | unmarshal: consumeBoolPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool. |
| 118 | func sizeBoolSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 119 | s := *p.BoolSlice() |
| 120 | for _, v := range s { |
| 121 | size += tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 122 | } |
| 123 | return size |
| 124 | } |
| 125 | |
| 126 | // appendBoolSlice encodes a []bool pointer as a repeated Bool. |
| 127 | func appendBoolSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 128 | s := *p.BoolSlice() |
| 129 | for _, v := range s { |
| 130 | b = wire.AppendVarint(b, wiretag) |
| 131 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 132 | } |
| 133 | return b, nil |
| 134 | } |
| 135 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 136 | // consumeBoolSlice wire decodes a []bool pointer as a repeated Bool. |
| 137 | func consumeBoolSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 138 | sp := p.BoolSlice() |
| 139 | if wtyp == wire.BytesType { |
| 140 | s := *sp |
| 141 | b, n = wire.ConsumeBytes(b) |
| 142 | if n < 0 { |
| 143 | return 0, wire.ParseError(n) |
| 144 | } |
| 145 | for len(b) > 0 { |
| 146 | v, n := wire.ConsumeVarint(b) |
| 147 | if n < 0 { |
| 148 | return 0, wire.ParseError(n) |
| 149 | } |
| 150 | s = append(s, wire.DecodeBool(v)) |
| 151 | b = b[n:] |
| 152 | } |
| 153 | *sp = s |
| 154 | return n, nil |
| 155 | } |
| 156 | if wtyp != wire.VarintType { |
| 157 | return 0, errUnknown |
| 158 | } |
| 159 | v, n := wire.ConsumeVarint(b) |
| 160 | if n < 0 { |
| 161 | return 0, wire.ParseError(n) |
| 162 | } |
| 163 | *sp = append(*sp, wire.DecodeBool(v)) |
| 164 | return n, nil |
| 165 | } |
| 166 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 167 | var coderBoolSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 168 | size: sizeBoolSlice, |
| 169 | marshal: appendBoolSlice, |
| 170 | unmarshal: consumeBoolSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool. |
| 174 | func sizeBoolPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 175 | s := *p.BoolSlice() |
| 176 | if len(s) == 0 { |
| 177 | return 0 |
| 178 | } |
| 179 | n := 0 |
| 180 | for _, v := range s { |
| 181 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 182 | } |
| 183 | return tagsize + wire.SizeBytes(n) |
| 184 | } |
| 185 | |
| 186 | // appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool. |
| 187 | func appendBoolPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 188 | s := *p.BoolSlice() |
| 189 | if len(s) == 0 { |
| 190 | return b, nil |
| 191 | } |
| 192 | b = wire.AppendVarint(b, wiretag) |
| 193 | n := 0 |
| 194 | for _, v := range s { |
| 195 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 196 | } |
| 197 | b = wire.AppendVarint(b, uint64(n)) |
| 198 | for _, v := range s { |
| 199 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 200 | } |
| 201 | return b, nil |
| 202 | } |
| 203 | |
| 204 | var coderBoolPackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 205 | size: sizeBoolPackedSlice, |
| 206 | marshal: appendBoolPackedSlice, |
| 207 | unmarshal: consumeBoolSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // sizeBoolIface returns the size of wire encoding a bool value as a Bool. |
| 211 | func sizeBoolIface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 212 | v := ival.(bool) |
| 213 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 214 | } |
| 215 | |
| 216 | // appendBoolIface encodes a bool value as a Bool. |
| 217 | func appendBoolIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 218 | v := ival.(bool) |
| 219 | b = wire.AppendVarint(b, wiretag) |
| 220 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 221 | return b, nil |
| 222 | } |
| 223 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 224 | // consumeBoolIface decodes a bool value as a Bool. |
| 225 | func consumeBoolIface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 226 | if wtyp != wire.VarintType { |
| 227 | return nil, 0, errUnknown |
| 228 | } |
| 229 | v, n := wire.ConsumeVarint(b) |
| 230 | if n < 0 { |
| 231 | return nil, 0, wire.ParseError(n) |
| 232 | } |
| 233 | return wire.DecodeBool(v), n, nil |
| 234 | } |
| 235 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 236 | var coderBoolIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 237 | size: sizeBoolIface, |
| 238 | marshal: appendBoolIface, |
| 239 | unmarshal: consumeBoolIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // sizeBoolSliceIface returns the size of wire encoding a []bool value as a repeated Bool. |
| 243 | func sizeBoolSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 244 | s := *ival.(*[]bool) |
| 245 | for _, v := range s { |
| 246 | size += tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 247 | } |
| 248 | return size |
| 249 | } |
| 250 | |
| 251 | // appendBoolSliceIface encodes a []bool value as a repeated Bool. |
| 252 | func appendBoolSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 253 | s := *ival.(*[]bool) |
| 254 | for _, v := range s { |
| 255 | b = wire.AppendVarint(b, wiretag) |
| 256 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 257 | } |
| 258 | return b, nil |
| 259 | } |
| 260 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 261 | // consumeBoolSliceIface wire decodes a []bool value as a repeated Bool. |
| 262 | func consumeBoolSliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 263 | sp := ival.(*[]bool) |
| 264 | if wtyp == wire.BytesType { |
| 265 | s := *sp |
| 266 | b, n = wire.ConsumeBytes(b) |
| 267 | if n < 0 { |
| 268 | return nil, 0, wire.ParseError(n) |
| 269 | } |
| 270 | for len(b) > 0 { |
| 271 | v, n := wire.ConsumeVarint(b) |
| 272 | if n < 0 { |
| 273 | return nil, 0, wire.ParseError(n) |
| 274 | } |
| 275 | s = append(s, wire.DecodeBool(v)) |
| 276 | b = b[n:] |
| 277 | } |
| 278 | *sp = s |
| 279 | return ival, n, nil |
| 280 | } |
| 281 | if wtyp != wire.VarintType { |
| 282 | return nil, 0, errUnknown |
| 283 | } |
| 284 | v, n := wire.ConsumeVarint(b) |
| 285 | if n < 0 { |
| 286 | return nil, 0, wire.ParseError(n) |
| 287 | } |
| 288 | *sp = append(*sp, wire.DecodeBool(v)) |
| 289 | return ival, n, nil |
| 290 | } |
| 291 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 292 | var coderBoolSliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 293 | size: sizeBoolSliceIface, |
| 294 | marshal: appendBoolSliceIface, |
| 295 | unmarshal: consumeBoolSliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 298 | // sizeBoolPackedSliceIface returns the size of wire encoding a []bool value as a packed repeated Bool. |
| 299 | func sizeBoolPackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 300 | s := *ival.(*[]bool) |
| 301 | if len(s) == 0 { |
| 302 | return 0 |
| 303 | } |
| 304 | n := 0 |
| 305 | for _, v := range s { |
| 306 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 307 | } |
| 308 | return tagsize + wire.SizeBytes(n) |
| 309 | } |
| 310 | |
| 311 | // appendBoolPackedSliceIface encodes a []bool value as a packed repeated Bool. |
| 312 | func appendBoolPackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 313 | s := *ival.(*[]bool) |
| 314 | if len(s) == 0 { |
| 315 | return b, nil |
| 316 | } |
| 317 | b = wire.AppendVarint(b, wiretag) |
| 318 | n := 0 |
| 319 | for _, v := range s { |
| 320 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 321 | } |
| 322 | b = wire.AppendVarint(b, uint64(n)) |
| 323 | for _, v := range s { |
| 324 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 325 | } |
| 326 | return b, nil |
| 327 | } |
| 328 | |
| 329 | var coderBoolPackedSliceIface = ifaceCoderFuncs{ |
| 330 | size: sizeBoolPackedSliceIface, |
| 331 | marshal: appendBoolPackedSliceIface, |
| 332 | unmarshal: consumeBoolSliceIface, |
| 333 | } |
| 334 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 335 | // sizeInt32 returns the size of wire encoding a int32 pointer as a Int32. |
| 336 | func sizeInt32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 337 | v := *p.Int32() |
| 338 | return tagsize + wire.SizeVarint(uint64(v)) |
| 339 | } |
| 340 | |
| 341 | // appendInt32 wire encodes a int32 pointer as a Int32. |
| 342 | func appendInt32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 343 | v := *p.Int32() |
| 344 | b = wire.AppendVarint(b, wiretag) |
| 345 | b = wire.AppendVarint(b, uint64(v)) |
| 346 | return b, nil |
| 347 | } |
| 348 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 349 | // consumeInt32 wire decodes a int32 pointer as a Int32. |
| 350 | func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 351 | if wtyp != wire.VarintType { |
| 352 | return 0, errUnknown |
| 353 | } |
| 354 | v, n := wire.ConsumeVarint(b) |
| 355 | if n < 0 { |
| 356 | return 0, wire.ParseError(n) |
| 357 | } |
| 358 | *p.Int32() = int32(v) |
| 359 | return n, nil |
| 360 | } |
| 361 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 362 | var coderInt32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 363 | size: sizeInt32, |
| 364 | marshal: appendInt32, |
| 365 | unmarshal: consumeInt32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 368 | // sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 369 | // The zero value is not encoded. |
| 370 | func sizeInt32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 371 | v := *p.Int32() |
| 372 | if v == 0 { |
| 373 | return 0 |
| 374 | } |
| 375 | return tagsize + wire.SizeVarint(uint64(v)) |
| 376 | } |
| 377 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 378 | // appendInt32NoZero wire encodes a int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 379 | // The zero value is not encoded. |
| 380 | func appendInt32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 381 | v := *p.Int32() |
| 382 | if v == 0 { |
| 383 | return b, nil |
| 384 | } |
| 385 | b = wire.AppendVarint(b, wiretag) |
| 386 | b = wire.AppendVarint(b, uint64(v)) |
| 387 | return b, nil |
| 388 | } |
| 389 | |
| 390 | var coderInt32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 391 | size: sizeInt32NoZero, |
| 392 | marshal: appendInt32NoZero, |
| 393 | unmarshal: consumeInt32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32. |
| 397 | // It panics if the pointer is nil. |
| 398 | func sizeInt32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 399 | v := **p.Int32Ptr() |
| 400 | return tagsize + wire.SizeVarint(uint64(v)) |
| 401 | } |
| 402 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 403 | // appendInt32Ptr wire encodes a *int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 404 | // It panics if the pointer is nil. |
| 405 | func appendInt32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 406 | v := **p.Int32Ptr() |
| 407 | b = wire.AppendVarint(b, wiretag) |
| 408 | b = wire.AppendVarint(b, uint64(v)) |
| 409 | return b, nil |
| 410 | } |
| 411 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 412 | // consumeInt32Ptr wire decodes a *int32 pointer as a Int32. |
| 413 | func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 414 | if wtyp != wire.VarintType { |
| 415 | return 0, errUnknown |
| 416 | } |
| 417 | v, n := wire.ConsumeVarint(b) |
| 418 | if n < 0 { |
| 419 | return 0, wire.ParseError(n) |
| 420 | } |
| 421 | vp := p.Int32Ptr() |
| 422 | if *vp == nil { |
| 423 | *vp = new(int32) |
| 424 | } |
| 425 | **vp = int32(v) |
| 426 | return n, nil |
| 427 | } |
| 428 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 429 | var coderInt32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 430 | size: sizeInt32Ptr, |
| 431 | marshal: appendInt32Ptr, |
| 432 | unmarshal: consumeInt32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32. |
| 436 | func sizeInt32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 437 | s := *p.Int32Slice() |
| 438 | for _, v := range s { |
| 439 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 440 | } |
| 441 | return size |
| 442 | } |
| 443 | |
| 444 | // appendInt32Slice encodes a []int32 pointer as a repeated Int32. |
| 445 | func appendInt32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 446 | s := *p.Int32Slice() |
| 447 | for _, v := range s { |
| 448 | b = wire.AppendVarint(b, wiretag) |
| 449 | b = wire.AppendVarint(b, uint64(v)) |
| 450 | } |
| 451 | return b, nil |
| 452 | } |
| 453 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 454 | // consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32. |
| 455 | func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 456 | sp := p.Int32Slice() |
| 457 | if wtyp == wire.BytesType { |
| 458 | s := *sp |
| 459 | b, n = wire.ConsumeBytes(b) |
| 460 | if n < 0 { |
| 461 | return 0, wire.ParseError(n) |
| 462 | } |
| 463 | for len(b) > 0 { |
| 464 | v, n := wire.ConsumeVarint(b) |
| 465 | if n < 0 { |
| 466 | return 0, wire.ParseError(n) |
| 467 | } |
| 468 | s = append(s, int32(v)) |
| 469 | b = b[n:] |
| 470 | } |
| 471 | *sp = s |
| 472 | return n, nil |
| 473 | } |
| 474 | if wtyp != wire.VarintType { |
| 475 | return 0, errUnknown |
| 476 | } |
| 477 | v, n := wire.ConsumeVarint(b) |
| 478 | if n < 0 { |
| 479 | return 0, wire.ParseError(n) |
| 480 | } |
| 481 | *sp = append(*sp, int32(v)) |
| 482 | return n, nil |
| 483 | } |
| 484 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 485 | var coderInt32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 486 | size: sizeInt32Slice, |
| 487 | marshal: appendInt32Slice, |
| 488 | unmarshal: consumeInt32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | // sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32. |
| 492 | func sizeInt32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 493 | s := *p.Int32Slice() |
| 494 | if len(s) == 0 { |
| 495 | return 0 |
| 496 | } |
| 497 | n := 0 |
| 498 | for _, v := range s { |
| 499 | n += wire.SizeVarint(uint64(v)) |
| 500 | } |
| 501 | return tagsize + wire.SizeBytes(n) |
| 502 | } |
| 503 | |
| 504 | // appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32. |
| 505 | func appendInt32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 506 | s := *p.Int32Slice() |
| 507 | if len(s) == 0 { |
| 508 | return b, nil |
| 509 | } |
| 510 | b = wire.AppendVarint(b, wiretag) |
| 511 | n := 0 |
| 512 | for _, v := range s { |
| 513 | n += wire.SizeVarint(uint64(v)) |
| 514 | } |
| 515 | b = wire.AppendVarint(b, uint64(n)) |
| 516 | for _, v := range s { |
| 517 | b = wire.AppendVarint(b, uint64(v)) |
| 518 | } |
| 519 | return b, nil |
| 520 | } |
| 521 | |
| 522 | var coderInt32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 523 | size: sizeInt32PackedSlice, |
| 524 | marshal: appendInt32PackedSlice, |
| 525 | unmarshal: consumeInt32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | // sizeInt32Iface returns the size of wire encoding a int32 value as a Int32. |
| 529 | func sizeInt32Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 530 | v := ival.(int32) |
| 531 | return tagsize + wire.SizeVarint(uint64(v)) |
| 532 | } |
| 533 | |
| 534 | // appendInt32Iface encodes a int32 value as a Int32. |
| 535 | func appendInt32Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 536 | v := ival.(int32) |
| 537 | b = wire.AppendVarint(b, wiretag) |
| 538 | b = wire.AppendVarint(b, uint64(v)) |
| 539 | return b, nil |
| 540 | } |
| 541 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 542 | // consumeInt32Iface decodes a int32 value as a Int32. |
| 543 | func consumeInt32Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 544 | if wtyp != wire.VarintType { |
| 545 | return nil, 0, errUnknown |
| 546 | } |
| 547 | v, n := wire.ConsumeVarint(b) |
| 548 | if n < 0 { |
| 549 | return nil, 0, wire.ParseError(n) |
| 550 | } |
| 551 | return int32(v), n, nil |
| 552 | } |
| 553 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 554 | var coderInt32Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 555 | size: sizeInt32Iface, |
| 556 | marshal: appendInt32Iface, |
| 557 | unmarshal: consumeInt32Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | // sizeInt32SliceIface returns the size of wire encoding a []int32 value as a repeated Int32. |
| 561 | func sizeInt32SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 562 | s := *ival.(*[]int32) |
| 563 | for _, v := range s { |
| 564 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 565 | } |
| 566 | return size |
| 567 | } |
| 568 | |
| 569 | // appendInt32SliceIface encodes a []int32 value as a repeated Int32. |
| 570 | func appendInt32SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 571 | s := *ival.(*[]int32) |
| 572 | for _, v := range s { |
| 573 | b = wire.AppendVarint(b, wiretag) |
| 574 | b = wire.AppendVarint(b, uint64(v)) |
| 575 | } |
| 576 | return b, nil |
| 577 | } |
| 578 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 579 | // consumeInt32SliceIface wire decodes a []int32 value as a repeated Int32. |
| 580 | func consumeInt32SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 581 | sp := ival.(*[]int32) |
| 582 | if wtyp == wire.BytesType { |
| 583 | s := *sp |
| 584 | b, n = wire.ConsumeBytes(b) |
| 585 | if n < 0 { |
| 586 | return nil, 0, wire.ParseError(n) |
| 587 | } |
| 588 | for len(b) > 0 { |
| 589 | v, n := wire.ConsumeVarint(b) |
| 590 | if n < 0 { |
| 591 | return nil, 0, wire.ParseError(n) |
| 592 | } |
| 593 | s = append(s, int32(v)) |
| 594 | b = b[n:] |
| 595 | } |
| 596 | *sp = s |
| 597 | return ival, n, nil |
| 598 | } |
| 599 | if wtyp != wire.VarintType { |
| 600 | return nil, 0, errUnknown |
| 601 | } |
| 602 | v, n := wire.ConsumeVarint(b) |
| 603 | if n < 0 { |
| 604 | return nil, 0, wire.ParseError(n) |
| 605 | } |
| 606 | *sp = append(*sp, int32(v)) |
| 607 | return ival, n, nil |
| 608 | } |
| 609 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 610 | var coderInt32SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 611 | size: sizeInt32SliceIface, |
| 612 | marshal: appendInt32SliceIface, |
| 613 | unmarshal: consumeInt32SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 616 | // sizeInt32PackedSliceIface returns the size of wire encoding a []int32 value as a packed repeated Int32. |
| 617 | func sizeInt32PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 618 | s := *ival.(*[]int32) |
| 619 | if len(s) == 0 { |
| 620 | return 0 |
| 621 | } |
| 622 | n := 0 |
| 623 | for _, v := range s { |
| 624 | n += wire.SizeVarint(uint64(v)) |
| 625 | } |
| 626 | return tagsize + wire.SizeBytes(n) |
| 627 | } |
| 628 | |
| 629 | // appendInt32PackedSliceIface encodes a []int32 value as a packed repeated Int32. |
| 630 | func appendInt32PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 631 | s := *ival.(*[]int32) |
| 632 | if len(s) == 0 { |
| 633 | return b, nil |
| 634 | } |
| 635 | b = wire.AppendVarint(b, wiretag) |
| 636 | n := 0 |
| 637 | for _, v := range s { |
| 638 | n += wire.SizeVarint(uint64(v)) |
| 639 | } |
| 640 | b = wire.AppendVarint(b, uint64(n)) |
| 641 | for _, v := range s { |
| 642 | b = wire.AppendVarint(b, uint64(v)) |
| 643 | } |
| 644 | return b, nil |
| 645 | } |
| 646 | |
| 647 | var coderInt32PackedSliceIface = ifaceCoderFuncs{ |
| 648 | size: sizeInt32PackedSliceIface, |
| 649 | marshal: appendInt32PackedSliceIface, |
| 650 | unmarshal: consumeInt32SliceIface, |
| 651 | } |
| 652 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 653 | // sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32. |
| 654 | func sizeSint32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 655 | v := *p.Int32() |
| 656 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 657 | } |
| 658 | |
| 659 | // appendSint32 wire encodes a int32 pointer as a Sint32. |
| 660 | func appendSint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 661 | v := *p.Int32() |
| 662 | b = wire.AppendVarint(b, wiretag) |
| 663 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 664 | return b, nil |
| 665 | } |
| 666 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 667 | // consumeSint32 wire decodes a int32 pointer as a Sint32. |
| 668 | func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 669 | if wtyp != wire.VarintType { |
| 670 | return 0, errUnknown |
| 671 | } |
| 672 | v, n := wire.ConsumeVarint(b) |
| 673 | if n < 0 { |
| 674 | return 0, wire.ParseError(n) |
| 675 | } |
| 676 | *p.Int32() = int32(wire.DecodeZigZag(v & math.MaxUint32)) |
| 677 | return n, nil |
| 678 | } |
| 679 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 680 | var coderSint32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 681 | size: sizeSint32, |
| 682 | marshal: appendSint32, |
| 683 | unmarshal: consumeSint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 686 | // sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 687 | // The zero value is not encoded. |
| 688 | func sizeSint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 689 | v := *p.Int32() |
| 690 | if v == 0 { |
| 691 | return 0 |
| 692 | } |
| 693 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 694 | } |
| 695 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 696 | // appendSint32NoZero wire encodes a int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 697 | // The zero value is not encoded. |
| 698 | func appendSint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 699 | v := *p.Int32() |
| 700 | if v == 0 { |
| 701 | return b, nil |
| 702 | } |
| 703 | b = wire.AppendVarint(b, wiretag) |
| 704 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 705 | return b, nil |
| 706 | } |
| 707 | |
| 708 | var coderSint32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 709 | size: sizeSint32NoZero, |
| 710 | marshal: appendSint32NoZero, |
| 711 | unmarshal: consumeSint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | // sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32. |
| 715 | // It panics if the pointer is nil. |
| 716 | func sizeSint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 717 | v := **p.Int32Ptr() |
| 718 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 719 | } |
| 720 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 721 | // appendSint32Ptr wire encodes a *int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 722 | // It panics if the pointer is nil. |
| 723 | func appendSint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 724 | v := **p.Int32Ptr() |
| 725 | b = wire.AppendVarint(b, wiretag) |
| 726 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 727 | return b, nil |
| 728 | } |
| 729 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 730 | // consumeSint32Ptr wire decodes a *int32 pointer as a Sint32. |
| 731 | func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 732 | if wtyp != wire.VarintType { |
| 733 | return 0, errUnknown |
| 734 | } |
| 735 | v, n := wire.ConsumeVarint(b) |
| 736 | if n < 0 { |
| 737 | return 0, wire.ParseError(n) |
| 738 | } |
| 739 | vp := p.Int32Ptr() |
| 740 | if *vp == nil { |
| 741 | *vp = new(int32) |
| 742 | } |
| 743 | **vp = int32(wire.DecodeZigZag(v & math.MaxUint32)) |
| 744 | return n, nil |
| 745 | } |
| 746 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 747 | var coderSint32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 748 | size: sizeSint32Ptr, |
| 749 | marshal: appendSint32Ptr, |
| 750 | unmarshal: consumeSint32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | // sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32. |
| 754 | func sizeSint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 755 | s := *p.Int32Slice() |
| 756 | for _, v := range s { |
| 757 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 758 | } |
| 759 | return size |
| 760 | } |
| 761 | |
| 762 | // appendSint32Slice encodes a []int32 pointer as a repeated Sint32. |
| 763 | func appendSint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 764 | s := *p.Int32Slice() |
| 765 | for _, v := range s { |
| 766 | b = wire.AppendVarint(b, wiretag) |
| 767 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 768 | } |
| 769 | return b, nil |
| 770 | } |
| 771 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 772 | // consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32. |
| 773 | func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 774 | sp := p.Int32Slice() |
| 775 | if wtyp == wire.BytesType { |
| 776 | s := *sp |
| 777 | b, n = wire.ConsumeBytes(b) |
| 778 | if n < 0 { |
| 779 | return 0, wire.ParseError(n) |
| 780 | } |
| 781 | for len(b) > 0 { |
| 782 | v, n := wire.ConsumeVarint(b) |
| 783 | if n < 0 { |
| 784 | return 0, wire.ParseError(n) |
| 785 | } |
| 786 | s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 787 | b = b[n:] |
| 788 | } |
| 789 | *sp = s |
| 790 | return n, nil |
| 791 | } |
| 792 | if wtyp != wire.VarintType { |
| 793 | return 0, errUnknown |
| 794 | } |
| 795 | v, n := wire.ConsumeVarint(b) |
| 796 | if n < 0 { |
| 797 | return 0, wire.ParseError(n) |
| 798 | } |
| 799 | *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 800 | return n, nil |
| 801 | } |
| 802 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 803 | var coderSint32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 804 | size: sizeSint32Slice, |
| 805 | marshal: appendSint32Slice, |
| 806 | unmarshal: consumeSint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | // sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32. |
| 810 | func sizeSint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 811 | s := *p.Int32Slice() |
| 812 | if len(s) == 0 { |
| 813 | return 0 |
| 814 | } |
| 815 | n := 0 |
| 816 | for _, v := range s { |
| 817 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 818 | } |
| 819 | return tagsize + wire.SizeBytes(n) |
| 820 | } |
| 821 | |
| 822 | // appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32. |
| 823 | func appendSint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 824 | s := *p.Int32Slice() |
| 825 | if len(s) == 0 { |
| 826 | return b, nil |
| 827 | } |
| 828 | b = wire.AppendVarint(b, wiretag) |
| 829 | n := 0 |
| 830 | for _, v := range s { |
| 831 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 832 | } |
| 833 | b = wire.AppendVarint(b, uint64(n)) |
| 834 | for _, v := range s { |
| 835 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 836 | } |
| 837 | return b, nil |
| 838 | } |
| 839 | |
| 840 | var coderSint32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 841 | size: sizeSint32PackedSlice, |
| 842 | marshal: appendSint32PackedSlice, |
| 843 | unmarshal: consumeSint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | // sizeSint32Iface returns the size of wire encoding a int32 value as a Sint32. |
| 847 | func sizeSint32Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 848 | v := ival.(int32) |
| 849 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 850 | } |
| 851 | |
| 852 | // appendSint32Iface encodes a int32 value as a Sint32. |
| 853 | func appendSint32Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 854 | v := ival.(int32) |
| 855 | b = wire.AppendVarint(b, wiretag) |
| 856 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 857 | return b, nil |
| 858 | } |
| 859 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 860 | // consumeSint32Iface decodes a int32 value as a Sint32. |
| 861 | func consumeSint32Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 862 | if wtyp != wire.VarintType { |
| 863 | return nil, 0, errUnknown |
| 864 | } |
| 865 | v, n := wire.ConsumeVarint(b) |
| 866 | if n < 0 { |
| 867 | return nil, 0, wire.ParseError(n) |
| 868 | } |
| 869 | return int32(wire.DecodeZigZag(v & math.MaxUint32)), n, nil |
| 870 | } |
| 871 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 872 | var coderSint32Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 873 | size: sizeSint32Iface, |
| 874 | marshal: appendSint32Iface, |
| 875 | unmarshal: consumeSint32Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | // sizeSint32SliceIface returns the size of wire encoding a []int32 value as a repeated Sint32. |
| 879 | func sizeSint32SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 880 | s := *ival.(*[]int32) |
| 881 | for _, v := range s { |
| 882 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 883 | } |
| 884 | return size |
| 885 | } |
| 886 | |
| 887 | // appendSint32SliceIface encodes a []int32 value as a repeated Sint32. |
| 888 | func appendSint32SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 889 | s := *ival.(*[]int32) |
| 890 | for _, v := range s { |
| 891 | b = wire.AppendVarint(b, wiretag) |
| 892 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 893 | } |
| 894 | return b, nil |
| 895 | } |
| 896 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 897 | // consumeSint32SliceIface wire decodes a []int32 value as a repeated Sint32. |
| 898 | func consumeSint32SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 899 | sp := ival.(*[]int32) |
| 900 | if wtyp == wire.BytesType { |
| 901 | s := *sp |
| 902 | b, n = wire.ConsumeBytes(b) |
| 903 | if n < 0 { |
| 904 | return nil, 0, wire.ParseError(n) |
| 905 | } |
| 906 | for len(b) > 0 { |
| 907 | v, n := wire.ConsumeVarint(b) |
| 908 | if n < 0 { |
| 909 | return nil, 0, wire.ParseError(n) |
| 910 | } |
| 911 | s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 912 | b = b[n:] |
| 913 | } |
| 914 | *sp = s |
| 915 | return ival, n, nil |
| 916 | } |
| 917 | if wtyp != wire.VarintType { |
| 918 | return nil, 0, errUnknown |
| 919 | } |
| 920 | v, n := wire.ConsumeVarint(b) |
| 921 | if n < 0 { |
| 922 | return nil, 0, wire.ParseError(n) |
| 923 | } |
| 924 | *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 925 | return ival, n, nil |
| 926 | } |
| 927 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 928 | var coderSint32SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 929 | size: sizeSint32SliceIface, |
| 930 | marshal: appendSint32SliceIface, |
| 931 | unmarshal: consumeSint32SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 934 | // sizeSint32PackedSliceIface returns the size of wire encoding a []int32 value as a packed repeated Sint32. |
| 935 | func sizeSint32PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 936 | s := *ival.(*[]int32) |
| 937 | if len(s) == 0 { |
| 938 | return 0 |
| 939 | } |
| 940 | n := 0 |
| 941 | for _, v := range s { |
| 942 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 943 | } |
| 944 | return tagsize + wire.SizeBytes(n) |
| 945 | } |
| 946 | |
| 947 | // appendSint32PackedSliceIface encodes a []int32 value as a packed repeated Sint32. |
| 948 | func appendSint32PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 949 | s := *ival.(*[]int32) |
| 950 | if len(s) == 0 { |
| 951 | return b, nil |
| 952 | } |
| 953 | b = wire.AppendVarint(b, wiretag) |
| 954 | n := 0 |
| 955 | for _, v := range s { |
| 956 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 957 | } |
| 958 | b = wire.AppendVarint(b, uint64(n)) |
| 959 | for _, v := range s { |
| 960 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 961 | } |
| 962 | return b, nil |
| 963 | } |
| 964 | |
| 965 | var coderSint32PackedSliceIface = ifaceCoderFuncs{ |
| 966 | size: sizeSint32PackedSliceIface, |
| 967 | marshal: appendSint32PackedSliceIface, |
| 968 | unmarshal: consumeSint32SliceIface, |
| 969 | } |
| 970 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 971 | // sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32. |
| 972 | func sizeUint32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 973 | v := *p.Uint32() |
| 974 | return tagsize + wire.SizeVarint(uint64(v)) |
| 975 | } |
| 976 | |
| 977 | // appendUint32 wire encodes a uint32 pointer as a Uint32. |
| 978 | func appendUint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 979 | v := *p.Uint32() |
| 980 | b = wire.AppendVarint(b, wiretag) |
| 981 | b = wire.AppendVarint(b, uint64(v)) |
| 982 | return b, nil |
| 983 | } |
| 984 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 985 | // consumeUint32 wire decodes a uint32 pointer as a Uint32. |
| 986 | func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 987 | if wtyp != wire.VarintType { |
| 988 | return 0, errUnknown |
| 989 | } |
| 990 | v, n := wire.ConsumeVarint(b) |
| 991 | if n < 0 { |
| 992 | return 0, wire.ParseError(n) |
| 993 | } |
| 994 | *p.Uint32() = uint32(v) |
| 995 | return n, nil |
| 996 | } |
| 997 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 998 | var coderUint32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 999 | size: sizeUint32, |
| 1000 | marshal: appendUint32, |
| 1001 | unmarshal: consumeUint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1004 | // sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1005 | // The zero value is not encoded. |
| 1006 | func sizeUint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1007 | v := *p.Uint32() |
| 1008 | if v == 0 { |
| 1009 | return 0 |
| 1010 | } |
| 1011 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1012 | } |
| 1013 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1014 | // appendUint32NoZero wire encodes a uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1015 | // The zero value is not encoded. |
| 1016 | func appendUint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1017 | v := *p.Uint32() |
| 1018 | if v == 0 { |
| 1019 | return b, nil |
| 1020 | } |
| 1021 | b = wire.AppendVarint(b, wiretag) |
| 1022 | b = wire.AppendVarint(b, uint64(v)) |
| 1023 | return b, nil |
| 1024 | } |
| 1025 | |
| 1026 | var coderUint32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1027 | size: sizeUint32NoZero, |
| 1028 | marshal: appendUint32NoZero, |
| 1029 | unmarshal: consumeUint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | // sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32. |
| 1033 | // It panics if the pointer is nil. |
| 1034 | func sizeUint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1035 | v := **p.Uint32Ptr() |
| 1036 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1037 | } |
| 1038 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1039 | // appendUint32Ptr wire encodes a *uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1040 | // It panics if the pointer is nil. |
| 1041 | func appendUint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1042 | v := **p.Uint32Ptr() |
| 1043 | b = wire.AppendVarint(b, wiretag) |
| 1044 | b = wire.AppendVarint(b, uint64(v)) |
| 1045 | return b, nil |
| 1046 | } |
| 1047 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1048 | // consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32. |
| 1049 | func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1050 | if wtyp != wire.VarintType { |
| 1051 | return 0, errUnknown |
| 1052 | } |
| 1053 | v, n := wire.ConsumeVarint(b) |
| 1054 | if n < 0 { |
| 1055 | return 0, wire.ParseError(n) |
| 1056 | } |
| 1057 | vp := p.Uint32Ptr() |
| 1058 | if *vp == nil { |
| 1059 | *vp = new(uint32) |
| 1060 | } |
| 1061 | **vp = uint32(v) |
| 1062 | return n, nil |
| 1063 | } |
| 1064 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1065 | var coderUint32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1066 | size: sizeUint32Ptr, |
| 1067 | marshal: appendUint32Ptr, |
| 1068 | unmarshal: consumeUint32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | // sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32. |
| 1072 | func sizeUint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1073 | s := *p.Uint32Slice() |
| 1074 | for _, v := range s { |
| 1075 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1076 | } |
| 1077 | return size |
| 1078 | } |
| 1079 | |
| 1080 | // appendUint32Slice encodes a []uint32 pointer as a repeated Uint32. |
| 1081 | func appendUint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1082 | s := *p.Uint32Slice() |
| 1083 | for _, v := range s { |
| 1084 | b = wire.AppendVarint(b, wiretag) |
| 1085 | b = wire.AppendVarint(b, uint64(v)) |
| 1086 | } |
| 1087 | return b, nil |
| 1088 | } |
| 1089 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1090 | // consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32. |
| 1091 | func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1092 | sp := p.Uint32Slice() |
| 1093 | if wtyp == wire.BytesType { |
| 1094 | s := *sp |
| 1095 | b, n = wire.ConsumeBytes(b) |
| 1096 | if n < 0 { |
| 1097 | return 0, wire.ParseError(n) |
| 1098 | } |
| 1099 | for len(b) > 0 { |
| 1100 | v, n := wire.ConsumeVarint(b) |
| 1101 | if n < 0 { |
| 1102 | return 0, wire.ParseError(n) |
| 1103 | } |
| 1104 | s = append(s, uint32(v)) |
| 1105 | b = b[n:] |
| 1106 | } |
| 1107 | *sp = s |
| 1108 | return n, nil |
| 1109 | } |
| 1110 | if wtyp != wire.VarintType { |
| 1111 | return 0, errUnknown |
| 1112 | } |
| 1113 | v, n := wire.ConsumeVarint(b) |
| 1114 | if n < 0 { |
| 1115 | return 0, wire.ParseError(n) |
| 1116 | } |
| 1117 | *sp = append(*sp, uint32(v)) |
| 1118 | return n, nil |
| 1119 | } |
| 1120 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1121 | var coderUint32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1122 | size: sizeUint32Slice, |
| 1123 | marshal: appendUint32Slice, |
| 1124 | unmarshal: consumeUint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | // sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32. |
| 1128 | func sizeUint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1129 | s := *p.Uint32Slice() |
| 1130 | if len(s) == 0 { |
| 1131 | return 0 |
| 1132 | } |
| 1133 | n := 0 |
| 1134 | for _, v := range s { |
| 1135 | n += wire.SizeVarint(uint64(v)) |
| 1136 | } |
| 1137 | return tagsize + wire.SizeBytes(n) |
| 1138 | } |
| 1139 | |
| 1140 | // appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32. |
| 1141 | func appendUint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1142 | s := *p.Uint32Slice() |
| 1143 | if len(s) == 0 { |
| 1144 | return b, nil |
| 1145 | } |
| 1146 | b = wire.AppendVarint(b, wiretag) |
| 1147 | n := 0 |
| 1148 | for _, v := range s { |
| 1149 | n += wire.SizeVarint(uint64(v)) |
| 1150 | } |
| 1151 | b = wire.AppendVarint(b, uint64(n)) |
| 1152 | for _, v := range s { |
| 1153 | b = wire.AppendVarint(b, uint64(v)) |
| 1154 | } |
| 1155 | return b, nil |
| 1156 | } |
| 1157 | |
| 1158 | var coderUint32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1159 | size: sizeUint32PackedSlice, |
| 1160 | marshal: appendUint32PackedSlice, |
| 1161 | unmarshal: consumeUint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | // sizeUint32Iface returns the size of wire encoding a uint32 value as a Uint32. |
| 1165 | func sizeUint32Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 1166 | v := ival.(uint32) |
| 1167 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1168 | } |
| 1169 | |
| 1170 | // appendUint32Iface encodes a uint32 value as a Uint32. |
| 1171 | func appendUint32Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1172 | v := ival.(uint32) |
| 1173 | b = wire.AppendVarint(b, wiretag) |
| 1174 | b = wire.AppendVarint(b, uint64(v)) |
| 1175 | return b, nil |
| 1176 | } |
| 1177 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1178 | // consumeUint32Iface decodes a uint32 value as a Uint32. |
| 1179 | func consumeUint32Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 1180 | if wtyp != wire.VarintType { |
| 1181 | return nil, 0, errUnknown |
| 1182 | } |
| 1183 | v, n := wire.ConsumeVarint(b) |
| 1184 | if n < 0 { |
| 1185 | return nil, 0, wire.ParseError(n) |
| 1186 | } |
| 1187 | return uint32(v), n, nil |
| 1188 | } |
| 1189 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1190 | var coderUint32Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1191 | size: sizeUint32Iface, |
| 1192 | marshal: appendUint32Iface, |
| 1193 | unmarshal: consumeUint32Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | // sizeUint32SliceIface returns the size of wire encoding a []uint32 value as a repeated Uint32. |
| 1197 | func sizeUint32SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1198 | s := *ival.(*[]uint32) |
| 1199 | for _, v := range s { |
| 1200 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1201 | } |
| 1202 | return size |
| 1203 | } |
| 1204 | |
| 1205 | // appendUint32SliceIface encodes a []uint32 value as a repeated Uint32. |
| 1206 | func appendUint32SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1207 | s := *ival.(*[]uint32) |
| 1208 | for _, v := range s { |
| 1209 | b = wire.AppendVarint(b, wiretag) |
| 1210 | b = wire.AppendVarint(b, uint64(v)) |
| 1211 | } |
| 1212 | return b, nil |
| 1213 | } |
| 1214 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1215 | // consumeUint32SliceIface wire decodes a []uint32 value as a repeated Uint32. |
| 1216 | func consumeUint32SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 1217 | sp := ival.(*[]uint32) |
| 1218 | if wtyp == wire.BytesType { |
| 1219 | s := *sp |
| 1220 | b, n = wire.ConsumeBytes(b) |
| 1221 | if n < 0 { |
| 1222 | return nil, 0, wire.ParseError(n) |
| 1223 | } |
| 1224 | for len(b) > 0 { |
| 1225 | v, n := wire.ConsumeVarint(b) |
| 1226 | if n < 0 { |
| 1227 | return nil, 0, wire.ParseError(n) |
| 1228 | } |
| 1229 | s = append(s, uint32(v)) |
| 1230 | b = b[n:] |
| 1231 | } |
| 1232 | *sp = s |
| 1233 | return ival, n, nil |
| 1234 | } |
| 1235 | if wtyp != wire.VarintType { |
| 1236 | return nil, 0, errUnknown |
| 1237 | } |
| 1238 | v, n := wire.ConsumeVarint(b) |
| 1239 | if n < 0 { |
| 1240 | return nil, 0, wire.ParseError(n) |
| 1241 | } |
| 1242 | *sp = append(*sp, uint32(v)) |
| 1243 | return ival, n, nil |
| 1244 | } |
| 1245 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1246 | var coderUint32SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1247 | size: sizeUint32SliceIface, |
| 1248 | marshal: appendUint32SliceIface, |
| 1249 | unmarshal: consumeUint32SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1252 | // sizeUint32PackedSliceIface returns the size of wire encoding a []uint32 value as a packed repeated Uint32. |
| 1253 | func sizeUint32PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1254 | s := *ival.(*[]uint32) |
| 1255 | if len(s) == 0 { |
| 1256 | return 0 |
| 1257 | } |
| 1258 | n := 0 |
| 1259 | for _, v := range s { |
| 1260 | n += wire.SizeVarint(uint64(v)) |
| 1261 | } |
| 1262 | return tagsize + wire.SizeBytes(n) |
| 1263 | } |
| 1264 | |
| 1265 | // appendUint32PackedSliceIface encodes a []uint32 value as a packed repeated Uint32. |
| 1266 | func appendUint32PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1267 | s := *ival.(*[]uint32) |
| 1268 | if len(s) == 0 { |
| 1269 | return b, nil |
| 1270 | } |
| 1271 | b = wire.AppendVarint(b, wiretag) |
| 1272 | n := 0 |
| 1273 | for _, v := range s { |
| 1274 | n += wire.SizeVarint(uint64(v)) |
| 1275 | } |
| 1276 | b = wire.AppendVarint(b, uint64(n)) |
| 1277 | for _, v := range s { |
| 1278 | b = wire.AppendVarint(b, uint64(v)) |
| 1279 | } |
| 1280 | return b, nil |
| 1281 | } |
| 1282 | |
| 1283 | var coderUint32PackedSliceIface = ifaceCoderFuncs{ |
| 1284 | size: sizeUint32PackedSliceIface, |
| 1285 | marshal: appendUint32PackedSliceIface, |
| 1286 | unmarshal: consumeUint32SliceIface, |
| 1287 | } |
| 1288 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1289 | // sizeInt64 returns the size of wire encoding a int64 pointer as a Int64. |
| 1290 | func sizeInt64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1291 | v := *p.Int64() |
| 1292 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1293 | } |
| 1294 | |
| 1295 | // appendInt64 wire encodes a int64 pointer as a Int64. |
| 1296 | func appendInt64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1297 | v := *p.Int64() |
| 1298 | b = wire.AppendVarint(b, wiretag) |
| 1299 | b = wire.AppendVarint(b, uint64(v)) |
| 1300 | return b, nil |
| 1301 | } |
| 1302 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1303 | // consumeInt64 wire decodes a int64 pointer as a Int64. |
| 1304 | func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1305 | if wtyp != wire.VarintType { |
| 1306 | return 0, errUnknown |
| 1307 | } |
| 1308 | v, n := wire.ConsumeVarint(b) |
| 1309 | if n < 0 { |
| 1310 | return 0, wire.ParseError(n) |
| 1311 | } |
| 1312 | *p.Int64() = int64(v) |
| 1313 | return n, nil |
| 1314 | } |
| 1315 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1316 | var coderInt64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1317 | size: sizeInt64, |
| 1318 | marshal: appendInt64, |
| 1319 | unmarshal: consumeInt64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1322 | // sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1323 | // The zero value is not encoded. |
| 1324 | func sizeInt64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1325 | v := *p.Int64() |
| 1326 | if v == 0 { |
| 1327 | return 0 |
| 1328 | } |
| 1329 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1330 | } |
| 1331 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1332 | // appendInt64NoZero wire encodes a int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1333 | // The zero value is not encoded. |
| 1334 | func appendInt64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1335 | v := *p.Int64() |
| 1336 | if v == 0 { |
| 1337 | return b, nil |
| 1338 | } |
| 1339 | b = wire.AppendVarint(b, wiretag) |
| 1340 | b = wire.AppendVarint(b, uint64(v)) |
| 1341 | return b, nil |
| 1342 | } |
| 1343 | |
| 1344 | var coderInt64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1345 | size: sizeInt64NoZero, |
| 1346 | marshal: appendInt64NoZero, |
| 1347 | unmarshal: consumeInt64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | // sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64. |
| 1351 | // It panics if the pointer is nil. |
| 1352 | func sizeInt64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1353 | v := **p.Int64Ptr() |
| 1354 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1355 | } |
| 1356 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1357 | // appendInt64Ptr wire encodes a *int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1358 | // It panics if the pointer is nil. |
| 1359 | func appendInt64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1360 | v := **p.Int64Ptr() |
| 1361 | b = wire.AppendVarint(b, wiretag) |
| 1362 | b = wire.AppendVarint(b, uint64(v)) |
| 1363 | return b, nil |
| 1364 | } |
| 1365 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1366 | // consumeInt64Ptr wire decodes a *int64 pointer as a Int64. |
| 1367 | func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1368 | if wtyp != wire.VarintType { |
| 1369 | return 0, errUnknown |
| 1370 | } |
| 1371 | v, n := wire.ConsumeVarint(b) |
| 1372 | if n < 0 { |
| 1373 | return 0, wire.ParseError(n) |
| 1374 | } |
| 1375 | vp := p.Int64Ptr() |
| 1376 | if *vp == nil { |
| 1377 | *vp = new(int64) |
| 1378 | } |
| 1379 | **vp = int64(v) |
| 1380 | return n, nil |
| 1381 | } |
| 1382 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1383 | var coderInt64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1384 | size: sizeInt64Ptr, |
| 1385 | marshal: appendInt64Ptr, |
| 1386 | unmarshal: consumeInt64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | // sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64. |
| 1390 | func sizeInt64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1391 | s := *p.Int64Slice() |
| 1392 | for _, v := range s { |
| 1393 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1394 | } |
| 1395 | return size |
| 1396 | } |
| 1397 | |
| 1398 | // appendInt64Slice encodes a []int64 pointer as a repeated Int64. |
| 1399 | func appendInt64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1400 | s := *p.Int64Slice() |
| 1401 | for _, v := range s { |
| 1402 | b = wire.AppendVarint(b, wiretag) |
| 1403 | b = wire.AppendVarint(b, uint64(v)) |
| 1404 | } |
| 1405 | return b, nil |
| 1406 | } |
| 1407 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1408 | // consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64. |
| 1409 | func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1410 | sp := p.Int64Slice() |
| 1411 | if wtyp == wire.BytesType { |
| 1412 | s := *sp |
| 1413 | b, n = wire.ConsumeBytes(b) |
| 1414 | if n < 0 { |
| 1415 | return 0, wire.ParseError(n) |
| 1416 | } |
| 1417 | for len(b) > 0 { |
| 1418 | v, n := wire.ConsumeVarint(b) |
| 1419 | if n < 0 { |
| 1420 | return 0, wire.ParseError(n) |
| 1421 | } |
| 1422 | s = append(s, int64(v)) |
| 1423 | b = b[n:] |
| 1424 | } |
| 1425 | *sp = s |
| 1426 | return n, nil |
| 1427 | } |
| 1428 | if wtyp != wire.VarintType { |
| 1429 | return 0, errUnknown |
| 1430 | } |
| 1431 | v, n := wire.ConsumeVarint(b) |
| 1432 | if n < 0 { |
| 1433 | return 0, wire.ParseError(n) |
| 1434 | } |
| 1435 | *sp = append(*sp, int64(v)) |
| 1436 | return n, nil |
| 1437 | } |
| 1438 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1439 | var coderInt64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1440 | size: sizeInt64Slice, |
| 1441 | marshal: appendInt64Slice, |
| 1442 | unmarshal: consumeInt64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | // sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64. |
| 1446 | func sizeInt64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1447 | s := *p.Int64Slice() |
| 1448 | if len(s) == 0 { |
| 1449 | return 0 |
| 1450 | } |
| 1451 | n := 0 |
| 1452 | for _, v := range s { |
| 1453 | n += wire.SizeVarint(uint64(v)) |
| 1454 | } |
| 1455 | return tagsize + wire.SizeBytes(n) |
| 1456 | } |
| 1457 | |
| 1458 | // appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64. |
| 1459 | func appendInt64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1460 | s := *p.Int64Slice() |
| 1461 | if len(s) == 0 { |
| 1462 | return b, nil |
| 1463 | } |
| 1464 | b = wire.AppendVarint(b, wiretag) |
| 1465 | n := 0 |
| 1466 | for _, v := range s { |
| 1467 | n += wire.SizeVarint(uint64(v)) |
| 1468 | } |
| 1469 | b = wire.AppendVarint(b, uint64(n)) |
| 1470 | for _, v := range s { |
| 1471 | b = wire.AppendVarint(b, uint64(v)) |
| 1472 | } |
| 1473 | return b, nil |
| 1474 | } |
| 1475 | |
| 1476 | var coderInt64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1477 | size: sizeInt64PackedSlice, |
| 1478 | marshal: appendInt64PackedSlice, |
| 1479 | unmarshal: consumeInt64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | // sizeInt64Iface returns the size of wire encoding a int64 value as a Int64. |
| 1483 | func sizeInt64Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 1484 | v := ival.(int64) |
| 1485 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1486 | } |
| 1487 | |
| 1488 | // appendInt64Iface encodes a int64 value as a Int64. |
| 1489 | func appendInt64Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1490 | v := ival.(int64) |
| 1491 | b = wire.AppendVarint(b, wiretag) |
| 1492 | b = wire.AppendVarint(b, uint64(v)) |
| 1493 | return b, nil |
| 1494 | } |
| 1495 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1496 | // consumeInt64Iface decodes a int64 value as a Int64. |
| 1497 | func consumeInt64Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 1498 | if wtyp != wire.VarintType { |
| 1499 | return nil, 0, errUnknown |
| 1500 | } |
| 1501 | v, n := wire.ConsumeVarint(b) |
| 1502 | if n < 0 { |
| 1503 | return nil, 0, wire.ParseError(n) |
| 1504 | } |
| 1505 | return int64(v), n, nil |
| 1506 | } |
| 1507 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1508 | var coderInt64Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1509 | size: sizeInt64Iface, |
| 1510 | marshal: appendInt64Iface, |
| 1511 | unmarshal: consumeInt64Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | // sizeInt64SliceIface returns the size of wire encoding a []int64 value as a repeated Int64. |
| 1515 | func sizeInt64SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1516 | s := *ival.(*[]int64) |
| 1517 | for _, v := range s { |
| 1518 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1519 | } |
| 1520 | return size |
| 1521 | } |
| 1522 | |
| 1523 | // appendInt64SliceIface encodes a []int64 value as a repeated Int64. |
| 1524 | func appendInt64SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1525 | s := *ival.(*[]int64) |
| 1526 | for _, v := range s { |
| 1527 | b = wire.AppendVarint(b, wiretag) |
| 1528 | b = wire.AppendVarint(b, uint64(v)) |
| 1529 | } |
| 1530 | return b, nil |
| 1531 | } |
| 1532 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1533 | // consumeInt64SliceIface wire decodes a []int64 value as a repeated Int64. |
| 1534 | func consumeInt64SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 1535 | sp := ival.(*[]int64) |
| 1536 | if wtyp == wire.BytesType { |
| 1537 | s := *sp |
| 1538 | b, n = wire.ConsumeBytes(b) |
| 1539 | if n < 0 { |
| 1540 | return nil, 0, wire.ParseError(n) |
| 1541 | } |
| 1542 | for len(b) > 0 { |
| 1543 | v, n := wire.ConsumeVarint(b) |
| 1544 | if n < 0 { |
| 1545 | return nil, 0, wire.ParseError(n) |
| 1546 | } |
| 1547 | s = append(s, int64(v)) |
| 1548 | b = b[n:] |
| 1549 | } |
| 1550 | *sp = s |
| 1551 | return ival, n, nil |
| 1552 | } |
| 1553 | if wtyp != wire.VarintType { |
| 1554 | return nil, 0, errUnknown |
| 1555 | } |
| 1556 | v, n := wire.ConsumeVarint(b) |
| 1557 | if n < 0 { |
| 1558 | return nil, 0, wire.ParseError(n) |
| 1559 | } |
| 1560 | *sp = append(*sp, int64(v)) |
| 1561 | return ival, n, nil |
| 1562 | } |
| 1563 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1564 | var coderInt64SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1565 | size: sizeInt64SliceIface, |
| 1566 | marshal: appendInt64SliceIface, |
| 1567 | unmarshal: consumeInt64SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1570 | // sizeInt64PackedSliceIface returns the size of wire encoding a []int64 value as a packed repeated Int64. |
| 1571 | func sizeInt64PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1572 | s := *ival.(*[]int64) |
| 1573 | if len(s) == 0 { |
| 1574 | return 0 |
| 1575 | } |
| 1576 | n := 0 |
| 1577 | for _, v := range s { |
| 1578 | n += wire.SizeVarint(uint64(v)) |
| 1579 | } |
| 1580 | return tagsize + wire.SizeBytes(n) |
| 1581 | } |
| 1582 | |
| 1583 | // appendInt64PackedSliceIface encodes a []int64 value as a packed repeated Int64. |
| 1584 | func appendInt64PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1585 | s := *ival.(*[]int64) |
| 1586 | if len(s) == 0 { |
| 1587 | return b, nil |
| 1588 | } |
| 1589 | b = wire.AppendVarint(b, wiretag) |
| 1590 | n := 0 |
| 1591 | for _, v := range s { |
| 1592 | n += wire.SizeVarint(uint64(v)) |
| 1593 | } |
| 1594 | b = wire.AppendVarint(b, uint64(n)) |
| 1595 | for _, v := range s { |
| 1596 | b = wire.AppendVarint(b, uint64(v)) |
| 1597 | } |
| 1598 | return b, nil |
| 1599 | } |
| 1600 | |
| 1601 | var coderInt64PackedSliceIface = ifaceCoderFuncs{ |
| 1602 | size: sizeInt64PackedSliceIface, |
| 1603 | marshal: appendInt64PackedSliceIface, |
| 1604 | unmarshal: consumeInt64SliceIface, |
| 1605 | } |
| 1606 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1607 | // sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64. |
| 1608 | func sizeSint64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1609 | v := *p.Int64() |
| 1610 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1611 | } |
| 1612 | |
| 1613 | // appendSint64 wire encodes a int64 pointer as a Sint64. |
| 1614 | func appendSint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1615 | v := *p.Int64() |
| 1616 | b = wire.AppendVarint(b, wiretag) |
| 1617 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1618 | return b, nil |
| 1619 | } |
| 1620 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1621 | // consumeSint64 wire decodes a int64 pointer as a Sint64. |
| 1622 | func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1623 | if wtyp != wire.VarintType { |
| 1624 | return 0, errUnknown |
| 1625 | } |
| 1626 | v, n := wire.ConsumeVarint(b) |
| 1627 | if n < 0 { |
| 1628 | return 0, wire.ParseError(n) |
| 1629 | } |
| 1630 | *p.Int64() = wire.DecodeZigZag(v) |
| 1631 | return n, nil |
| 1632 | } |
| 1633 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1634 | var coderSint64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1635 | size: sizeSint64, |
| 1636 | marshal: appendSint64, |
| 1637 | unmarshal: consumeSint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1640 | // sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1641 | // The zero value is not encoded. |
| 1642 | func sizeSint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1643 | v := *p.Int64() |
| 1644 | if v == 0 { |
| 1645 | return 0 |
| 1646 | } |
| 1647 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1648 | } |
| 1649 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1650 | // appendSint64NoZero wire encodes a int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1651 | // The zero value is not encoded. |
| 1652 | func appendSint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1653 | v := *p.Int64() |
| 1654 | if v == 0 { |
| 1655 | return b, nil |
| 1656 | } |
| 1657 | b = wire.AppendVarint(b, wiretag) |
| 1658 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1659 | return b, nil |
| 1660 | } |
| 1661 | |
| 1662 | var coderSint64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1663 | size: sizeSint64NoZero, |
| 1664 | marshal: appendSint64NoZero, |
| 1665 | unmarshal: consumeSint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | // sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64. |
| 1669 | // It panics if the pointer is nil. |
| 1670 | func sizeSint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1671 | v := **p.Int64Ptr() |
| 1672 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1673 | } |
| 1674 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1675 | // appendSint64Ptr wire encodes a *int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1676 | // It panics if the pointer is nil. |
| 1677 | func appendSint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1678 | v := **p.Int64Ptr() |
| 1679 | b = wire.AppendVarint(b, wiretag) |
| 1680 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1681 | return b, nil |
| 1682 | } |
| 1683 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1684 | // consumeSint64Ptr wire decodes a *int64 pointer as a Sint64. |
| 1685 | func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1686 | if wtyp != wire.VarintType { |
| 1687 | return 0, errUnknown |
| 1688 | } |
| 1689 | v, n := wire.ConsumeVarint(b) |
| 1690 | if n < 0 { |
| 1691 | return 0, wire.ParseError(n) |
| 1692 | } |
| 1693 | vp := p.Int64Ptr() |
| 1694 | if *vp == nil { |
| 1695 | *vp = new(int64) |
| 1696 | } |
| 1697 | **vp = wire.DecodeZigZag(v) |
| 1698 | return n, nil |
| 1699 | } |
| 1700 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1701 | var coderSint64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1702 | size: sizeSint64Ptr, |
| 1703 | marshal: appendSint64Ptr, |
| 1704 | unmarshal: consumeSint64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | // sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64. |
| 1708 | func sizeSint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1709 | s := *p.Int64Slice() |
| 1710 | for _, v := range s { |
| 1711 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1712 | } |
| 1713 | return size |
| 1714 | } |
| 1715 | |
| 1716 | // appendSint64Slice encodes a []int64 pointer as a repeated Sint64. |
| 1717 | func appendSint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1718 | s := *p.Int64Slice() |
| 1719 | for _, v := range s { |
| 1720 | b = wire.AppendVarint(b, wiretag) |
| 1721 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1722 | } |
| 1723 | return b, nil |
| 1724 | } |
| 1725 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1726 | // consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64. |
| 1727 | func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1728 | sp := p.Int64Slice() |
| 1729 | if wtyp == wire.BytesType { |
| 1730 | s := *sp |
| 1731 | b, n = wire.ConsumeBytes(b) |
| 1732 | if n < 0 { |
| 1733 | return 0, wire.ParseError(n) |
| 1734 | } |
| 1735 | for len(b) > 0 { |
| 1736 | v, n := wire.ConsumeVarint(b) |
| 1737 | if n < 0 { |
| 1738 | return 0, wire.ParseError(n) |
| 1739 | } |
| 1740 | s = append(s, wire.DecodeZigZag(v)) |
| 1741 | b = b[n:] |
| 1742 | } |
| 1743 | *sp = s |
| 1744 | return n, nil |
| 1745 | } |
| 1746 | if wtyp != wire.VarintType { |
| 1747 | return 0, errUnknown |
| 1748 | } |
| 1749 | v, n := wire.ConsumeVarint(b) |
| 1750 | if n < 0 { |
| 1751 | return 0, wire.ParseError(n) |
| 1752 | } |
| 1753 | *sp = append(*sp, wire.DecodeZigZag(v)) |
| 1754 | return n, nil |
| 1755 | } |
| 1756 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1757 | var coderSint64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1758 | size: sizeSint64Slice, |
| 1759 | marshal: appendSint64Slice, |
| 1760 | unmarshal: consumeSint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | // sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64. |
| 1764 | func sizeSint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1765 | s := *p.Int64Slice() |
| 1766 | if len(s) == 0 { |
| 1767 | return 0 |
| 1768 | } |
| 1769 | n := 0 |
| 1770 | for _, v := range s { |
| 1771 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1772 | } |
| 1773 | return tagsize + wire.SizeBytes(n) |
| 1774 | } |
| 1775 | |
| 1776 | // appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64. |
| 1777 | func appendSint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1778 | s := *p.Int64Slice() |
| 1779 | if len(s) == 0 { |
| 1780 | return b, nil |
| 1781 | } |
| 1782 | b = wire.AppendVarint(b, wiretag) |
| 1783 | n := 0 |
| 1784 | for _, v := range s { |
| 1785 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1786 | } |
| 1787 | b = wire.AppendVarint(b, uint64(n)) |
| 1788 | for _, v := range s { |
| 1789 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1790 | } |
| 1791 | return b, nil |
| 1792 | } |
| 1793 | |
| 1794 | var coderSint64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1795 | size: sizeSint64PackedSlice, |
| 1796 | marshal: appendSint64PackedSlice, |
| 1797 | unmarshal: consumeSint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // sizeSint64Iface returns the size of wire encoding a int64 value as a Sint64. |
| 1801 | func sizeSint64Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 1802 | v := ival.(int64) |
| 1803 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1804 | } |
| 1805 | |
| 1806 | // appendSint64Iface encodes a int64 value as a Sint64. |
| 1807 | func appendSint64Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1808 | v := ival.(int64) |
| 1809 | b = wire.AppendVarint(b, wiretag) |
| 1810 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1811 | return b, nil |
| 1812 | } |
| 1813 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1814 | // consumeSint64Iface decodes a int64 value as a Sint64. |
| 1815 | func consumeSint64Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 1816 | if wtyp != wire.VarintType { |
| 1817 | return nil, 0, errUnknown |
| 1818 | } |
| 1819 | v, n := wire.ConsumeVarint(b) |
| 1820 | if n < 0 { |
| 1821 | return nil, 0, wire.ParseError(n) |
| 1822 | } |
| 1823 | return wire.DecodeZigZag(v), n, nil |
| 1824 | } |
| 1825 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1826 | var coderSint64Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1827 | size: sizeSint64Iface, |
| 1828 | marshal: appendSint64Iface, |
| 1829 | unmarshal: consumeSint64Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | // sizeSint64SliceIface returns the size of wire encoding a []int64 value as a repeated Sint64. |
| 1833 | func sizeSint64SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1834 | s := *ival.(*[]int64) |
| 1835 | for _, v := range s { |
| 1836 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1837 | } |
| 1838 | return size |
| 1839 | } |
| 1840 | |
| 1841 | // appendSint64SliceIface encodes a []int64 value as a repeated Sint64. |
| 1842 | func appendSint64SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1843 | s := *ival.(*[]int64) |
| 1844 | for _, v := range s { |
| 1845 | b = wire.AppendVarint(b, wiretag) |
| 1846 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1847 | } |
| 1848 | return b, nil |
| 1849 | } |
| 1850 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1851 | // consumeSint64SliceIface wire decodes a []int64 value as a repeated Sint64. |
| 1852 | func consumeSint64SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 1853 | sp := ival.(*[]int64) |
| 1854 | if wtyp == wire.BytesType { |
| 1855 | s := *sp |
| 1856 | b, n = wire.ConsumeBytes(b) |
| 1857 | if n < 0 { |
| 1858 | return nil, 0, wire.ParseError(n) |
| 1859 | } |
| 1860 | for len(b) > 0 { |
| 1861 | v, n := wire.ConsumeVarint(b) |
| 1862 | if n < 0 { |
| 1863 | return nil, 0, wire.ParseError(n) |
| 1864 | } |
| 1865 | s = append(s, wire.DecodeZigZag(v)) |
| 1866 | b = b[n:] |
| 1867 | } |
| 1868 | *sp = s |
| 1869 | return ival, n, nil |
| 1870 | } |
| 1871 | if wtyp != wire.VarintType { |
| 1872 | return nil, 0, errUnknown |
| 1873 | } |
| 1874 | v, n := wire.ConsumeVarint(b) |
| 1875 | if n < 0 { |
| 1876 | return nil, 0, wire.ParseError(n) |
| 1877 | } |
| 1878 | *sp = append(*sp, wire.DecodeZigZag(v)) |
| 1879 | return ival, n, nil |
| 1880 | } |
| 1881 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1882 | var coderSint64SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1883 | size: sizeSint64SliceIface, |
| 1884 | marshal: appendSint64SliceIface, |
| 1885 | unmarshal: consumeSint64SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1888 | // sizeSint64PackedSliceIface returns the size of wire encoding a []int64 value as a packed repeated Sint64. |
| 1889 | func sizeSint64PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 1890 | s := *ival.(*[]int64) |
| 1891 | if len(s) == 0 { |
| 1892 | return 0 |
| 1893 | } |
| 1894 | n := 0 |
| 1895 | for _, v := range s { |
| 1896 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1897 | } |
| 1898 | return tagsize + wire.SizeBytes(n) |
| 1899 | } |
| 1900 | |
| 1901 | // appendSint64PackedSliceIface encodes a []int64 value as a packed repeated Sint64. |
| 1902 | func appendSint64PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1903 | s := *ival.(*[]int64) |
| 1904 | if len(s) == 0 { |
| 1905 | return b, nil |
| 1906 | } |
| 1907 | b = wire.AppendVarint(b, wiretag) |
| 1908 | n := 0 |
| 1909 | for _, v := range s { |
| 1910 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1911 | } |
| 1912 | b = wire.AppendVarint(b, uint64(n)) |
| 1913 | for _, v := range s { |
| 1914 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1915 | } |
| 1916 | return b, nil |
| 1917 | } |
| 1918 | |
| 1919 | var coderSint64PackedSliceIface = ifaceCoderFuncs{ |
| 1920 | size: sizeSint64PackedSliceIface, |
| 1921 | marshal: appendSint64PackedSliceIface, |
| 1922 | unmarshal: consumeSint64SliceIface, |
| 1923 | } |
| 1924 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1925 | // sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64. |
| 1926 | func sizeUint64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1927 | v := *p.Uint64() |
| 1928 | return tagsize + wire.SizeVarint(v) |
| 1929 | } |
| 1930 | |
| 1931 | // appendUint64 wire encodes a uint64 pointer as a Uint64. |
| 1932 | func appendUint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1933 | v := *p.Uint64() |
| 1934 | b = wire.AppendVarint(b, wiretag) |
| 1935 | b = wire.AppendVarint(b, v) |
| 1936 | return b, nil |
| 1937 | } |
| 1938 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1939 | // consumeUint64 wire decodes a uint64 pointer as a Uint64. |
| 1940 | func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1941 | if wtyp != wire.VarintType { |
| 1942 | return 0, errUnknown |
| 1943 | } |
| 1944 | v, n := wire.ConsumeVarint(b) |
| 1945 | if n < 0 { |
| 1946 | return 0, wire.ParseError(n) |
| 1947 | } |
| 1948 | *p.Uint64() = v |
| 1949 | return n, nil |
| 1950 | } |
| 1951 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1952 | var coderUint64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1953 | size: sizeUint64, |
| 1954 | marshal: appendUint64, |
| 1955 | unmarshal: consumeUint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1958 | // sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1959 | // The zero value is not encoded. |
| 1960 | func sizeUint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1961 | v := *p.Uint64() |
| 1962 | if v == 0 { |
| 1963 | return 0 |
| 1964 | } |
| 1965 | return tagsize + wire.SizeVarint(v) |
| 1966 | } |
| 1967 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 1968 | // appendUint64NoZero wire encodes a uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1969 | // The zero value is not encoded. |
| 1970 | func appendUint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1971 | v := *p.Uint64() |
| 1972 | if v == 0 { |
| 1973 | return b, nil |
| 1974 | } |
| 1975 | b = wire.AppendVarint(b, wiretag) |
| 1976 | b = wire.AppendVarint(b, v) |
| 1977 | return b, nil |
| 1978 | } |
| 1979 | |
| 1980 | var coderUint64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1981 | size: sizeUint64NoZero, |
| 1982 | marshal: appendUint64NoZero, |
| 1983 | unmarshal: consumeUint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | // sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64. |
| 1987 | // It panics if the pointer is nil. |
| 1988 | func sizeUint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1989 | v := **p.Uint64Ptr() |
| 1990 | return tagsize + wire.SizeVarint(v) |
| 1991 | } |
| 1992 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1993 | // appendUint64Ptr wire encodes a *uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1994 | // It panics if the pointer is nil. |
| 1995 | func appendUint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1996 | v := **p.Uint64Ptr() |
| 1997 | b = wire.AppendVarint(b, wiretag) |
| 1998 | b = wire.AppendVarint(b, v) |
| 1999 | return b, nil |
| 2000 | } |
| 2001 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2002 | // consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64. |
| 2003 | func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2004 | if wtyp != wire.VarintType { |
| 2005 | return 0, errUnknown |
| 2006 | } |
| 2007 | v, n := wire.ConsumeVarint(b) |
| 2008 | if n < 0 { |
| 2009 | return 0, wire.ParseError(n) |
| 2010 | } |
| 2011 | vp := p.Uint64Ptr() |
| 2012 | if *vp == nil { |
| 2013 | *vp = new(uint64) |
| 2014 | } |
| 2015 | **vp = v |
| 2016 | return n, nil |
| 2017 | } |
| 2018 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2019 | var coderUint64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2020 | size: sizeUint64Ptr, |
| 2021 | marshal: appendUint64Ptr, |
| 2022 | unmarshal: consumeUint64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | // sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64. |
| 2026 | func sizeUint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2027 | s := *p.Uint64Slice() |
| 2028 | for _, v := range s { |
| 2029 | size += tagsize + wire.SizeVarint(v) |
| 2030 | } |
| 2031 | return size |
| 2032 | } |
| 2033 | |
| 2034 | // appendUint64Slice encodes a []uint64 pointer as a repeated Uint64. |
| 2035 | func appendUint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2036 | s := *p.Uint64Slice() |
| 2037 | for _, v := range s { |
| 2038 | b = wire.AppendVarint(b, wiretag) |
| 2039 | b = wire.AppendVarint(b, v) |
| 2040 | } |
| 2041 | return b, nil |
| 2042 | } |
| 2043 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2044 | // consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64. |
| 2045 | func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2046 | sp := p.Uint64Slice() |
| 2047 | if wtyp == wire.BytesType { |
| 2048 | s := *sp |
| 2049 | b, n = wire.ConsumeBytes(b) |
| 2050 | if n < 0 { |
| 2051 | return 0, wire.ParseError(n) |
| 2052 | } |
| 2053 | for len(b) > 0 { |
| 2054 | v, n := wire.ConsumeVarint(b) |
| 2055 | if n < 0 { |
| 2056 | return 0, wire.ParseError(n) |
| 2057 | } |
| 2058 | s = append(s, v) |
| 2059 | b = b[n:] |
| 2060 | } |
| 2061 | *sp = s |
| 2062 | return n, nil |
| 2063 | } |
| 2064 | if wtyp != wire.VarintType { |
| 2065 | return 0, errUnknown |
| 2066 | } |
| 2067 | v, n := wire.ConsumeVarint(b) |
| 2068 | if n < 0 { |
| 2069 | return 0, wire.ParseError(n) |
| 2070 | } |
| 2071 | *sp = append(*sp, v) |
| 2072 | return n, nil |
| 2073 | } |
| 2074 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2075 | var coderUint64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2076 | size: sizeUint64Slice, |
| 2077 | marshal: appendUint64Slice, |
| 2078 | unmarshal: consumeUint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | // sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64. |
| 2082 | func sizeUint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2083 | s := *p.Uint64Slice() |
| 2084 | if len(s) == 0 { |
| 2085 | return 0 |
| 2086 | } |
| 2087 | n := 0 |
| 2088 | for _, v := range s { |
| 2089 | n += wire.SizeVarint(v) |
| 2090 | } |
| 2091 | return tagsize + wire.SizeBytes(n) |
| 2092 | } |
| 2093 | |
| 2094 | // appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64. |
| 2095 | func appendUint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2096 | s := *p.Uint64Slice() |
| 2097 | if len(s) == 0 { |
| 2098 | return b, nil |
| 2099 | } |
| 2100 | b = wire.AppendVarint(b, wiretag) |
| 2101 | n := 0 |
| 2102 | for _, v := range s { |
| 2103 | n += wire.SizeVarint(v) |
| 2104 | } |
| 2105 | b = wire.AppendVarint(b, uint64(n)) |
| 2106 | for _, v := range s { |
| 2107 | b = wire.AppendVarint(b, v) |
| 2108 | } |
| 2109 | return b, nil |
| 2110 | } |
| 2111 | |
| 2112 | var coderUint64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2113 | size: sizeUint64PackedSlice, |
| 2114 | marshal: appendUint64PackedSlice, |
| 2115 | unmarshal: consumeUint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | // sizeUint64Iface returns the size of wire encoding a uint64 value as a Uint64. |
| 2119 | func sizeUint64Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 2120 | v := ival.(uint64) |
| 2121 | return tagsize + wire.SizeVarint(v) |
| 2122 | } |
| 2123 | |
| 2124 | // appendUint64Iface encodes a uint64 value as a Uint64. |
| 2125 | func appendUint64Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2126 | v := ival.(uint64) |
| 2127 | b = wire.AppendVarint(b, wiretag) |
| 2128 | b = wire.AppendVarint(b, v) |
| 2129 | return b, nil |
| 2130 | } |
| 2131 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2132 | // consumeUint64Iface decodes a uint64 value as a Uint64. |
| 2133 | func consumeUint64Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 2134 | if wtyp != wire.VarintType { |
| 2135 | return nil, 0, errUnknown |
| 2136 | } |
| 2137 | v, n := wire.ConsumeVarint(b) |
| 2138 | if n < 0 { |
| 2139 | return nil, 0, wire.ParseError(n) |
| 2140 | } |
| 2141 | return v, n, nil |
| 2142 | } |
| 2143 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2144 | var coderUint64Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2145 | size: sizeUint64Iface, |
| 2146 | marshal: appendUint64Iface, |
| 2147 | unmarshal: consumeUint64Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | // sizeUint64SliceIface returns the size of wire encoding a []uint64 value as a repeated Uint64. |
| 2151 | func sizeUint64SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2152 | s := *ival.(*[]uint64) |
| 2153 | for _, v := range s { |
| 2154 | size += tagsize + wire.SizeVarint(v) |
| 2155 | } |
| 2156 | return size |
| 2157 | } |
| 2158 | |
| 2159 | // appendUint64SliceIface encodes a []uint64 value as a repeated Uint64. |
| 2160 | func appendUint64SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2161 | s := *ival.(*[]uint64) |
| 2162 | for _, v := range s { |
| 2163 | b = wire.AppendVarint(b, wiretag) |
| 2164 | b = wire.AppendVarint(b, v) |
| 2165 | } |
| 2166 | return b, nil |
| 2167 | } |
| 2168 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2169 | // consumeUint64SliceIface wire decodes a []uint64 value as a repeated Uint64. |
| 2170 | func consumeUint64SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 2171 | sp := ival.(*[]uint64) |
| 2172 | if wtyp == wire.BytesType { |
| 2173 | s := *sp |
| 2174 | b, n = wire.ConsumeBytes(b) |
| 2175 | if n < 0 { |
| 2176 | return nil, 0, wire.ParseError(n) |
| 2177 | } |
| 2178 | for len(b) > 0 { |
| 2179 | v, n := wire.ConsumeVarint(b) |
| 2180 | if n < 0 { |
| 2181 | return nil, 0, wire.ParseError(n) |
| 2182 | } |
| 2183 | s = append(s, v) |
| 2184 | b = b[n:] |
| 2185 | } |
| 2186 | *sp = s |
| 2187 | return ival, n, nil |
| 2188 | } |
| 2189 | if wtyp != wire.VarintType { |
| 2190 | return nil, 0, errUnknown |
| 2191 | } |
| 2192 | v, n := wire.ConsumeVarint(b) |
| 2193 | if n < 0 { |
| 2194 | return nil, 0, wire.ParseError(n) |
| 2195 | } |
| 2196 | *sp = append(*sp, v) |
| 2197 | return ival, n, nil |
| 2198 | } |
| 2199 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2200 | var coderUint64SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2201 | size: sizeUint64SliceIface, |
| 2202 | marshal: appendUint64SliceIface, |
| 2203 | unmarshal: consumeUint64SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2206 | // sizeUint64PackedSliceIface returns the size of wire encoding a []uint64 value as a packed repeated Uint64. |
| 2207 | func sizeUint64PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2208 | s := *ival.(*[]uint64) |
| 2209 | if len(s) == 0 { |
| 2210 | return 0 |
| 2211 | } |
| 2212 | n := 0 |
| 2213 | for _, v := range s { |
| 2214 | n += wire.SizeVarint(v) |
| 2215 | } |
| 2216 | return tagsize + wire.SizeBytes(n) |
| 2217 | } |
| 2218 | |
| 2219 | // appendUint64PackedSliceIface encodes a []uint64 value as a packed repeated Uint64. |
| 2220 | func appendUint64PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2221 | s := *ival.(*[]uint64) |
| 2222 | if len(s) == 0 { |
| 2223 | return b, nil |
| 2224 | } |
| 2225 | b = wire.AppendVarint(b, wiretag) |
| 2226 | n := 0 |
| 2227 | for _, v := range s { |
| 2228 | n += wire.SizeVarint(v) |
| 2229 | } |
| 2230 | b = wire.AppendVarint(b, uint64(n)) |
| 2231 | for _, v := range s { |
| 2232 | b = wire.AppendVarint(b, v) |
| 2233 | } |
| 2234 | return b, nil |
| 2235 | } |
| 2236 | |
| 2237 | var coderUint64PackedSliceIface = ifaceCoderFuncs{ |
| 2238 | size: sizeUint64PackedSliceIface, |
| 2239 | marshal: appendUint64PackedSliceIface, |
| 2240 | unmarshal: consumeUint64SliceIface, |
| 2241 | } |
| 2242 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2243 | // sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32. |
| 2244 | func sizeSfixed32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2245 | |
| 2246 | return tagsize + wire.SizeFixed32() |
| 2247 | } |
| 2248 | |
| 2249 | // appendSfixed32 wire encodes a int32 pointer as a Sfixed32. |
| 2250 | func appendSfixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2251 | v := *p.Int32() |
| 2252 | b = wire.AppendVarint(b, wiretag) |
| 2253 | b = wire.AppendFixed32(b, uint32(v)) |
| 2254 | return b, nil |
| 2255 | } |
| 2256 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2257 | // consumeSfixed32 wire decodes a int32 pointer as a Sfixed32. |
| 2258 | func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2259 | if wtyp != wire.Fixed32Type { |
| 2260 | return 0, errUnknown |
| 2261 | } |
| 2262 | v, n := wire.ConsumeFixed32(b) |
| 2263 | if n < 0 { |
| 2264 | return 0, wire.ParseError(n) |
| 2265 | } |
| 2266 | *p.Int32() = int32(v) |
| 2267 | return n, nil |
| 2268 | } |
| 2269 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2270 | var coderSfixed32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2271 | size: sizeSfixed32, |
| 2272 | marshal: appendSfixed32, |
| 2273 | unmarshal: consumeSfixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2276 | // sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2277 | // The zero value is not encoded. |
| 2278 | func sizeSfixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2279 | v := *p.Int32() |
| 2280 | if v == 0 { |
| 2281 | return 0 |
| 2282 | } |
| 2283 | return tagsize + wire.SizeFixed32() |
| 2284 | } |
| 2285 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2286 | // appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2287 | // The zero value is not encoded. |
| 2288 | func appendSfixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2289 | v := *p.Int32() |
| 2290 | if v == 0 { |
| 2291 | return b, nil |
| 2292 | } |
| 2293 | b = wire.AppendVarint(b, wiretag) |
| 2294 | b = wire.AppendFixed32(b, uint32(v)) |
| 2295 | return b, nil |
| 2296 | } |
| 2297 | |
| 2298 | var coderSfixed32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2299 | size: sizeSfixed32NoZero, |
| 2300 | marshal: appendSfixed32NoZero, |
| 2301 | unmarshal: consumeSfixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | // sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32. |
| 2305 | // It panics if the pointer is nil. |
| 2306 | func sizeSfixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2307 | return tagsize + wire.SizeFixed32() |
| 2308 | } |
| 2309 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2310 | // appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2311 | // It panics if the pointer is nil. |
| 2312 | func appendSfixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2313 | v := **p.Int32Ptr() |
| 2314 | b = wire.AppendVarint(b, wiretag) |
| 2315 | b = wire.AppendFixed32(b, uint32(v)) |
| 2316 | return b, nil |
| 2317 | } |
| 2318 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2319 | // consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32. |
| 2320 | func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2321 | if wtyp != wire.Fixed32Type { |
| 2322 | return 0, errUnknown |
| 2323 | } |
| 2324 | v, n := wire.ConsumeFixed32(b) |
| 2325 | if n < 0 { |
| 2326 | return 0, wire.ParseError(n) |
| 2327 | } |
| 2328 | vp := p.Int32Ptr() |
| 2329 | if *vp == nil { |
| 2330 | *vp = new(int32) |
| 2331 | } |
| 2332 | **vp = int32(v) |
| 2333 | return n, nil |
| 2334 | } |
| 2335 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2336 | var coderSfixed32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2337 | size: sizeSfixed32Ptr, |
| 2338 | marshal: appendSfixed32Ptr, |
| 2339 | unmarshal: consumeSfixed32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | // sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32. |
| 2343 | func sizeSfixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2344 | s := *p.Int32Slice() |
| 2345 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2346 | return size |
| 2347 | } |
| 2348 | |
| 2349 | // appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32. |
| 2350 | func appendSfixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2351 | s := *p.Int32Slice() |
| 2352 | for _, v := range s { |
| 2353 | b = wire.AppendVarint(b, wiretag) |
| 2354 | b = wire.AppendFixed32(b, uint32(v)) |
| 2355 | } |
| 2356 | return b, nil |
| 2357 | } |
| 2358 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2359 | // consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32. |
| 2360 | func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2361 | sp := p.Int32Slice() |
| 2362 | if wtyp == wire.BytesType { |
| 2363 | s := *sp |
| 2364 | b, n = wire.ConsumeBytes(b) |
| 2365 | if n < 0 { |
| 2366 | return 0, wire.ParseError(n) |
| 2367 | } |
| 2368 | for len(b) > 0 { |
| 2369 | v, n := wire.ConsumeFixed32(b) |
| 2370 | if n < 0 { |
| 2371 | return 0, wire.ParseError(n) |
| 2372 | } |
| 2373 | s = append(s, int32(v)) |
| 2374 | b = b[n:] |
| 2375 | } |
| 2376 | *sp = s |
| 2377 | return n, nil |
| 2378 | } |
| 2379 | if wtyp != wire.Fixed32Type { |
| 2380 | return 0, errUnknown |
| 2381 | } |
| 2382 | v, n := wire.ConsumeFixed32(b) |
| 2383 | if n < 0 { |
| 2384 | return 0, wire.ParseError(n) |
| 2385 | } |
| 2386 | *sp = append(*sp, int32(v)) |
| 2387 | return n, nil |
| 2388 | } |
| 2389 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2390 | var coderSfixed32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2391 | size: sizeSfixed32Slice, |
| 2392 | marshal: appendSfixed32Slice, |
| 2393 | unmarshal: consumeSfixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | // sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32. |
| 2397 | func sizeSfixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2398 | s := *p.Int32Slice() |
| 2399 | if len(s) == 0 { |
| 2400 | return 0 |
| 2401 | } |
| 2402 | n := len(s) * wire.SizeFixed32() |
| 2403 | return tagsize + wire.SizeBytes(n) |
| 2404 | } |
| 2405 | |
| 2406 | // appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32. |
| 2407 | func appendSfixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2408 | s := *p.Int32Slice() |
| 2409 | if len(s) == 0 { |
| 2410 | return b, nil |
| 2411 | } |
| 2412 | b = wire.AppendVarint(b, wiretag) |
| 2413 | n := len(s) * wire.SizeFixed32() |
| 2414 | b = wire.AppendVarint(b, uint64(n)) |
| 2415 | for _, v := range s { |
| 2416 | b = wire.AppendFixed32(b, uint32(v)) |
| 2417 | } |
| 2418 | return b, nil |
| 2419 | } |
| 2420 | |
| 2421 | var coderSfixed32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2422 | size: sizeSfixed32PackedSlice, |
| 2423 | marshal: appendSfixed32PackedSlice, |
| 2424 | unmarshal: consumeSfixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | // sizeSfixed32Iface returns the size of wire encoding a int32 value as a Sfixed32. |
| 2428 | func sizeSfixed32Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 2429 | return tagsize + wire.SizeFixed32() |
| 2430 | } |
| 2431 | |
| 2432 | // appendSfixed32Iface encodes a int32 value as a Sfixed32. |
| 2433 | func appendSfixed32Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2434 | v := ival.(int32) |
| 2435 | b = wire.AppendVarint(b, wiretag) |
| 2436 | b = wire.AppendFixed32(b, uint32(v)) |
| 2437 | return b, nil |
| 2438 | } |
| 2439 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2440 | // consumeSfixed32Iface decodes a int32 value as a Sfixed32. |
| 2441 | func consumeSfixed32Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 2442 | if wtyp != wire.Fixed32Type { |
| 2443 | return nil, 0, errUnknown |
| 2444 | } |
| 2445 | v, n := wire.ConsumeFixed32(b) |
| 2446 | if n < 0 { |
| 2447 | return nil, 0, wire.ParseError(n) |
| 2448 | } |
| 2449 | return int32(v), n, nil |
| 2450 | } |
| 2451 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2452 | var coderSfixed32Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2453 | size: sizeSfixed32Iface, |
| 2454 | marshal: appendSfixed32Iface, |
| 2455 | unmarshal: consumeSfixed32Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | // sizeSfixed32SliceIface returns the size of wire encoding a []int32 value as a repeated Sfixed32. |
| 2459 | func sizeSfixed32SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2460 | s := *ival.(*[]int32) |
| 2461 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2462 | return size |
| 2463 | } |
| 2464 | |
| 2465 | // appendSfixed32SliceIface encodes a []int32 value as a repeated Sfixed32. |
| 2466 | func appendSfixed32SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2467 | s := *ival.(*[]int32) |
| 2468 | for _, v := range s { |
| 2469 | b = wire.AppendVarint(b, wiretag) |
| 2470 | b = wire.AppendFixed32(b, uint32(v)) |
| 2471 | } |
| 2472 | return b, nil |
| 2473 | } |
| 2474 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2475 | // consumeSfixed32SliceIface wire decodes a []int32 value as a repeated Sfixed32. |
| 2476 | func consumeSfixed32SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 2477 | sp := ival.(*[]int32) |
| 2478 | if wtyp == wire.BytesType { |
| 2479 | s := *sp |
| 2480 | b, n = wire.ConsumeBytes(b) |
| 2481 | if n < 0 { |
| 2482 | return nil, 0, wire.ParseError(n) |
| 2483 | } |
| 2484 | for len(b) > 0 { |
| 2485 | v, n := wire.ConsumeFixed32(b) |
| 2486 | if n < 0 { |
| 2487 | return nil, 0, wire.ParseError(n) |
| 2488 | } |
| 2489 | s = append(s, int32(v)) |
| 2490 | b = b[n:] |
| 2491 | } |
| 2492 | *sp = s |
| 2493 | return ival, n, nil |
| 2494 | } |
| 2495 | if wtyp != wire.Fixed32Type { |
| 2496 | return nil, 0, errUnknown |
| 2497 | } |
| 2498 | v, n := wire.ConsumeFixed32(b) |
| 2499 | if n < 0 { |
| 2500 | return nil, 0, wire.ParseError(n) |
| 2501 | } |
| 2502 | *sp = append(*sp, int32(v)) |
| 2503 | return ival, n, nil |
| 2504 | } |
| 2505 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2506 | var coderSfixed32SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2507 | size: sizeSfixed32SliceIface, |
| 2508 | marshal: appendSfixed32SliceIface, |
| 2509 | unmarshal: consumeSfixed32SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2512 | // sizeSfixed32PackedSliceIface returns the size of wire encoding a []int32 value as a packed repeated Sfixed32. |
| 2513 | func sizeSfixed32PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2514 | s := *ival.(*[]int32) |
| 2515 | if len(s) == 0 { |
| 2516 | return 0 |
| 2517 | } |
| 2518 | n := len(s) * wire.SizeFixed32() |
| 2519 | return tagsize + wire.SizeBytes(n) |
| 2520 | } |
| 2521 | |
| 2522 | // appendSfixed32PackedSliceIface encodes a []int32 value as a packed repeated Sfixed32. |
| 2523 | func appendSfixed32PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2524 | s := *ival.(*[]int32) |
| 2525 | if len(s) == 0 { |
| 2526 | return b, nil |
| 2527 | } |
| 2528 | b = wire.AppendVarint(b, wiretag) |
| 2529 | n := len(s) * wire.SizeFixed32() |
| 2530 | b = wire.AppendVarint(b, uint64(n)) |
| 2531 | for _, v := range s { |
| 2532 | b = wire.AppendFixed32(b, uint32(v)) |
| 2533 | } |
| 2534 | return b, nil |
| 2535 | } |
| 2536 | |
| 2537 | var coderSfixed32PackedSliceIface = ifaceCoderFuncs{ |
| 2538 | size: sizeSfixed32PackedSliceIface, |
| 2539 | marshal: appendSfixed32PackedSliceIface, |
| 2540 | unmarshal: consumeSfixed32SliceIface, |
| 2541 | } |
| 2542 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2543 | // sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32. |
| 2544 | func sizeFixed32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2545 | |
| 2546 | return tagsize + wire.SizeFixed32() |
| 2547 | } |
| 2548 | |
| 2549 | // appendFixed32 wire encodes a uint32 pointer as a Fixed32. |
| 2550 | func appendFixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2551 | v := *p.Uint32() |
| 2552 | b = wire.AppendVarint(b, wiretag) |
| 2553 | b = wire.AppendFixed32(b, v) |
| 2554 | return b, nil |
| 2555 | } |
| 2556 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2557 | // consumeFixed32 wire decodes a uint32 pointer as a Fixed32. |
| 2558 | func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2559 | if wtyp != wire.Fixed32Type { |
| 2560 | return 0, errUnknown |
| 2561 | } |
| 2562 | v, n := wire.ConsumeFixed32(b) |
| 2563 | if n < 0 { |
| 2564 | return 0, wire.ParseError(n) |
| 2565 | } |
| 2566 | *p.Uint32() = v |
| 2567 | return n, nil |
| 2568 | } |
| 2569 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2570 | var coderFixed32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2571 | size: sizeFixed32, |
| 2572 | marshal: appendFixed32, |
| 2573 | unmarshal: consumeFixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2576 | // sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2577 | // The zero value is not encoded. |
| 2578 | func sizeFixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2579 | v := *p.Uint32() |
| 2580 | if v == 0 { |
| 2581 | return 0 |
| 2582 | } |
| 2583 | return tagsize + wire.SizeFixed32() |
| 2584 | } |
| 2585 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2586 | // appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2587 | // The zero value is not encoded. |
| 2588 | func appendFixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2589 | v := *p.Uint32() |
| 2590 | if v == 0 { |
| 2591 | return b, nil |
| 2592 | } |
| 2593 | b = wire.AppendVarint(b, wiretag) |
| 2594 | b = wire.AppendFixed32(b, v) |
| 2595 | return b, nil |
| 2596 | } |
| 2597 | |
| 2598 | var coderFixed32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2599 | size: sizeFixed32NoZero, |
| 2600 | marshal: appendFixed32NoZero, |
| 2601 | unmarshal: consumeFixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | // sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32. |
| 2605 | // It panics if the pointer is nil. |
| 2606 | func sizeFixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2607 | return tagsize + wire.SizeFixed32() |
| 2608 | } |
| 2609 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2610 | // appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2611 | // It panics if the pointer is nil. |
| 2612 | func appendFixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2613 | v := **p.Uint32Ptr() |
| 2614 | b = wire.AppendVarint(b, wiretag) |
| 2615 | b = wire.AppendFixed32(b, v) |
| 2616 | return b, nil |
| 2617 | } |
| 2618 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2619 | // consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32. |
| 2620 | func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2621 | if wtyp != wire.Fixed32Type { |
| 2622 | return 0, errUnknown |
| 2623 | } |
| 2624 | v, n := wire.ConsumeFixed32(b) |
| 2625 | if n < 0 { |
| 2626 | return 0, wire.ParseError(n) |
| 2627 | } |
| 2628 | vp := p.Uint32Ptr() |
| 2629 | if *vp == nil { |
| 2630 | *vp = new(uint32) |
| 2631 | } |
| 2632 | **vp = v |
| 2633 | return n, nil |
| 2634 | } |
| 2635 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2636 | var coderFixed32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2637 | size: sizeFixed32Ptr, |
| 2638 | marshal: appendFixed32Ptr, |
| 2639 | unmarshal: consumeFixed32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | // sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32. |
| 2643 | func sizeFixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2644 | s := *p.Uint32Slice() |
| 2645 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2646 | return size |
| 2647 | } |
| 2648 | |
| 2649 | // appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32. |
| 2650 | func appendFixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2651 | s := *p.Uint32Slice() |
| 2652 | for _, v := range s { |
| 2653 | b = wire.AppendVarint(b, wiretag) |
| 2654 | b = wire.AppendFixed32(b, v) |
| 2655 | } |
| 2656 | return b, nil |
| 2657 | } |
| 2658 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2659 | // consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32. |
| 2660 | func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2661 | sp := p.Uint32Slice() |
| 2662 | if wtyp == wire.BytesType { |
| 2663 | s := *sp |
| 2664 | b, n = wire.ConsumeBytes(b) |
| 2665 | if n < 0 { |
| 2666 | return 0, wire.ParseError(n) |
| 2667 | } |
| 2668 | for len(b) > 0 { |
| 2669 | v, n := wire.ConsumeFixed32(b) |
| 2670 | if n < 0 { |
| 2671 | return 0, wire.ParseError(n) |
| 2672 | } |
| 2673 | s = append(s, v) |
| 2674 | b = b[n:] |
| 2675 | } |
| 2676 | *sp = s |
| 2677 | return n, nil |
| 2678 | } |
| 2679 | if wtyp != wire.Fixed32Type { |
| 2680 | return 0, errUnknown |
| 2681 | } |
| 2682 | v, n := wire.ConsumeFixed32(b) |
| 2683 | if n < 0 { |
| 2684 | return 0, wire.ParseError(n) |
| 2685 | } |
| 2686 | *sp = append(*sp, v) |
| 2687 | return n, nil |
| 2688 | } |
| 2689 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2690 | var coderFixed32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2691 | size: sizeFixed32Slice, |
| 2692 | marshal: appendFixed32Slice, |
| 2693 | unmarshal: consumeFixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | // sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32. |
| 2697 | func sizeFixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2698 | s := *p.Uint32Slice() |
| 2699 | if len(s) == 0 { |
| 2700 | return 0 |
| 2701 | } |
| 2702 | n := len(s) * wire.SizeFixed32() |
| 2703 | return tagsize + wire.SizeBytes(n) |
| 2704 | } |
| 2705 | |
| 2706 | // appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32. |
| 2707 | func appendFixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2708 | s := *p.Uint32Slice() |
| 2709 | if len(s) == 0 { |
| 2710 | return b, nil |
| 2711 | } |
| 2712 | b = wire.AppendVarint(b, wiretag) |
| 2713 | n := len(s) * wire.SizeFixed32() |
| 2714 | b = wire.AppendVarint(b, uint64(n)) |
| 2715 | for _, v := range s { |
| 2716 | b = wire.AppendFixed32(b, v) |
| 2717 | } |
| 2718 | return b, nil |
| 2719 | } |
| 2720 | |
| 2721 | var coderFixed32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2722 | size: sizeFixed32PackedSlice, |
| 2723 | marshal: appendFixed32PackedSlice, |
| 2724 | unmarshal: consumeFixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | // sizeFixed32Iface returns the size of wire encoding a uint32 value as a Fixed32. |
| 2728 | func sizeFixed32Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 2729 | return tagsize + wire.SizeFixed32() |
| 2730 | } |
| 2731 | |
| 2732 | // appendFixed32Iface encodes a uint32 value as a Fixed32. |
| 2733 | func appendFixed32Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2734 | v := ival.(uint32) |
| 2735 | b = wire.AppendVarint(b, wiretag) |
| 2736 | b = wire.AppendFixed32(b, v) |
| 2737 | return b, nil |
| 2738 | } |
| 2739 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2740 | // consumeFixed32Iface decodes a uint32 value as a Fixed32. |
| 2741 | func consumeFixed32Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 2742 | if wtyp != wire.Fixed32Type { |
| 2743 | return nil, 0, errUnknown |
| 2744 | } |
| 2745 | v, n := wire.ConsumeFixed32(b) |
| 2746 | if n < 0 { |
| 2747 | return nil, 0, wire.ParseError(n) |
| 2748 | } |
| 2749 | return v, n, nil |
| 2750 | } |
| 2751 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2752 | var coderFixed32Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2753 | size: sizeFixed32Iface, |
| 2754 | marshal: appendFixed32Iface, |
| 2755 | unmarshal: consumeFixed32Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | // sizeFixed32SliceIface returns the size of wire encoding a []uint32 value as a repeated Fixed32. |
| 2759 | func sizeFixed32SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2760 | s := *ival.(*[]uint32) |
| 2761 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2762 | return size |
| 2763 | } |
| 2764 | |
| 2765 | // appendFixed32SliceIface encodes a []uint32 value as a repeated Fixed32. |
| 2766 | func appendFixed32SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2767 | s := *ival.(*[]uint32) |
| 2768 | for _, v := range s { |
| 2769 | b = wire.AppendVarint(b, wiretag) |
| 2770 | b = wire.AppendFixed32(b, v) |
| 2771 | } |
| 2772 | return b, nil |
| 2773 | } |
| 2774 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2775 | // consumeFixed32SliceIface wire decodes a []uint32 value as a repeated Fixed32. |
| 2776 | func consumeFixed32SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 2777 | sp := ival.(*[]uint32) |
| 2778 | if wtyp == wire.BytesType { |
| 2779 | s := *sp |
| 2780 | b, n = wire.ConsumeBytes(b) |
| 2781 | if n < 0 { |
| 2782 | return nil, 0, wire.ParseError(n) |
| 2783 | } |
| 2784 | for len(b) > 0 { |
| 2785 | v, n := wire.ConsumeFixed32(b) |
| 2786 | if n < 0 { |
| 2787 | return nil, 0, wire.ParseError(n) |
| 2788 | } |
| 2789 | s = append(s, v) |
| 2790 | b = b[n:] |
| 2791 | } |
| 2792 | *sp = s |
| 2793 | return ival, n, nil |
| 2794 | } |
| 2795 | if wtyp != wire.Fixed32Type { |
| 2796 | return nil, 0, errUnknown |
| 2797 | } |
| 2798 | v, n := wire.ConsumeFixed32(b) |
| 2799 | if n < 0 { |
| 2800 | return nil, 0, wire.ParseError(n) |
| 2801 | } |
| 2802 | *sp = append(*sp, v) |
| 2803 | return ival, n, nil |
| 2804 | } |
| 2805 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2806 | var coderFixed32SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2807 | size: sizeFixed32SliceIface, |
| 2808 | marshal: appendFixed32SliceIface, |
| 2809 | unmarshal: consumeFixed32SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2812 | // sizeFixed32PackedSliceIface returns the size of wire encoding a []uint32 value as a packed repeated Fixed32. |
| 2813 | func sizeFixed32PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 2814 | s := *ival.(*[]uint32) |
| 2815 | if len(s) == 0 { |
| 2816 | return 0 |
| 2817 | } |
| 2818 | n := len(s) * wire.SizeFixed32() |
| 2819 | return tagsize + wire.SizeBytes(n) |
| 2820 | } |
| 2821 | |
| 2822 | // appendFixed32PackedSliceIface encodes a []uint32 value as a packed repeated Fixed32. |
| 2823 | func appendFixed32PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2824 | s := *ival.(*[]uint32) |
| 2825 | if len(s) == 0 { |
| 2826 | return b, nil |
| 2827 | } |
| 2828 | b = wire.AppendVarint(b, wiretag) |
| 2829 | n := len(s) * wire.SizeFixed32() |
| 2830 | b = wire.AppendVarint(b, uint64(n)) |
| 2831 | for _, v := range s { |
| 2832 | b = wire.AppendFixed32(b, v) |
| 2833 | } |
| 2834 | return b, nil |
| 2835 | } |
| 2836 | |
| 2837 | var coderFixed32PackedSliceIface = ifaceCoderFuncs{ |
| 2838 | size: sizeFixed32PackedSliceIface, |
| 2839 | marshal: appendFixed32PackedSliceIface, |
| 2840 | unmarshal: consumeFixed32SliceIface, |
| 2841 | } |
| 2842 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2843 | // sizeFloat returns the size of wire encoding a float32 pointer as a Float. |
| 2844 | func sizeFloat(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2845 | |
| 2846 | return tagsize + wire.SizeFixed32() |
| 2847 | } |
| 2848 | |
| 2849 | // appendFloat wire encodes a float32 pointer as a Float. |
| 2850 | func appendFloat(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2851 | v := *p.Float32() |
| 2852 | b = wire.AppendVarint(b, wiretag) |
| 2853 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 2854 | return b, nil |
| 2855 | } |
| 2856 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2857 | // consumeFloat wire decodes a float32 pointer as a Float. |
| 2858 | func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2859 | if wtyp != wire.Fixed32Type { |
| 2860 | return 0, errUnknown |
| 2861 | } |
| 2862 | v, n := wire.ConsumeFixed32(b) |
| 2863 | if n < 0 { |
| 2864 | return 0, wire.ParseError(n) |
| 2865 | } |
| 2866 | *p.Float32() = math.Float32frombits(v) |
| 2867 | return n, nil |
| 2868 | } |
| 2869 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2870 | var coderFloat = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2871 | size: sizeFloat, |
| 2872 | marshal: appendFloat, |
| 2873 | unmarshal: consumeFloat, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2876 | // sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2877 | // The zero value is not encoded. |
| 2878 | func sizeFloatNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2879 | v := *p.Float32() |
| 2880 | if v == 0 && !math.Signbit(float64(v)) { |
| 2881 | return 0 |
| 2882 | } |
| 2883 | return tagsize + wire.SizeFixed32() |
| 2884 | } |
| 2885 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 2886 | // appendFloatNoZero wire encodes a float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2887 | // The zero value is not encoded. |
| 2888 | func appendFloatNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2889 | v := *p.Float32() |
| 2890 | if v == 0 && !math.Signbit(float64(v)) { |
| 2891 | return b, nil |
| 2892 | } |
| 2893 | b = wire.AppendVarint(b, wiretag) |
| 2894 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 2895 | return b, nil |
| 2896 | } |
| 2897 | |
| 2898 | var coderFloatNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2899 | size: sizeFloatNoZero, |
| 2900 | marshal: appendFloatNoZero, |
| 2901 | unmarshal: consumeFloat, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | // sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float. |
| 2905 | // It panics if the pointer is nil. |
| 2906 | func sizeFloatPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2907 | return tagsize + wire.SizeFixed32() |
| 2908 | } |
| 2909 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2910 | // appendFloatPtr wire encodes a *float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2911 | // It panics if the pointer is nil. |
| 2912 | func appendFloatPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2913 | v := **p.Float32Ptr() |
| 2914 | b = wire.AppendVarint(b, wiretag) |
| 2915 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 2916 | return b, nil |
| 2917 | } |
| 2918 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2919 | // consumeFloatPtr wire decodes a *float32 pointer as a Float. |
| 2920 | func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2921 | if wtyp != wire.Fixed32Type { |
| 2922 | return 0, errUnknown |
| 2923 | } |
| 2924 | v, n := wire.ConsumeFixed32(b) |
| 2925 | if n < 0 { |
| 2926 | return 0, wire.ParseError(n) |
| 2927 | } |
| 2928 | vp := p.Float32Ptr() |
| 2929 | if *vp == nil { |
| 2930 | *vp = new(float32) |
| 2931 | } |
| 2932 | **vp = math.Float32frombits(v) |
| 2933 | return n, nil |
| 2934 | } |
| 2935 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2936 | var coderFloatPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2937 | size: sizeFloatPtr, |
| 2938 | marshal: appendFloatPtr, |
| 2939 | unmarshal: consumeFloatPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | // sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float. |
| 2943 | func sizeFloatSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2944 | s := *p.Float32Slice() |
| 2945 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2946 | return size |
| 2947 | } |
| 2948 | |
| 2949 | // appendFloatSlice encodes a []float32 pointer as a repeated Float. |
| 2950 | func appendFloatSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2951 | s := *p.Float32Slice() |
| 2952 | for _, v := range s { |
| 2953 | b = wire.AppendVarint(b, wiretag) |
| 2954 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 2955 | } |
| 2956 | return b, nil |
| 2957 | } |
| 2958 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2959 | // consumeFloatSlice wire decodes a []float32 pointer as a repeated Float. |
| 2960 | func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2961 | sp := p.Float32Slice() |
| 2962 | if wtyp == wire.BytesType { |
| 2963 | s := *sp |
| 2964 | b, n = wire.ConsumeBytes(b) |
| 2965 | if n < 0 { |
| 2966 | return 0, wire.ParseError(n) |
| 2967 | } |
| 2968 | for len(b) > 0 { |
| 2969 | v, n := wire.ConsumeFixed32(b) |
| 2970 | if n < 0 { |
| 2971 | return 0, wire.ParseError(n) |
| 2972 | } |
| 2973 | s = append(s, math.Float32frombits(v)) |
| 2974 | b = b[n:] |
| 2975 | } |
| 2976 | *sp = s |
| 2977 | return n, nil |
| 2978 | } |
| 2979 | if wtyp != wire.Fixed32Type { |
| 2980 | return 0, errUnknown |
| 2981 | } |
| 2982 | v, n := wire.ConsumeFixed32(b) |
| 2983 | if n < 0 { |
| 2984 | return 0, wire.ParseError(n) |
| 2985 | } |
| 2986 | *sp = append(*sp, math.Float32frombits(v)) |
| 2987 | return n, nil |
| 2988 | } |
| 2989 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2990 | var coderFloatSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2991 | size: sizeFloatSlice, |
| 2992 | marshal: appendFloatSlice, |
| 2993 | unmarshal: consumeFloatSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | // sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float. |
| 2997 | func sizeFloatPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2998 | s := *p.Float32Slice() |
| 2999 | if len(s) == 0 { |
| 3000 | return 0 |
| 3001 | } |
| 3002 | n := len(s) * wire.SizeFixed32() |
| 3003 | return tagsize + wire.SizeBytes(n) |
| 3004 | } |
| 3005 | |
| 3006 | // appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float. |
| 3007 | func appendFloatPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3008 | s := *p.Float32Slice() |
| 3009 | if len(s) == 0 { |
| 3010 | return b, nil |
| 3011 | } |
| 3012 | b = wire.AppendVarint(b, wiretag) |
| 3013 | n := len(s) * wire.SizeFixed32() |
| 3014 | b = wire.AppendVarint(b, uint64(n)) |
| 3015 | for _, v := range s { |
| 3016 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3017 | } |
| 3018 | return b, nil |
| 3019 | } |
| 3020 | |
| 3021 | var coderFloatPackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3022 | size: sizeFloatPackedSlice, |
| 3023 | marshal: appendFloatPackedSlice, |
| 3024 | unmarshal: consumeFloatSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | // sizeFloatIface returns the size of wire encoding a float32 value as a Float. |
| 3028 | func sizeFloatIface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 3029 | return tagsize + wire.SizeFixed32() |
| 3030 | } |
| 3031 | |
| 3032 | // appendFloatIface encodes a float32 value as a Float. |
| 3033 | func appendFloatIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3034 | v := ival.(float32) |
| 3035 | b = wire.AppendVarint(b, wiretag) |
| 3036 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3037 | return b, nil |
| 3038 | } |
| 3039 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3040 | // consumeFloatIface decodes a float32 value as a Float. |
| 3041 | func consumeFloatIface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 3042 | if wtyp != wire.Fixed32Type { |
| 3043 | return nil, 0, errUnknown |
| 3044 | } |
| 3045 | v, n := wire.ConsumeFixed32(b) |
| 3046 | if n < 0 { |
| 3047 | return nil, 0, wire.ParseError(n) |
| 3048 | } |
| 3049 | return math.Float32frombits(v), n, nil |
| 3050 | } |
| 3051 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3052 | var coderFloatIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3053 | size: sizeFloatIface, |
| 3054 | marshal: appendFloatIface, |
| 3055 | unmarshal: consumeFloatIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | // sizeFloatSliceIface returns the size of wire encoding a []float32 value as a repeated Float. |
| 3059 | func sizeFloatSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3060 | s := *ival.(*[]float32) |
| 3061 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 3062 | return size |
| 3063 | } |
| 3064 | |
| 3065 | // appendFloatSliceIface encodes a []float32 value as a repeated Float. |
| 3066 | func appendFloatSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3067 | s := *ival.(*[]float32) |
| 3068 | for _, v := range s { |
| 3069 | b = wire.AppendVarint(b, wiretag) |
| 3070 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3071 | } |
| 3072 | return b, nil |
| 3073 | } |
| 3074 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3075 | // consumeFloatSliceIface wire decodes a []float32 value as a repeated Float. |
| 3076 | func consumeFloatSliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 3077 | sp := ival.(*[]float32) |
| 3078 | if wtyp == wire.BytesType { |
| 3079 | s := *sp |
| 3080 | b, n = wire.ConsumeBytes(b) |
| 3081 | if n < 0 { |
| 3082 | return nil, 0, wire.ParseError(n) |
| 3083 | } |
| 3084 | for len(b) > 0 { |
| 3085 | v, n := wire.ConsumeFixed32(b) |
| 3086 | if n < 0 { |
| 3087 | return nil, 0, wire.ParseError(n) |
| 3088 | } |
| 3089 | s = append(s, math.Float32frombits(v)) |
| 3090 | b = b[n:] |
| 3091 | } |
| 3092 | *sp = s |
| 3093 | return ival, n, nil |
| 3094 | } |
| 3095 | if wtyp != wire.Fixed32Type { |
| 3096 | return nil, 0, errUnknown |
| 3097 | } |
| 3098 | v, n := wire.ConsumeFixed32(b) |
| 3099 | if n < 0 { |
| 3100 | return nil, 0, wire.ParseError(n) |
| 3101 | } |
| 3102 | *sp = append(*sp, math.Float32frombits(v)) |
| 3103 | return ival, n, nil |
| 3104 | } |
| 3105 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3106 | var coderFloatSliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3107 | size: sizeFloatSliceIface, |
| 3108 | marshal: appendFloatSliceIface, |
| 3109 | unmarshal: consumeFloatSliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3112 | // sizeFloatPackedSliceIface returns the size of wire encoding a []float32 value as a packed repeated Float. |
| 3113 | func sizeFloatPackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3114 | s := *ival.(*[]float32) |
| 3115 | if len(s) == 0 { |
| 3116 | return 0 |
| 3117 | } |
| 3118 | n := len(s) * wire.SizeFixed32() |
| 3119 | return tagsize + wire.SizeBytes(n) |
| 3120 | } |
| 3121 | |
| 3122 | // appendFloatPackedSliceIface encodes a []float32 value as a packed repeated Float. |
| 3123 | func appendFloatPackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3124 | s := *ival.(*[]float32) |
| 3125 | if len(s) == 0 { |
| 3126 | return b, nil |
| 3127 | } |
| 3128 | b = wire.AppendVarint(b, wiretag) |
| 3129 | n := len(s) * wire.SizeFixed32() |
| 3130 | b = wire.AppendVarint(b, uint64(n)) |
| 3131 | for _, v := range s { |
| 3132 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3133 | } |
| 3134 | return b, nil |
| 3135 | } |
| 3136 | |
| 3137 | var coderFloatPackedSliceIface = ifaceCoderFuncs{ |
| 3138 | size: sizeFloatPackedSliceIface, |
| 3139 | marshal: appendFloatPackedSliceIface, |
| 3140 | unmarshal: consumeFloatSliceIface, |
| 3141 | } |
| 3142 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3143 | // sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64. |
| 3144 | func sizeSfixed64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3145 | |
| 3146 | return tagsize + wire.SizeFixed64() |
| 3147 | } |
| 3148 | |
| 3149 | // appendSfixed64 wire encodes a int64 pointer as a Sfixed64. |
| 3150 | func appendSfixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3151 | v := *p.Int64() |
| 3152 | b = wire.AppendVarint(b, wiretag) |
| 3153 | b = wire.AppendFixed64(b, uint64(v)) |
| 3154 | return b, nil |
| 3155 | } |
| 3156 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3157 | // consumeSfixed64 wire decodes a int64 pointer as a Sfixed64. |
| 3158 | func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3159 | if wtyp != wire.Fixed64Type { |
| 3160 | return 0, errUnknown |
| 3161 | } |
| 3162 | v, n := wire.ConsumeFixed64(b) |
| 3163 | if n < 0 { |
| 3164 | return 0, wire.ParseError(n) |
| 3165 | } |
| 3166 | *p.Int64() = int64(v) |
| 3167 | return n, nil |
| 3168 | } |
| 3169 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3170 | var coderSfixed64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3171 | size: sizeSfixed64, |
| 3172 | marshal: appendSfixed64, |
| 3173 | unmarshal: consumeSfixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3176 | // sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3177 | // The zero value is not encoded. |
| 3178 | func sizeSfixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3179 | v := *p.Int64() |
| 3180 | if v == 0 { |
| 3181 | return 0 |
| 3182 | } |
| 3183 | return tagsize + wire.SizeFixed64() |
| 3184 | } |
| 3185 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3186 | // appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3187 | // The zero value is not encoded. |
| 3188 | func appendSfixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3189 | v := *p.Int64() |
| 3190 | if v == 0 { |
| 3191 | return b, nil |
| 3192 | } |
| 3193 | b = wire.AppendVarint(b, wiretag) |
| 3194 | b = wire.AppendFixed64(b, uint64(v)) |
| 3195 | return b, nil |
| 3196 | } |
| 3197 | |
| 3198 | var coderSfixed64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3199 | size: sizeSfixed64NoZero, |
| 3200 | marshal: appendSfixed64NoZero, |
| 3201 | unmarshal: consumeSfixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | // sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64. |
| 3205 | // It panics if the pointer is nil. |
| 3206 | func sizeSfixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3207 | return tagsize + wire.SizeFixed64() |
| 3208 | } |
| 3209 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3210 | // appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3211 | // It panics if the pointer is nil. |
| 3212 | func appendSfixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3213 | v := **p.Int64Ptr() |
| 3214 | b = wire.AppendVarint(b, wiretag) |
| 3215 | b = wire.AppendFixed64(b, uint64(v)) |
| 3216 | return b, nil |
| 3217 | } |
| 3218 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3219 | // consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64. |
| 3220 | func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3221 | if wtyp != wire.Fixed64Type { |
| 3222 | return 0, errUnknown |
| 3223 | } |
| 3224 | v, n := wire.ConsumeFixed64(b) |
| 3225 | if n < 0 { |
| 3226 | return 0, wire.ParseError(n) |
| 3227 | } |
| 3228 | vp := p.Int64Ptr() |
| 3229 | if *vp == nil { |
| 3230 | *vp = new(int64) |
| 3231 | } |
| 3232 | **vp = int64(v) |
| 3233 | return n, nil |
| 3234 | } |
| 3235 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3236 | var coderSfixed64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3237 | size: sizeSfixed64Ptr, |
| 3238 | marshal: appendSfixed64Ptr, |
| 3239 | unmarshal: consumeSfixed64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | // sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64. |
| 3243 | func sizeSfixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3244 | s := *p.Int64Slice() |
| 3245 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3246 | return size |
| 3247 | } |
| 3248 | |
| 3249 | // appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64. |
| 3250 | func appendSfixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3251 | s := *p.Int64Slice() |
| 3252 | for _, v := range s { |
| 3253 | b = wire.AppendVarint(b, wiretag) |
| 3254 | b = wire.AppendFixed64(b, uint64(v)) |
| 3255 | } |
| 3256 | return b, nil |
| 3257 | } |
| 3258 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3259 | // consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64. |
| 3260 | func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3261 | sp := p.Int64Slice() |
| 3262 | if wtyp == wire.BytesType { |
| 3263 | s := *sp |
| 3264 | b, n = wire.ConsumeBytes(b) |
| 3265 | if n < 0 { |
| 3266 | return 0, wire.ParseError(n) |
| 3267 | } |
| 3268 | for len(b) > 0 { |
| 3269 | v, n := wire.ConsumeFixed64(b) |
| 3270 | if n < 0 { |
| 3271 | return 0, wire.ParseError(n) |
| 3272 | } |
| 3273 | s = append(s, int64(v)) |
| 3274 | b = b[n:] |
| 3275 | } |
| 3276 | *sp = s |
| 3277 | return n, nil |
| 3278 | } |
| 3279 | if wtyp != wire.Fixed64Type { |
| 3280 | return 0, errUnknown |
| 3281 | } |
| 3282 | v, n := wire.ConsumeFixed64(b) |
| 3283 | if n < 0 { |
| 3284 | return 0, wire.ParseError(n) |
| 3285 | } |
| 3286 | *sp = append(*sp, int64(v)) |
| 3287 | return n, nil |
| 3288 | } |
| 3289 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3290 | var coderSfixed64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3291 | size: sizeSfixed64Slice, |
| 3292 | marshal: appendSfixed64Slice, |
| 3293 | unmarshal: consumeSfixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | // sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64. |
| 3297 | func sizeSfixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3298 | s := *p.Int64Slice() |
| 3299 | if len(s) == 0 { |
| 3300 | return 0 |
| 3301 | } |
| 3302 | n := len(s) * wire.SizeFixed64() |
| 3303 | return tagsize + wire.SizeBytes(n) |
| 3304 | } |
| 3305 | |
| 3306 | // appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64. |
| 3307 | func appendSfixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3308 | s := *p.Int64Slice() |
| 3309 | if len(s) == 0 { |
| 3310 | return b, nil |
| 3311 | } |
| 3312 | b = wire.AppendVarint(b, wiretag) |
| 3313 | n := len(s) * wire.SizeFixed64() |
| 3314 | b = wire.AppendVarint(b, uint64(n)) |
| 3315 | for _, v := range s { |
| 3316 | b = wire.AppendFixed64(b, uint64(v)) |
| 3317 | } |
| 3318 | return b, nil |
| 3319 | } |
| 3320 | |
| 3321 | var coderSfixed64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3322 | size: sizeSfixed64PackedSlice, |
| 3323 | marshal: appendSfixed64PackedSlice, |
| 3324 | unmarshal: consumeSfixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | // sizeSfixed64Iface returns the size of wire encoding a int64 value as a Sfixed64. |
| 3328 | func sizeSfixed64Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 3329 | return tagsize + wire.SizeFixed64() |
| 3330 | } |
| 3331 | |
| 3332 | // appendSfixed64Iface encodes a int64 value as a Sfixed64. |
| 3333 | func appendSfixed64Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3334 | v := ival.(int64) |
| 3335 | b = wire.AppendVarint(b, wiretag) |
| 3336 | b = wire.AppendFixed64(b, uint64(v)) |
| 3337 | return b, nil |
| 3338 | } |
| 3339 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3340 | // consumeSfixed64Iface decodes a int64 value as a Sfixed64. |
| 3341 | func consumeSfixed64Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 3342 | if wtyp != wire.Fixed64Type { |
| 3343 | return nil, 0, errUnknown |
| 3344 | } |
| 3345 | v, n := wire.ConsumeFixed64(b) |
| 3346 | if n < 0 { |
| 3347 | return nil, 0, wire.ParseError(n) |
| 3348 | } |
| 3349 | return int64(v), n, nil |
| 3350 | } |
| 3351 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3352 | var coderSfixed64Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3353 | size: sizeSfixed64Iface, |
| 3354 | marshal: appendSfixed64Iface, |
| 3355 | unmarshal: consumeSfixed64Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | // sizeSfixed64SliceIface returns the size of wire encoding a []int64 value as a repeated Sfixed64. |
| 3359 | func sizeSfixed64SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3360 | s := *ival.(*[]int64) |
| 3361 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3362 | return size |
| 3363 | } |
| 3364 | |
| 3365 | // appendSfixed64SliceIface encodes a []int64 value as a repeated Sfixed64. |
| 3366 | func appendSfixed64SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3367 | s := *ival.(*[]int64) |
| 3368 | for _, v := range s { |
| 3369 | b = wire.AppendVarint(b, wiretag) |
| 3370 | b = wire.AppendFixed64(b, uint64(v)) |
| 3371 | } |
| 3372 | return b, nil |
| 3373 | } |
| 3374 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3375 | // consumeSfixed64SliceIface wire decodes a []int64 value as a repeated Sfixed64. |
| 3376 | func consumeSfixed64SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 3377 | sp := ival.(*[]int64) |
| 3378 | if wtyp == wire.BytesType { |
| 3379 | s := *sp |
| 3380 | b, n = wire.ConsumeBytes(b) |
| 3381 | if n < 0 { |
| 3382 | return nil, 0, wire.ParseError(n) |
| 3383 | } |
| 3384 | for len(b) > 0 { |
| 3385 | v, n := wire.ConsumeFixed64(b) |
| 3386 | if n < 0 { |
| 3387 | return nil, 0, wire.ParseError(n) |
| 3388 | } |
| 3389 | s = append(s, int64(v)) |
| 3390 | b = b[n:] |
| 3391 | } |
| 3392 | *sp = s |
| 3393 | return ival, n, nil |
| 3394 | } |
| 3395 | if wtyp != wire.Fixed64Type { |
| 3396 | return nil, 0, errUnknown |
| 3397 | } |
| 3398 | v, n := wire.ConsumeFixed64(b) |
| 3399 | if n < 0 { |
| 3400 | return nil, 0, wire.ParseError(n) |
| 3401 | } |
| 3402 | *sp = append(*sp, int64(v)) |
| 3403 | return ival, n, nil |
| 3404 | } |
| 3405 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3406 | var coderSfixed64SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3407 | size: sizeSfixed64SliceIface, |
| 3408 | marshal: appendSfixed64SliceIface, |
| 3409 | unmarshal: consumeSfixed64SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3412 | // sizeSfixed64PackedSliceIface returns the size of wire encoding a []int64 value as a packed repeated Sfixed64. |
| 3413 | func sizeSfixed64PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3414 | s := *ival.(*[]int64) |
| 3415 | if len(s) == 0 { |
| 3416 | return 0 |
| 3417 | } |
| 3418 | n := len(s) * wire.SizeFixed64() |
| 3419 | return tagsize + wire.SizeBytes(n) |
| 3420 | } |
| 3421 | |
| 3422 | // appendSfixed64PackedSliceIface encodes a []int64 value as a packed repeated Sfixed64. |
| 3423 | func appendSfixed64PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3424 | s := *ival.(*[]int64) |
| 3425 | if len(s) == 0 { |
| 3426 | return b, nil |
| 3427 | } |
| 3428 | b = wire.AppendVarint(b, wiretag) |
| 3429 | n := len(s) * wire.SizeFixed64() |
| 3430 | b = wire.AppendVarint(b, uint64(n)) |
| 3431 | for _, v := range s { |
| 3432 | b = wire.AppendFixed64(b, uint64(v)) |
| 3433 | } |
| 3434 | return b, nil |
| 3435 | } |
| 3436 | |
| 3437 | var coderSfixed64PackedSliceIface = ifaceCoderFuncs{ |
| 3438 | size: sizeSfixed64PackedSliceIface, |
| 3439 | marshal: appendSfixed64PackedSliceIface, |
| 3440 | unmarshal: consumeSfixed64SliceIface, |
| 3441 | } |
| 3442 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3443 | // sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64. |
| 3444 | func sizeFixed64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3445 | |
| 3446 | return tagsize + wire.SizeFixed64() |
| 3447 | } |
| 3448 | |
| 3449 | // appendFixed64 wire encodes a uint64 pointer as a Fixed64. |
| 3450 | func appendFixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3451 | v := *p.Uint64() |
| 3452 | b = wire.AppendVarint(b, wiretag) |
| 3453 | b = wire.AppendFixed64(b, v) |
| 3454 | return b, nil |
| 3455 | } |
| 3456 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3457 | // consumeFixed64 wire decodes a uint64 pointer as a Fixed64. |
| 3458 | func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3459 | if wtyp != wire.Fixed64Type { |
| 3460 | return 0, errUnknown |
| 3461 | } |
| 3462 | v, n := wire.ConsumeFixed64(b) |
| 3463 | if n < 0 { |
| 3464 | return 0, wire.ParseError(n) |
| 3465 | } |
| 3466 | *p.Uint64() = v |
| 3467 | return n, nil |
| 3468 | } |
| 3469 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3470 | var coderFixed64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3471 | size: sizeFixed64, |
| 3472 | marshal: appendFixed64, |
| 3473 | unmarshal: consumeFixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3476 | // sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3477 | // The zero value is not encoded. |
| 3478 | func sizeFixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3479 | v := *p.Uint64() |
| 3480 | if v == 0 { |
| 3481 | return 0 |
| 3482 | } |
| 3483 | return tagsize + wire.SizeFixed64() |
| 3484 | } |
| 3485 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3486 | // appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3487 | // The zero value is not encoded. |
| 3488 | func appendFixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3489 | v := *p.Uint64() |
| 3490 | if v == 0 { |
| 3491 | return b, nil |
| 3492 | } |
| 3493 | b = wire.AppendVarint(b, wiretag) |
| 3494 | b = wire.AppendFixed64(b, v) |
| 3495 | return b, nil |
| 3496 | } |
| 3497 | |
| 3498 | var coderFixed64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3499 | size: sizeFixed64NoZero, |
| 3500 | marshal: appendFixed64NoZero, |
| 3501 | unmarshal: consumeFixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | // sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64. |
| 3505 | // It panics if the pointer is nil. |
| 3506 | func sizeFixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3507 | return tagsize + wire.SizeFixed64() |
| 3508 | } |
| 3509 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3510 | // appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3511 | // It panics if the pointer is nil. |
| 3512 | func appendFixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3513 | v := **p.Uint64Ptr() |
| 3514 | b = wire.AppendVarint(b, wiretag) |
| 3515 | b = wire.AppendFixed64(b, v) |
| 3516 | return b, nil |
| 3517 | } |
| 3518 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3519 | // consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64. |
| 3520 | func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3521 | if wtyp != wire.Fixed64Type { |
| 3522 | return 0, errUnknown |
| 3523 | } |
| 3524 | v, n := wire.ConsumeFixed64(b) |
| 3525 | if n < 0 { |
| 3526 | return 0, wire.ParseError(n) |
| 3527 | } |
| 3528 | vp := p.Uint64Ptr() |
| 3529 | if *vp == nil { |
| 3530 | *vp = new(uint64) |
| 3531 | } |
| 3532 | **vp = v |
| 3533 | return n, nil |
| 3534 | } |
| 3535 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3536 | var coderFixed64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3537 | size: sizeFixed64Ptr, |
| 3538 | marshal: appendFixed64Ptr, |
| 3539 | unmarshal: consumeFixed64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | // sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64. |
| 3543 | func sizeFixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3544 | s := *p.Uint64Slice() |
| 3545 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3546 | return size |
| 3547 | } |
| 3548 | |
| 3549 | // appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64. |
| 3550 | func appendFixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3551 | s := *p.Uint64Slice() |
| 3552 | for _, v := range s { |
| 3553 | b = wire.AppendVarint(b, wiretag) |
| 3554 | b = wire.AppendFixed64(b, v) |
| 3555 | } |
| 3556 | return b, nil |
| 3557 | } |
| 3558 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3559 | // consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64. |
| 3560 | func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3561 | sp := p.Uint64Slice() |
| 3562 | if wtyp == wire.BytesType { |
| 3563 | s := *sp |
| 3564 | b, n = wire.ConsumeBytes(b) |
| 3565 | if n < 0 { |
| 3566 | return 0, wire.ParseError(n) |
| 3567 | } |
| 3568 | for len(b) > 0 { |
| 3569 | v, n := wire.ConsumeFixed64(b) |
| 3570 | if n < 0 { |
| 3571 | return 0, wire.ParseError(n) |
| 3572 | } |
| 3573 | s = append(s, v) |
| 3574 | b = b[n:] |
| 3575 | } |
| 3576 | *sp = s |
| 3577 | return n, nil |
| 3578 | } |
| 3579 | if wtyp != wire.Fixed64Type { |
| 3580 | return 0, errUnknown |
| 3581 | } |
| 3582 | v, n := wire.ConsumeFixed64(b) |
| 3583 | if n < 0 { |
| 3584 | return 0, wire.ParseError(n) |
| 3585 | } |
| 3586 | *sp = append(*sp, v) |
| 3587 | return n, nil |
| 3588 | } |
| 3589 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3590 | var coderFixed64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3591 | size: sizeFixed64Slice, |
| 3592 | marshal: appendFixed64Slice, |
| 3593 | unmarshal: consumeFixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | // sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64. |
| 3597 | func sizeFixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3598 | s := *p.Uint64Slice() |
| 3599 | if len(s) == 0 { |
| 3600 | return 0 |
| 3601 | } |
| 3602 | n := len(s) * wire.SizeFixed64() |
| 3603 | return tagsize + wire.SizeBytes(n) |
| 3604 | } |
| 3605 | |
| 3606 | // appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64. |
| 3607 | func appendFixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3608 | s := *p.Uint64Slice() |
| 3609 | if len(s) == 0 { |
| 3610 | return b, nil |
| 3611 | } |
| 3612 | b = wire.AppendVarint(b, wiretag) |
| 3613 | n := len(s) * wire.SizeFixed64() |
| 3614 | b = wire.AppendVarint(b, uint64(n)) |
| 3615 | for _, v := range s { |
| 3616 | b = wire.AppendFixed64(b, v) |
| 3617 | } |
| 3618 | return b, nil |
| 3619 | } |
| 3620 | |
| 3621 | var coderFixed64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3622 | size: sizeFixed64PackedSlice, |
| 3623 | marshal: appendFixed64PackedSlice, |
| 3624 | unmarshal: consumeFixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | // sizeFixed64Iface returns the size of wire encoding a uint64 value as a Fixed64. |
| 3628 | func sizeFixed64Iface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 3629 | return tagsize + wire.SizeFixed64() |
| 3630 | } |
| 3631 | |
| 3632 | // appendFixed64Iface encodes a uint64 value as a Fixed64. |
| 3633 | func appendFixed64Iface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3634 | v := ival.(uint64) |
| 3635 | b = wire.AppendVarint(b, wiretag) |
| 3636 | b = wire.AppendFixed64(b, v) |
| 3637 | return b, nil |
| 3638 | } |
| 3639 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3640 | // consumeFixed64Iface decodes a uint64 value as a Fixed64. |
| 3641 | func consumeFixed64Iface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 3642 | if wtyp != wire.Fixed64Type { |
| 3643 | return nil, 0, errUnknown |
| 3644 | } |
| 3645 | v, n := wire.ConsumeFixed64(b) |
| 3646 | if n < 0 { |
| 3647 | return nil, 0, wire.ParseError(n) |
| 3648 | } |
| 3649 | return v, n, nil |
| 3650 | } |
| 3651 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3652 | var coderFixed64Iface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3653 | size: sizeFixed64Iface, |
| 3654 | marshal: appendFixed64Iface, |
| 3655 | unmarshal: consumeFixed64Iface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | // sizeFixed64SliceIface returns the size of wire encoding a []uint64 value as a repeated Fixed64. |
| 3659 | func sizeFixed64SliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3660 | s := *ival.(*[]uint64) |
| 3661 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3662 | return size |
| 3663 | } |
| 3664 | |
| 3665 | // appendFixed64SliceIface encodes a []uint64 value as a repeated Fixed64. |
| 3666 | func appendFixed64SliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3667 | s := *ival.(*[]uint64) |
| 3668 | for _, v := range s { |
| 3669 | b = wire.AppendVarint(b, wiretag) |
| 3670 | b = wire.AppendFixed64(b, v) |
| 3671 | } |
| 3672 | return b, nil |
| 3673 | } |
| 3674 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3675 | // consumeFixed64SliceIface wire decodes a []uint64 value as a repeated Fixed64. |
| 3676 | func consumeFixed64SliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 3677 | sp := ival.(*[]uint64) |
| 3678 | if wtyp == wire.BytesType { |
| 3679 | s := *sp |
| 3680 | b, n = wire.ConsumeBytes(b) |
| 3681 | if n < 0 { |
| 3682 | return nil, 0, wire.ParseError(n) |
| 3683 | } |
| 3684 | for len(b) > 0 { |
| 3685 | v, n := wire.ConsumeFixed64(b) |
| 3686 | if n < 0 { |
| 3687 | return nil, 0, wire.ParseError(n) |
| 3688 | } |
| 3689 | s = append(s, v) |
| 3690 | b = b[n:] |
| 3691 | } |
| 3692 | *sp = s |
| 3693 | return ival, n, nil |
| 3694 | } |
| 3695 | if wtyp != wire.Fixed64Type { |
| 3696 | return nil, 0, errUnknown |
| 3697 | } |
| 3698 | v, n := wire.ConsumeFixed64(b) |
| 3699 | if n < 0 { |
| 3700 | return nil, 0, wire.ParseError(n) |
| 3701 | } |
| 3702 | *sp = append(*sp, v) |
| 3703 | return ival, n, nil |
| 3704 | } |
| 3705 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3706 | var coderFixed64SliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3707 | size: sizeFixed64SliceIface, |
| 3708 | marshal: appendFixed64SliceIface, |
| 3709 | unmarshal: consumeFixed64SliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3712 | // sizeFixed64PackedSliceIface returns the size of wire encoding a []uint64 value as a packed repeated Fixed64. |
| 3713 | func sizeFixed64PackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3714 | s := *ival.(*[]uint64) |
| 3715 | if len(s) == 0 { |
| 3716 | return 0 |
| 3717 | } |
| 3718 | n := len(s) * wire.SizeFixed64() |
| 3719 | return tagsize + wire.SizeBytes(n) |
| 3720 | } |
| 3721 | |
| 3722 | // appendFixed64PackedSliceIface encodes a []uint64 value as a packed repeated Fixed64. |
| 3723 | func appendFixed64PackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3724 | s := *ival.(*[]uint64) |
| 3725 | if len(s) == 0 { |
| 3726 | return b, nil |
| 3727 | } |
| 3728 | b = wire.AppendVarint(b, wiretag) |
| 3729 | n := len(s) * wire.SizeFixed64() |
| 3730 | b = wire.AppendVarint(b, uint64(n)) |
| 3731 | for _, v := range s { |
| 3732 | b = wire.AppendFixed64(b, v) |
| 3733 | } |
| 3734 | return b, nil |
| 3735 | } |
| 3736 | |
| 3737 | var coderFixed64PackedSliceIface = ifaceCoderFuncs{ |
| 3738 | size: sizeFixed64PackedSliceIface, |
| 3739 | marshal: appendFixed64PackedSliceIface, |
| 3740 | unmarshal: consumeFixed64SliceIface, |
| 3741 | } |
| 3742 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3743 | // sizeDouble returns the size of wire encoding a float64 pointer as a Double. |
| 3744 | func sizeDouble(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3745 | |
| 3746 | return tagsize + wire.SizeFixed64() |
| 3747 | } |
| 3748 | |
| 3749 | // appendDouble wire encodes a float64 pointer as a Double. |
| 3750 | func appendDouble(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3751 | v := *p.Float64() |
| 3752 | b = wire.AppendVarint(b, wiretag) |
| 3753 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3754 | return b, nil |
| 3755 | } |
| 3756 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3757 | // consumeDouble wire decodes a float64 pointer as a Double. |
| 3758 | func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3759 | if wtyp != wire.Fixed64Type { |
| 3760 | return 0, errUnknown |
| 3761 | } |
| 3762 | v, n := wire.ConsumeFixed64(b) |
| 3763 | if n < 0 { |
| 3764 | return 0, wire.ParseError(n) |
| 3765 | } |
| 3766 | *p.Float64() = math.Float64frombits(v) |
| 3767 | return n, nil |
| 3768 | } |
| 3769 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3770 | var coderDouble = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3771 | size: sizeDouble, |
| 3772 | marshal: appendDouble, |
| 3773 | unmarshal: consumeDouble, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3776 | // sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3777 | // The zero value is not encoded. |
| 3778 | func sizeDoubleNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3779 | v := *p.Float64() |
| 3780 | if v == 0 && !math.Signbit(float64(v)) { |
| 3781 | return 0 |
| 3782 | } |
| 3783 | return tagsize + wire.SizeFixed64() |
| 3784 | } |
| 3785 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 3786 | // appendDoubleNoZero wire encodes a float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3787 | // The zero value is not encoded. |
| 3788 | func appendDoubleNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3789 | v := *p.Float64() |
| 3790 | if v == 0 && !math.Signbit(float64(v)) { |
| 3791 | return b, nil |
| 3792 | } |
| 3793 | b = wire.AppendVarint(b, wiretag) |
| 3794 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3795 | return b, nil |
| 3796 | } |
| 3797 | |
| 3798 | var coderDoubleNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3799 | size: sizeDoubleNoZero, |
| 3800 | marshal: appendDoubleNoZero, |
| 3801 | unmarshal: consumeDouble, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | // sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double. |
| 3805 | // It panics if the pointer is nil. |
| 3806 | func sizeDoublePtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3807 | return tagsize + wire.SizeFixed64() |
| 3808 | } |
| 3809 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3810 | // appendDoublePtr wire encodes a *float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3811 | // It panics if the pointer is nil. |
| 3812 | func appendDoublePtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3813 | v := **p.Float64Ptr() |
| 3814 | b = wire.AppendVarint(b, wiretag) |
| 3815 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3816 | return b, nil |
| 3817 | } |
| 3818 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3819 | // consumeDoublePtr wire decodes a *float64 pointer as a Double. |
| 3820 | func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3821 | if wtyp != wire.Fixed64Type { |
| 3822 | return 0, errUnknown |
| 3823 | } |
| 3824 | v, n := wire.ConsumeFixed64(b) |
| 3825 | if n < 0 { |
| 3826 | return 0, wire.ParseError(n) |
| 3827 | } |
| 3828 | vp := p.Float64Ptr() |
| 3829 | if *vp == nil { |
| 3830 | *vp = new(float64) |
| 3831 | } |
| 3832 | **vp = math.Float64frombits(v) |
| 3833 | return n, nil |
| 3834 | } |
| 3835 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3836 | var coderDoublePtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3837 | size: sizeDoublePtr, |
| 3838 | marshal: appendDoublePtr, |
| 3839 | unmarshal: consumeDoublePtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | // sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double. |
| 3843 | func sizeDoubleSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3844 | s := *p.Float64Slice() |
| 3845 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3846 | return size |
| 3847 | } |
| 3848 | |
| 3849 | // appendDoubleSlice encodes a []float64 pointer as a repeated Double. |
| 3850 | func appendDoubleSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3851 | s := *p.Float64Slice() |
| 3852 | for _, v := range s { |
| 3853 | b = wire.AppendVarint(b, wiretag) |
| 3854 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3855 | } |
| 3856 | return b, nil |
| 3857 | } |
| 3858 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3859 | // consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double. |
| 3860 | func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3861 | sp := p.Float64Slice() |
| 3862 | if wtyp == wire.BytesType { |
| 3863 | s := *sp |
| 3864 | b, n = wire.ConsumeBytes(b) |
| 3865 | if n < 0 { |
| 3866 | return 0, wire.ParseError(n) |
| 3867 | } |
| 3868 | for len(b) > 0 { |
| 3869 | v, n := wire.ConsumeFixed64(b) |
| 3870 | if n < 0 { |
| 3871 | return 0, wire.ParseError(n) |
| 3872 | } |
| 3873 | s = append(s, math.Float64frombits(v)) |
| 3874 | b = b[n:] |
| 3875 | } |
| 3876 | *sp = s |
| 3877 | return n, nil |
| 3878 | } |
| 3879 | if wtyp != wire.Fixed64Type { |
| 3880 | return 0, errUnknown |
| 3881 | } |
| 3882 | v, n := wire.ConsumeFixed64(b) |
| 3883 | if n < 0 { |
| 3884 | return 0, wire.ParseError(n) |
| 3885 | } |
| 3886 | *sp = append(*sp, math.Float64frombits(v)) |
| 3887 | return n, nil |
| 3888 | } |
| 3889 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3890 | var coderDoubleSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3891 | size: sizeDoubleSlice, |
| 3892 | marshal: appendDoubleSlice, |
| 3893 | unmarshal: consumeDoubleSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | // sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double. |
| 3897 | func sizeDoublePackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3898 | s := *p.Float64Slice() |
| 3899 | if len(s) == 0 { |
| 3900 | return 0 |
| 3901 | } |
| 3902 | n := len(s) * wire.SizeFixed64() |
| 3903 | return tagsize + wire.SizeBytes(n) |
| 3904 | } |
| 3905 | |
| 3906 | // appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double. |
| 3907 | func appendDoublePackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3908 | s := *p.Float64Slice() |
| 3909 | if len(s) == 0 { |
| 3910 | return b, nil |
| 3911 | } |
| 3912 | b = wire.AppendVarint(b, wiretag) |
| 3913 | n := len(s) * wire.SizeFixed64() |
| 3914 | b = wire.AppendVarint(b, uint64(n)) |
| 3915 | for _, v := range s { |
| 3916 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3917 | } |
| 3918 | return b, nil |
| 3919 | } |
| 3920 | |
| 3921 | var coderDoublePackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3922 | size: sizeDoublePackedSlice, |
| 3923 | marshal: appendDoublePackedSlice, |
| 3924 | unmarshal: consumeDoubleSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | // sizeDoubleIface returns the size of wire encoding a float64 value as a Double. |
| 3928 | func sizeDoubleIface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 3929 | return tagsize + wire.SizeFixed64() |
| 3930 | } |
| 3931 | |
| 3932 | // appendDoubleIface encodes a float64 value as a Double. |
| 3933 | func appendDoubleIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3934 | v := ival.(float64) |
| 3935 | b = wire.AppendVarint(b, wiretag) |
| 3936 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3937 | return b, nil |
| 3938 | } |
| 3939 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3940 | // consumeDoubleIface decodes a float64 value as a Double. |
| 3941 | func consumeDoubleIface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 3942 | if wtyp != wire.Fixed64Type { |
| 3943 | return nil, 0, errUnknown |
| 3944 | } |
| 3945 | v, n := wire.ConsumeFixed64(b) |
| 3946 | if n < 0 { |
| 3947 | return nil, 0, wire.ParseError(n) |
| 3948 | } |
| 3949 | return math.Float64frombits(v), n, nil |
| 3950 | } |
| 3951 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3952 | var coderDoubleIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3953 | size: sizeDoubleIface, |
| 3954 | marshal: appendDoubleIface, |
| 3955 | unmarshal: consumeDoubleIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | // sizeDoubleSliceIface returns the size of wire encoding a []float64 value as a repeated Double. |
| 3959 | func sizeDoubleSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 3960 | s := *ival.(*[]float64) |
| 3961 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3962 | return size |
| 3963 | } |
| 3964 | |
| 3965 | // appendDoubleSliceIface encodes a []float64 value as a repeated Double. |
| 3966 | func appendDoubleSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3967 | s := *ival.(*[]float64) |
| 3968 | for _, v := range s { |
| 3969 | b = wire.AppendVarint(b, wiretag) |
| 3970 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3971 | } |
| 3972 | return b, nil |
| 3973 | } |
| 3974 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3975 | // consumeDoubleSliceIface wire decodes a []float64 value as a repeated Double. |
| 3976 | func consumeDoubleSliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 3977 | sp := ival.(*[]float64) |
| 3978 | if wtyp == wire.BytesType { |
| 3979 | s := *sp |
| 3980 | b, n = wire.ConsumeBytes(b) |
| 3981 | if n < 0 { |
| 3982 | return nil, 0, wire.ParseError(n) |
| 3983 | } |
| 3984 | for len(b) > 0 { |
| 3985 | v, n := wire.ConsumeFixed64(b) |
| 3986 | if n < 0 { |
| 3987 | return nil, 0, wire.ParseError(n) |
| 3988 | } |
| 3989 | s = append(s, math.Float64frombits(v)) |
| 3990 | b = b[n:] |
| 3991 | } |
| 3992 | *sp = s |
| 3993 | return ival, n, nil |
| 3994 | } |
| 3995 | if wtyp != wire.Fixed64Type { |
| 3996 | return nil, 0, errUnknown |
| 3997 | } |
| 3998 | v, n := wire.ConsumeFixed64(b) |
| 3999 | if n < 0 { |
| 4000 | return nil, 0, wire.ParseError(n) |
| 4001 | } |
| 4002 | *sp = append(*sp, math.Float64frombits(v)) |
| 4003 | return ival, n, nil |
| 4004 | } |
| 4005 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4006 | var coderDoubleSliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4007 | size: sizeDoubleSliceIface, |
| 4008 | marshal: appendDoubleSliceIface, |
| 4009 | unmarshal: consumeDoubleSliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4012 | // sizeDoublePackedSliceIface returns the size of wire encoding a []float64 value as a packed repeated Double. |
| 4013 | func sizeDoublePackedSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 4014 | s := *ival.(*[]float64) |
| 4015 | if len(s) == 0 { |
| 4016 | return 0 |
| 4017 | } |
| 4018 | n := len(s) * wire.SizeFixed64() |
| 4019 | return tagsize + wire.SizeBytes(n) |
| 4020 | } |
| 4021 | |
| 4022 | // appendDoublePackedSliceIface encodes a []float64 value as a packed repeated Double. |
| 4023 | func appendDoublePackedSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4024 | s := *ival.(*[]float64) |
| 4025 | if len(s) == 0 { |
| 4026 | return b, nil |
| 4027 | } |
| 4028 | b = wire.AppendVarint(b, wiretag) |
| 4029 | n := len(s) * wire.SizeFixed64() |
| 4030 | b = wire.AppendVarint(b, uint64(n)) |
| 4031 | for _, v := range s { |
| 4032 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 4033 | } |
| 4034 | return b, nil |
| 4035 | } |
| 4036 | |
| 4037 | var coderDoublePackedSliceIface = ifaceCoderFuncs{ |
| 4038 | size: sizeDoublePackedSliceIface, |
| 4039 | marshal: appendDoublePackedSliceIface, |
| 4040 | unmarshal: consumeDoubleSliceIface, |
| 4041 | } |
| 4042 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4043 | // sizeString returns the size of wire encoding a string pointer as a String. |
| 4044 | func sizeString(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4045 | v := *p.String() |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4046 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | // appendString wire encodes a string pointer as a String. |
| 4050 | func appendString(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4051 | v := *p.String() |
| 4052 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4053 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4054 | return b, nil |
| 4055 | } |
| 4056 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4057 | // consumeString wire decodes a string pointer as a String. |
| 4058 | func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4059 | if wtyp != wire.BytesType { |
| 4060 | return 0, errUnknown |
| 4061 | } |
| 4062 | v, n := wire.ConsumeString(b) |
| 4063 | if n < 0 { |
| 4064 | return 0, wire.ParseError(n) |
| 4065 | } |
| 4066 | *p.String() = v |
| 4067 | return n, nil |
| 4068 | } |
| 4069 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4070 | var coderString = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4071 | size: sizeString, |
| 4072 | marshal: appendString, |
| 4073 | unmarshal: consumeString, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4076 | // appendStringValidateUTF8 wire encodes a string pointer as a String. |
| 4077 | func appendStringValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4078 | v := *p.String() |
| 4079 | b = wire.AppendVarint(b, wiretag) |
| 4080 | b = wire.AppendString(b, v) |
| 4081 | if !utf8.ValidString(v) { |
| 4082 | return b, errInvalidUTF8{} |
| 4083 | } |
| 4084 | return b, nil |
| 4085 | } |
| 4086 | |
| 4087 | // consumeStringValidateUTF8 wire decodes a string pointer as a String. |
| 4088 | func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4089 | if wtyp != wire.BytesType { |
| 4090 | return 0, errUnknown |
| 4091 | } |
| 4092 | v, n := wire.ConsumeString(b) |
| 4093 | if n < 0 { |
| 4094 | return 0, wire.ParseError(n) |
| 4095 | } |
| 4096 | if !utf8.ValidString(v) { |
| 4097 | return 0, errInvalidUTF8{} |
| 4098 | } |
| 4099 | *p.String() = v |
| 4100 | return n, nil |
| 4101 | } |
| 4102 | |
| 4103 | var coderStringValidateUTF8 = pointerCoderFuncs{ |
| 4104 | size: sizeString, |
| 4105 | marshal: appendStringValidateUTF8, |
| 4106 | unmarshal: consumeStringValidateUTF8, |
| 4107 | } |
| 4108 | |
| 4109 | // sizeStringNoZero returns the size of wire encoding a string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4110 | // The zero value is not encoded. |
| 4111 | func sizeStringNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4112 | v := *p.String() |
| 4113 | if len(v) == 0 { |
| 4114 | return 0 |
| 4115 | } |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4116 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4119 | // appendStringNoZero wire encodes a string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4120 | // The zero value is not encoded. |
| 4121 | func appendStringNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4122 | v := *p.String() |
| 4123 | if len(v) == 0 { |
| 4124 | return b, nil |
| 4125 | } |
| 4126 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4127 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4128 | return b, nil |
| 4129 | } |
| 4130 | |
| 4131 | var coderStringNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4132 | size: sizeStringNoZero, |
| 4133 | marshal: appendStringNoZero, |
| 4134 | unmarshal: consumeString, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4137 | // appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String. |
| 4138 | // The zero value is not encoded. |
| 4139 | func appendStringNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4140 | v := *p.String() |
| 4141 | if len(v) == 0 { |
| 4142 | return b, nil |
| 4143 | } |
| 4144 | b = wire.AppendVarint(b, wiretag) |
| 4145 | b = wire.AppendString(b, v) |
| 4146 | if !utf8.ValidString(v) { |
| 4147 | return b, errInvalidUTF8{} |
| 4148 | } |
| 4149 | return b, nil |
| 4150 | } |
| 4151 | |
| 4152 | var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 4153 | size: sizeStringNoZero, |
| 4154 | marshal: appendStringNoZeroValidateUTF8, |
| 4155 | unmarshal: consumeStringValidateUTF8, |
| 4156 | } |
| 4157 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4158 | // sizeStringPtr returns the size of wire encoding a *string pointer as a String. |
| 4159 | // It panics if the pointer is nil. |
| 4160 | func sizeStringPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4161 | v := **p.StringPtr() |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4162 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4165 | // appendStringPtr wire encodes a *string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4166 | // It panics if the pointer is nil. |
| 4167 | func appendStringPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4168 | v := **p.StringPtr() |
| 4169 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4170 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4171 | return b, nil |
| 4172 | } |
| 4173 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4174 | // consumeStringPtr wire decodes a *string pointer as a String. |
| 4175 | func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4176 | if wtyp != wire.BytesType { |
| 4177 | return 0, errUnknown |
| 4178 | } |
| 4179 | v, n := wire.ConsumeString(b) |
| 4180 | if n < 0 { |
| 4181 | return 0, wire.ParseError(n) |
| 4182 | } |
| 4183 | vp := p.StringPtr() |
| 4184 | if *vp == nil { |
| 4185 | *vp = new(string) |
| 4186 | } |
| 4187 | **vp = v |
| 4188 | return n, nil |
| 4189 | } |
| 4190 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4191 | var coderStringPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4192 | size: sizeStringPtr, |
| 4193 | marshal: appendStringPtr, |
| 4194 | unmarshal: consumeStringPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | // sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String. |
| 4198 | func sizeStringSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4199 | s := *p.StringSlice() |
| 4200 | for _, v := range s { |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4201 | size += tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4202 | } |
| 4203 | return size |
| 4204 | } |
| 4205 | |
| 4206 | // appendStringSlice encodes a []string pointer as a repeated String. |
| 4207 | func appendStringSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4208 | s := *p.StringSlice() |
| 4209 | for _, v := range s { |
| 4210 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4211 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4212 | } |
| 4213 | return b, nil |
| 4214 | } |
| 4215 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4216 | // consumeStringSlice wire decodes a []string pointer as a repeated String. |
| 4217 | func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4218 | sp := p.StringSlice() |
| 4219 | if wtyp != wire.BytesType { |
| 4220 | return 0, errUnknown |
| 4221 | } |
| 4222 | v, n := wire.ConsumeString(b) |
| 4223 | if n < 0 { |
| 4224 | return 0, wire.ParseError(n) |
| 4225 | } |
| 4226 | *sp = append(*sp, v) |
| 4227 | return n, nil |
| 4228 | } |
| 4229 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4230 | var coderStringSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4231 | size: sizeStringSlice, |
| 4232 | marshal: appendStringSlice, |
| 4233 | unmarshal: consumeStringSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4234 | } |
| 4235 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4236 | // appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String. |
| 4237 | func appendStringSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4238 | s := *p.StringSlice() |
| 4239 | for _, v := range s { |
| 4240 | b = wire.AppendVarint(b, wiretag) |
| 4241 | b = wire.AppendString(b, v) |
| 4242 | if !utf8.ValidString(v) { |
| 4243 | return b, errInvalidUTF8{} |
| 4244 | } |
| 4245 | } |
| 4246 | return b, nil |
| 4247 | } |
| 4248 | |
| 4249 | // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String. |
| 4250 | func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4251 | sp := p.StringSlice() |
| 4252 | if wtyp != wire.BytesType { |
| 4253 | return 0, errUnknown |
| 4254 | } |
| 4255 | v, n := wire.ConsumeString(b) |
| 4256 | if n < 0 { |
| 4257 | return 0, wire.ParseError(n) |
| 4258 | } |
| 4259 | if !utf8.ValidString(v) { |
| 4260 | return 0, errInvalidUTF8{} |
| 4261 | } |
| 4262 | *sp = append(*sp, v) |
| 4263 | return n, nil |
| 4264 | } |
| 4265 | |
| 4266 | var coderStringSliceValidateUTF8 = pointerCoderFuncs{ |
| 4267 | size: sizeStringSlice, |
| 4268 | marshal: appendStringSliceValidateUTF8, |
| 4269 | unmarshal: consumeStringSliceValidateUTF8, |
| 4270 | } |
| 4271 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4272 | // sizeStringIface returns the size of wire encoding a string value as a String. |
| 4273 | func sizeStringIface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 4274 | v := ival.(string) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4275 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | // appendStringIface encodes a string value as a String. |
| 4279 | func appendStringIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4280 | v := ival.(string) |
| 4281 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4282 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4283 | return b, nil |
| 4284 | } |
| 4285 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4286 | // consumeStringIface decodes a string value as a String. |
| 4287 | func consumeStringIface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 4288 | if wtyp != wire.BytesType { |
| 4289 | return nil, 0, errUnknown |
| 4290 | } |
| 4291 | v, n := wire.ConsumeString(b) |
| 4292 | if n < 0 { |
| 4293 | return nil, 0, wire.ParseError(n) |
| 4294 | } |
| 4295 | return v, n, nil |
| 4296 | } |
| 4297 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4298 | var coderStringIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4299 | size: sizeStringIface, |
| 4300 | marshal: appendStringIface, |
| 4301 | unmarshal: consumeStringIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4304 | // appendStringIfaceValidateUTF8 encodes a string value as a String. |
| 4305 | func appendStringIfaceValidateUTF8(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4306 | v := ival.(string) |
| 4307 | b = wire.AppendVarint(b, wiretag) |
| 4308 | b = wire.AppendString(b, v) |
| 4309 | if !utf8.ValidString(v) { |
| 4310 | return b, errInvalidUTF8{} |
| 4311 | } |
| 4312 | return b, nil |
| 4313 | } |
| 4314 | |
| 4315 | // consumeStringIfaceValidateUTF8 decodes a string value as a String. |
| 4316 | func consumeStringIfaceValidateUTF8(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 4317 | if wtyp != wire.BytesType { |
| 4318 | return nil, 0, errUnknown |
| 4319 | } |
| 4320 | v, n := wire.ConsumeString(b) |
| 4321 | if n < 0 { |
| 4322 | return nil, 0, wire.ParseError(n) |
| 4323 | } |
| 4324 | if !utf8.ValidString(v) { |
| 4325 | return nil, 0, errInvalidUTF8{} |
| 4326 | } |
| 4327 | return v, n, nil |
| 4328 | } |
| 4329 | |
| 4330 | var coderStringIfaceValidateUTF8 = ifaceCoderFuncs{ |
| 4331 | size: sizeStringIface, |
| 4332 | marshal: appendStringIfaceValidateUTF8, |
| 4333 | unmarshal: consumeStringIfaceValidateUTF8, |
| 4334 | } |
| 4335 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4336 | // sizeStringSliceIface returns the size of wire encoding a []string value as a repeated String. |
| 4337 | func sizeStringSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 4338 | s := *ival.(*[]string) |
| 4339 | for _, v := range s { |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4340 | size += tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4341 | } |
| 4342 | return size |
| 4343 | } |
| 4344 | |
| 4345 | // appendStringSliceIface encodes a []string value as a repeated String. |
| 4346 | func appendStringSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4347 | s := *ival.(*[]string) |
| 4348 | for _, v := range s { |
| 4349 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4350 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4351 | } |
| 4352 | return b, nil |
| 4353 | } |
| 4354 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4355 | // consumeStringSliceIface wire decodes a []string value as a repeated String. |
| 4356 | func consumeStringSliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 4357 | sp := ival.(*[]string) |
| 4358 | if wtyp != wire.BytesType { |
| 4359 | return nil, 0, errUnknown |
| 4360 | } |
| 4361 | v, n := wire.ConsumeString(b) |
| 4362 | if n < 0 { |
| 4363 | return nil, 0, wire.ParseError(n) |
| 4364 | } |
| 4365 | *sp = append(*sp, v) |
| 4366 | return ival, n, nil |
| 4367 | } |
| 4368 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4369 | var coderStringSliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4370 | size: sizeStringSliceIface, |
| 4371 | marshal: appendStringSliceIface, |
| 4372 | unmarshal: consumeStringSliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | // sizeBytes returns the size of wire encoding a []byte pointer as a Bytes. |
| 4376 | func sizeBytes(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4377 | v := *p.Bytes() |
| 4378 | return tagsize + wire.SizeBytes(len(v)) |
| 4379 | } |
| 4380 | |
| 4381 | // appendBytes wire encodes a []byte pointer as a Bytes. |
| 4382 | func appendBytes(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4383 | v := *p.Bytes() |
| 4384 | b = wire.AppendVarint(b, wiretag) |
| 4385 | b = wire.AppendBytes(b, v) |
| 4386 | return b, nil |
| 4387 | } |
| 4388 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4389 | // consumeBytes wire decodes a []byte pointer as a Bytes. |
| 4390 | func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4391 | if wtyp != wire.BytesType { |
| 4392 | return 0, errUnknown |
| 4393 | } |
| 4394 | v, n := wire.ConsumeBytes(b) |
| 4395 | if n < 0 { |
| 4396 | return 0, wire.ParseError(n) |
| 4397 | } |
| 4398 | *p.Bytes() = append(([]byte)(nil), v...) |
| 4399 | return n, nil |
| 4400 | } |
| 4401 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4402 | var coderBytes = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4403 | size: sizeBytes, |
| 4404 | marshal: appendBytes, |
| 4405 | unmarshal: consumeBytes, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4408 | // appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 4409 | func appendBytesValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4410 | v := *p.Bytes() |
| 4411 | b = wire.AppendVarint(b, wiretag) |
| 4412 | b = wire.AppendBytes(b, v) |
| 4413 | if !utf8.Valid(v) { |
| 4414 | return b, errInvalidUTF8{} |
| 4415 | } |
| 4416 | return b, nil |
| 4417 | } |
| 4418 | |
| 4419 | // consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes. |
| 4420 | func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4421 | if wtyp != wire.BytesType { |
| 4422 | return 0, errUnknown |
| 4423 | } |
| 4424 | v, n := wire.ConsumeBytes(b) |
| 4425 | if n < 0 { |
| 4426 | return 0, wire.ParseError(n) |
| 4427 | } |
| 4428 | if !utf8.Valid(v) { |
| 4429 | return 0, errInvalidUTF8{} |
| 4430 | } |
| 4431 | *p.Bytes() = append(([]byte)(nil), v...) |
| 4432 | return n, nil |
| 4433 | } |
| 4434 | |
| 4435 | var coderBytesValidateUTF8 = pointerCoderFuncs{ |
| 4436 | size: sizeBytes, |
| 4437 | marshal: appendBytesValidateUTF8, |
| 4438 | unmarshal: consumeBytesValidateUTF8, |
| 4439 | } |
| 4440 | |
| 4441 | // sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4442 | // The zero value is not encoded. |
| 4443 | func sizeBytesNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4444 | v := *p.Bytes() |
| 4445 | if len(v) == 0 { |
| 4446 | return 0 |
| 4447 | } |
| 4448 | return tagsize + wire.SizeBytes(len(v)) |
| 4449 | } |
| 4450 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4451 | // appendBytesNoZero wire encodes a []byte pointer as a Bytes. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4452 | // The zero value is not encoded. |
| 4453 | func appendBytesNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4454 | v := *p.Bytes() |
| 4455 | if len(v) == 0 { |
| 4456 | return b, nil |
| 4457 | } |
| 4458 | b = wire.AppendVarint(b, wiretag) |
| 4459 | b = wire.AppendBytes(b, v) |
| 4460 | return b, nil |
| 4461 | } |
| 4462 | |
| 4463 | var coderBytesNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4464 | size: sizeBytesNoZero, |
| 4465 | marshal: appendBytesNoZero, |
| 4466 | unmarshal: consumeBytes, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4469 | // appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 4470 | // The zero value is not encoded. |
| 4471 | func appendBytesNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4472 | v := *p.Bytes() |
| 4473 | if len(v) == 0 { |
| 4474 | return b, nil |
| 4475 | } |
| 4476 | b = wire.AppendVarint(b, wiretag) |
| 4477 | b = wire.AppendBytes(b, v) |
| 4478 | if !utf8.Valid(v) { |
| 4479 | return b, errInvalidUTF8{} |
| 4480 | } |
| 4481 | return b, nil |
| 4482 | } |
| 4483 | |
| 4484 | var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 4485 | size: sizeBytesNoZero, |
| 4486 | marshal: appendBytesNoZeroValidateUTF8, |
| 4487 | unmarshal: consumeBytesValidateUTF8, |
| 4488 | } |
| 4489 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4490 | // sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes. |
| 4491 | func sizeBytesSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4492 | s := *p.BytesSlice() |
| 4493 | for _, v := range s { |
| 4494 | size += tagsize + wire.SizeBytes(len(v)) |
| 4495 | } |
| 4496 | return size |
| 4497 | } |
| 4498 | |
| 4499 | // appendBytesSlice encodes a [][]byte pointer as a repeated Bytes. |
| 4500 | func appendBytesSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4501 | s := *p.BytesSlice() |
| 4502 | for _, v := range s { |
| 4503 | b = wire.AppendVarint(b, wiretag) |
| 4504 | b = wire.AppendBytes(b, v) |
| 4505 | } |
| 4506 | return b, nil |
| 4507 | } |
| 4508 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4509 | // consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes. |
| 4510 | func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4511 | sp := p.BytesSlice() |
| 4512 | if wtyp != wire.BytesType { |
| 4513 | return 0, errUnknown |
| 4514 | } |
| 4515 | v, n := wire.ConsumeBytes(b) |
| 4516 | if n < 0 { |
| 4517 | return 0, wire.ParseError(n) |
| 4518 | } |
| 4519 | *sp = append(*sp, append(([]byte)(nil), v...)) |
| 4520 | return n, nil |
| 4521 | } |
| 4522 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4523 | var coderBytesSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4524 | size: sizeBytesSlice, |
| 4525 | marshal: appendBytesSlice, |
| 4526 | unmarshal: consumeBytesSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4529 | // appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes. |
| 4530 | func appendBytesSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4531 | s := *p.BytesSlice() |
| 4532 | for _, v := range s { |
| 4533 | b = wire.AppendVarint(b, wiretag) |
| 4534 | b = wire.AppendBytes(b, v) |
| 4535 | if !utf8.Valid(v) { |
| 4536 | return b, errInvalidUTF8{} |
| 4537 | } |
| 4538 | } |
| 4539 | return b, nil |
| 4540 | } |
| 4541 | |
| 4542 | // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes. |
| 4543 | func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4544 | sp := p.BytesSlice() |
| 4545 | if wtyp != wire.BytesType { |
| 4546 | return 0, errUnknown |
| 4547 | } |
| 4548 | v, n := wire.ConsumeBytes(b) |
| 4549 | if n < 0 { |
| 4550 | return 0, wire.ParseError(n) |
| 4551 | } |
| 4552 | if !utf8.Valid(v) { |
| 4553 | return 0, errInvalidUTF8{} |
| 4554 | } |
| 4555 | *sp = append(*sp, append(([]byte)(nil), v...)) |
| 4556 | return n, nil |
| 4557 | } |
| 4558 | |
| 4559 | var coderBytesSliceValidateUTF8 = pointerCoderFuncs{ |
| 4560 | size: sizeBytesSlice, |
| 4561 | marshal: appendBytesSliceValidateUTF8, |
| 4562 | unmarshal: consumeBytesSliceValidateUTF8, |
| 4563 | } |
| 4564 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4565 | // sizeBytesIface returns the size of wire encoding a []byte value as a Bytes. |
| 4566 | func sizeBytesIface(ival interface{}, tagsize int, _ marshalOptions) int { |
| 4567 | v := ival.([]byte) |
| 4568 | return tagsize + wire.SizeBytes(len(v)) |
| 4569 | } |
| 4570 | |
| 4571 | // appendBytesIface encodes a []byte value as a Bytes. |
| 4572 | func appendBytesIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4573 | v := ival.([]byte) |
| 4574 | b = wire.AppendVarint(b, wiretag) |
| 4575 | b = wire.AppendBytes(b, v) |
| 4576 | return b, nil |
| 4577 | } |
| 4578 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4579 | // consumeBytesIface decodes a []byte value as a Bytes. |
| 4580 | func consumeBytesIface(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 4581 | if wtyp != wire.BytesType { |
| 4582 | return nil, 0, errUnknown |
| 4583 | } |
| 4584 | v, n := wire.ConsumeBytes(b) |
| 4585 | if n < 0 { |
| 4586 | return nil, 0, wire.ParseError(n) |
| 4587 | } |
| 4588 | return append(([]byte)(nil), v...), n, nil |
| 4589 | } |
| 4590 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4591 | var coderBytesIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4592 | size: sizeBytesIface, |
| 4593 | marshal: appendBytesIface, |
| 4594 | unmarshal: consumeBytesIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame^] | 4597 | // appendBytesIfaceValidateUTF8 encodes a []byte value as a Bytes. |
| 4598 | func appendBytesIfaceValidateUTF8(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4599 | v := ival.([]byte) |
| 4600 | b = wire.AppendVarint(b, wiretag) |
| 4601 | b = wire.AppendBytes(b, v) |
| 4602 | if !utf8.Valid(v) { |
| 4603 | return b, errInvalidUTF8{} |
| 4604 | } |
| 4605 | return b, nil |
| 4606 | } |
| 4607 | |
| 4608 | // consumeBytesIfaceValidateUTF8 decodes a []byte value as a Bytes. |
| 4609 | func consumeBytesIfaceValidateUTF8(b []byte, _ interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (interface{}, int, error) { |
| 4610 | if wtyp != wire.BytesType { |
| 4611 | return nil, 0, errUnknown |
| 4612 | } |
| 4613 | v, n := wire.ConsumeBytes(b) |
| 4614 | if n < 0 { |
| 4615 | return nil, 0, wire.ParseError(n) |
| 4616 | } |
| 4617 | if !utf8.Valid(v) { |
| 4618 | return nil, 0, errInvalidUTF8{} |
| 4619 | } |
| 4620 | return append(([]byte)(nil), v...), n, nil |
| 4621 | } |
| 4622 | |
| 4623 | var coderBytesIfaceValidateUTF8 = ifaceCoderFuncs{ |
| 4624 | size: sizeBytesIface, |
| 4625 | marshal: appendBytesIfaceValidateUTF8, |
| 4626 | unmarshal: consumeBytesIfaceValidateUTF8, |
| 4627 | } |
| 4628 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4629 | // sizeBytesSliceIface returns the size of wire encoding a [][]byte value as a repeated Bytes. |
| 4630 | func sizeBytesSliceIface(ival interface{}, tagsize int, _ marshalOptions) (size int) { |
| 4631 | s := *ival.(*[][]byte) |
| 4632 | for _, v := range s { |
| 4633 | size += tagsize + wire.SizeBytes(len(v)) |
| 4634 | } |
| 4635 | return size |
| 4636 | } |
| 4637 | |
| 4638 | // appendBytesSliceIface encodes a [][]byte value as a repeated Bytes. |
| 4639 | func appendBytesSliceIface(b []byte, ival interface{}, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4640 | s := *ival.(*[][]byte) |
| 4641 | for _, v := range s { |
| 4642 | b = wire.AppendVarint(b, wiretag) |
| 4643 | b = wire.AppendBytes(b, v) |
| 4644 | } |
| 4645 | return b, nil |
| 4646 | } |
| 4647 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4648 | // consumeBytesSliceIface wire decodes a [][]byte value as a repeated Bytes. |
| 4649 | func consumeBytesSliceIface(b []byte, ival interface{}, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ interface{}, n int, err error) { |
| 4650 | sp := ival.(*[][]byte) |
| 4651 | if wtyp != wire.BytesType { |
| 4652 | return nil, 0, errUnknown |
| 4653 | } |
| 4654 | v, n := wire.ConsumeBytes(b) |
| 4655 | if n < 0 { |
| 4656 | return nil, 0, wire.ParseError(n) |
| 4657 | } |
| 4658 | *sp = append(*sp, append(([]byte)(nil), v...)) |
| 4659 | return ival, n, nil |
| 4660 | } |
| 4661 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4662 | var coderBytesSliceIface = ifaceCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4663 | size: sizeBytesSliceIface, |
| 4664 | marshal: appendBytesSliceIface, |
| 4665 | unmarshal: consumeBytesSliceIface, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | var wireTypes = map[protoreflect.Kind]wire.Type{ |
| 4669 | protoreflect.BoolKind: wire.VarintType, |
| 4670 | protoreflect.EnumKind: wire.VarintType, |
| 4671 | protoreflect.Int32Kind: wire.VarintType, |
| 4672 | protoreflect.Sint32Kind: wire.VarintType, |
| 4673 | protoreflect.Uint32Kind: wire.VarintType, |
| 4674 | protoreflect.Int64Kind: wire.VarintType, |
| 4675 | protoreflect.Sint64Kind: wire.VarintType, |
| 4676 | protoreflect.Uint64Kind: wire.VarintType, |
| 4677 | protoreflect.Sfixed32Kind: wire.Fixed32Type, |
| 4678 | protoreflect.Fixed32Kind: wire.Fixed32Type, |
| 4679 | protoreflect.FloatKind: wire.Fixed32Type, |
| 4680 | protoreflect.Sfixed64Kind: wire.Fixed64Type, |
| 4681 | protoreflect.Fixed64Kind: wire.Fixed64Type, |
| 4682 | protoreflect.DoubleKind: wire.Fixed64Type, |
| 4683 | protoreflect.StringKind: wire.BytesType, |
| 4684 | protoreflect.BytesKind: wire.BytesType, |
| 4685 | protoreflect.MessageKind: wire.BytesType, |
| 4686 | protoreflect.GroupKind: wire.StartGroupType, |
| 4687 | } |