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