1// Protocol Buffers for Go with Gadgets 2// 3// Copyright (c) 2018, The GoGo Authors. All rights reserved. 4// http://github.com/gogo/protobuf 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: 9// 10// * Redistributions of source code must retain the above copyright 11// notice, this list of conditions and the following disclaimer. 12// * Redistributions in binary form must reproduce the above 13// copyright notice, this list of conditions and the following disclaimer 14// in the documentation and/or other materials provided with the 15// distribution. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29package proto 30 31import ( 32 "io" 33 "reflect" 34) 35 36func makeStdDoubleValueMarshaler(u *marshalInfo) (sizer, marshaler) { 37 return func(ptr pointer, tagsize int) int { 38 t := ptr.asPointerTo(u.typ).Interface().(*float64) 39 v := &float64Value{*t} 40 siz := Size(v) 41 return tagsize + SizeVarint(uint64(siz)) + siz 42 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 43 t := ptr.asPointerTo(u.typ).Interface().(*float64) 44 v := &float64Value{*t} 45 buf, err := Marshal(v) 46 if err != nil { 47 return nil, err 48 } 49 b = appendVarint(b, wiretag) 50 b = appendVarint(b, uint64(len(buf))) 51 b = append(b, buf...) 52 return b, nil 53 } 54} 55 56func makeStdDoubleValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 57 return func(ptr pointer, tagsize int) int { 58 if ptr.isNil() { 59 return 0 60 } 61 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64) 62 v := &float64Value{*t} 63 siz := Size(v) 64 return tagsize + SizeVarint(uint64(siz)) + siz 65 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 66 if ptr.isNil() { 67 return b, nil 68 } 69 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64) 70 v := &float64Value{*t} 71 buf, err := Marshal(v) 72 if err != nil { 73 return nil, err 74 } 75 b = appendVarint(b, wiretag) 76 b = appendVarint(b, uint64(len(buf))) 77 b = append(b, buf...) 78 return b, nil 79 } 80} 81 82func makeStdDoubleValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 83 return func(ptr pointer, tagsize int) int { 84 s := ptr.getSlice(u.typ) 85 n := 0 86 for i := 0; i < s.Len(); i++ { 87 elem := s.Index(i) 88 t := elem.Interface().(float64) 89 v := &float64Value{t} 90 siz := Size(v) 91 n += siz + SizeVarint(uint64(siz)) + tagsize 92 } 93 return n 94 }, 95 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 96 s := ptr.getSlice(u.typ) 97 for i := 0; i < s.Len(); i++ { 98 elem := s.Index(i) 99 t := elem.Interface().(float64) 100 v := &float64Value{t} 101 siz := Size(v) 102 buf, err := Marshal(v) 103 if err != nil { 104 return nil, err 105 } 106 b = appendVarint(b, wiretag) 107 b = appendVarint(b, uint64(siz)) 108 b = append(b, buf...) 109 } 110 111 return b, nil 112 } 113} 114 115func makeStdDoubleValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 116 return func(ptr pointer, tagsize int) int { 117 s := ptr.getSlice(reflect.PtrTo(u.typ)) 118 n := 0 119 for i := 0; i < s.Len(); i++ { 120 elem := s.Index(i) 121 t := elem.Interface().(*float64) 122 v := &float64Value{*t} 123 siz := Size(v) 124 n += siz + SizeVarint(uint64(siz)) + tagsize 125 } 126 return n 127 }, 128 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 129 s := ptr.getSlice(reflect.PtrTo(u.typ)) 130 for i := 0; i < s.Len(); i++ { 131 elem := s.Index(i) 132 t := elem.Interface().(*float64) 133 v := &float64Value{*t} 134 siz := Size(v) 135 buf, err := Marshal(v) 136 if err != nil { 137 return nil, err 138 } 139 b = appendVarint(b, wiretag) 140 b = appendVarint(b, uint64(siz)) 141 b = append(b, buf...) 142 } 143 144 return b, nil 145 } 146} 147 148func makeStdDoubleValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 149 return func(b []byte, f pointer, w int) ([]byte, error) { 150 if w != WireBytes { 151 return nil, errInternalBadWireType 152 } 153 x, n := decodeVarint(b) 154 if n == 0 { 155 return nil, io.ErrUnexpectedEOF 156 } 157 b = b[n:] 158 if x > uint64(len(b)) { 159 return nil, io.ErrUnexpectedEOF 160 } 161 m := &float64Value{} 162 if err := Unmarshal(b[:x], m); err != nil { 163 return nil, err 164 } 165 s := f.asPointerTo(sub.typ).Elem() 166 s.Set(reflect.ValueOf(m.Value)) 167 return b[x:], nil 168 } 169} 170 171func makeStdDoubleValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 172 return func(b []byte, f pointer, w int) ([]byte, error) { 173 if w != WireBytes { 174 return nil, errInternalBadWireType 175 } 176 x, n := decodeVarint(b) 177 if n == 0 { 178 return nil, io.ErrUnexpectedEOF 179 } 180 b = b[n:] 181 if x > uint64(len(b)) { 182 return nil, io.ErrUnexpectedEOF 183 } 184 m := &float64Value{} 185 if err := Unmarshal(b[:x], m); err != nil { 186 return nil, err 187 } 188 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 189 s.Set(reflect.ValueOf(&m.Value)) 190 return b[x:], nil 191 } 192} 193 194func makeStdDoubleValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 195 return func(b []byte, f pointer, w int) ([]byte, error) { 196 if w != WireBytes { 197 return nil, errInternalBadWireType 198 } 199 x, n := decodeVarint(b) 200 if n == 0 { 201 return nil, io.ErrUnexpectedEOF 202 } 203 b = b[n:] 204 if x > uint64(len(b)) { 205 return nil, io.ErrUnexpectedEOF 206 } 207 m := &float64Value{} 208 if err := Unmarshal(b[:x], m); err != nil { 209 return nil, err 210 } 211 slice := f.getSlice(reflect.PtrTo(sub.typ)) 212 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 213 slice.Set(newSlice) 214 return b[x:], nil 215 } 216} 217 218func makeStdDoubleValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 219 return func(b []byte, f pointer, w int) ([]byte, error) { 220 if w != WireBytes { 221 return nil, errInternalBadWireType 222 } 223 x, n := decodeVarint(b) 224 if n == 0 { 225 return nil, io.ErrUnexpectedEOF 226 } 227 b = b[n:] 228 if x > uint64(len(b)) { 229 return nil, io.ErrUnexpectedEOF 230 } 231 m := &float64Value{} 232 if err := Unmarshal(b[:x], m); err != nil { 233 return nil, err 234 } 235 slice := f.getSlice(sub.typ) 236 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 237 slice.Set(newSlice) 238 return b[x:], nil 239 } 240} 241 242func makeStdFloatValueMarshaler(u *marshalInfo) (sizer, marshaler) { 243 return func(ptr pointer, tagsize int) int { 244 t := ptr.asPointerTo(u.typ).Interface().(*float32) 245 v := &float32Value{*t} 246 siz := Size(v) 247 return tagsize + SizeVarint(uint64(siz)) + siz 248 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 249 t := ptr.asPointerTo(u.typ).Interface().(*float32) 250 v := &float32Value{*t} 251 buf, err := Marshal(v) 252 if err != nil { 253 return nil, err 254 } 255 b = appendVarint(b, wiretag) 256 b = appendVarint(b, uint64(len(buf))) 257 b = append(b, buf...) 258 return b, nil 259 } 260} 261 262func makeStdFloatValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 263 return func(ptr pointer, tagsize int) int { 264 if ptr.isNil() { 265 return 0 266 } 267 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32) 268 v := &float32Value{*t} 269 siz := Size(v) 270 return tagsize + SizeVarint(uint64(siz)) + siz 271 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 272 if ptr.isNil() { 273 return b, nil 274 } 275 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32) 276 v := &float32Value{*t} 277 buf, err := Marshal(v) 278 if err != nil { 279 return nil, err 280 } 281 b = appendVarint(b, wiretag) 282 b = appendVarint(b, uint64(len(buf))) 283 b = append(b, buf...) 284 return b, nil 285 } 286} 287 288func makeStdFloatValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 289 return func(ptr pointer, tagsize int) int { 290 s := ptr.getSlice(u.typ) 291 n := 0 292 for i := 0; i < s.Len(); i++ { 293 elem := s.Index(i) 294 t := elem.Interface().(float32) 295 v := &float32Value{t} 296 siz := Size(v) 297 n += siz + SizeVarint(uint64(siz)) + tagsize 298 } 299 return n 300 }, 301 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 302 s := ptr.getSlice(u.typ) 303 for i := 0; i < s.Len(); i++ { 304 elem := s.Index(i) 305 t := elem.Interface().(float32) 306 v := &float32Value{t} 307 siz := Size(v) 308 buf, err := Marshal(v) 309 if err != nil { 310 return nil, err 311 } 312 b = appendVarint(b, wiretag) 313 b = appendVarint(b, uint64(siz)) 314 b = append(b, buf...) 315 } 316 317 return b, nil 318 } 319} 320 321func makeStdFloatValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 322 return func(ptr pointer, tagsize int) int { 323 s := ptr.getSlice(reflect.PtrTo(u.typ)) 324 n := 0 325 for i := 0; i < s.Len(); i++ { 326 elem := s.Index(i) 327 t := elem.Interface().(*float32) 328 v := &float32Value{*t} 329 siz := Size(v) 330 n += siz + SizeVarint(uint64(siz)) + tagsize 331 } 332 return n 333 }, 334 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 335 s := ptr.getSlice(reflect.PtrTo(u.typ)) 336 for i := 0; i < s.Len(); i++ { 337 elem := s.Index(i) 338 t := elem.Interface().(*float32) 339 v := &float32Value{*t} 340 siz := Size(v) 341 buf, err := Marshal(v) 342 if err != nil { 343 return nil, err 344 } 345 b = appendVarint(b, wiretag) 346 b = appendVarint(b, uint64(siz)) 347 b = append(b, buf...) 348 } 349 350 return b, nil 351 } 352} 353 354func makeStdFloatValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 355 return func(b []byte, f pointer, w int) ([]byte, error) { 356 if w != WireBytes { 357 return nil, errInternalBadWireType 358 } 359 x, n := decodeVarint(b) 360 if n == 0 { 361 return nil, io.ErrUnexpectedEOF 362 } 363 b = b[n:] 364 if x > uint64(len(b)) { 365 return nil, io.ErrUnexpectedEOF 366 } 367 m := &float32Value{} 368 if err := Unmarshal(b[:x], m); err != nil { 369 return nil, err 370 } 371 s := f.asPointerTo(sub.typ).Elem() 372 s.Set(reflect.ValueOf(m.Value)) 373 return b[x:], nil 374 } 375} 376 377func makeStdFloatValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 378 return func(b []byte, f pointer, w int) ([]byte, error) { 379 if w != WireBytes { 380 return nil, errInternalBadWireType 381 } 382 x, n := decodeVarint(b) 383 if n == 0 { 384 return nil, io.ErrUnexpectedEOF 385 } 386 b = b[n:] 387 if x > uint64(len(b)) { 388 return nil, io.ErrUnexpectedEOF 389 } 390 m := &float32Value{} 391 if err := Unmarshal(b[:x], m); err != nil { 392 return nil, err 393 } 394 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 395 s.Set(reflect.ValueOf(&m.Value)) 396 return b[x:], nil 397 } 398} 399 400func makeStdFloatValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 401 return func(b []byte, f pointer, w int) ([]byte, error) { 402 if w != WireBytes { 403 return nil, errInternalBadWireType 404 } 405 x, n := decodeVarint(b) 406 if n == 0 { 407 return nil, io.ErrUnexpectedEOF 408 } 409 b = b[n:] 410 if x > uint64(len(b)) { 411 return nil, io.ErrUnexpectedEOF 412 } 413 m := &float32Value{} 414 if err := Unmarshal(b[:x], m); err != nil { 415 return nil, err 416 } 417 slice := f.getSlice(reflect.PtrTo(sub.typ)) 418 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 419 slice.Set(newSlice) 420 return b[x:], nil 421 } 422} 423 424func makeStdFloatValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 425 return func(b []byte, f pointer, w int) ([]byte, error) { 426 if w != WireBytes { 427 return nil, errInternalBadWireType 428 } 429 x, n := decodeVarint(b) 430 if n == 0 { 431 return nil, io.ErrUnexpectedEOF 432 } 433 b = b[n:] 434 if x > uint64(len(b)) { 435 return nil, io.ErrUnexpectedEOF 436 } 437 m := &float32Value{} 438 if err := Unmarshal(b[:x], m); err != nil { 439 return nil, err 440 } 441 slice := f.getSlice(sub.typ) 442 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 443 slice.Set(newSlice) 444 return b[x:], nil 445 } 446} 447 448func makeStdInt64ValueMarshaler(u *marshalInfo) (sizer, marshaler) { 449 return func(ptr pointer, tagsize int) int { 450 t := ptr.asPointerTo(u.typ).Interface().(*int64) 451 v := &int64Value{*t} 452 siz := Size(v) 453 return tagsize + SizeVarint(uint64(siz)) + siz 454 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 455 t := ptr.asPointerTo(u.typ).Interface().(*int64) 456 v := &int64Value{*t} 457 buf, err := Marshal(v) 458 if err != nil { 459 return nil, err 460 } 461 b = appendVarint(b, wiretag) 462 b = appendVarint(b, uint64(len(buf))) 463 b = append(b, buf...) 464 return b, nil 465 } 466} 467 468func makeStdInt64ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 469 return func(ptr pointer, tagsize int) int { 470 if ptr.isNil() { 471 return 0 472 } 473 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64) 474 v := &int64Value{*t} 475 siz := Size(v) 476 return tagsize + SizeVarint(uint64(siz)) + siz 477 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 478 if ptr.isNil() { 479 return b, nil 480 } 481 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64) 482 v := &int64Value{*t} 483 buf, err := Marshal(v) 484 if err != nil { 485 return nil, err 486 } 487 b = appendVarint(b, wiretag) 488 b = appendVarint(b, uint64(len(buf))) 489 b = append(b, buf...) 490 return b, nil 491 } 492} 493 494func makeStdInt64ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 495 return func(ptr pointer, tagsize int) int { 496 s := ptr.getSlice(u.typ) 497 n := 0 498 for i := 0; i < s.Len(); i++ { 499 elem := s.Index(i) 500 t := elem.Interface().(int64) 501 v := &int64Value{t} 502 siz := Size(v) 503 n += siz + SizeVarint(uint64(siz)) + tagsize 504 } 505 return n 506 }, 507 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 508 s := ptr.getSlice(u.typ) 509 for i := 0; i < s.Len(); i++ { 510 elem := s.Index(i) 511 t := elem.Interface().(int64) 512 v := &int64Value{t} 513 siz := Size(v) 514 buf, err := Marshal(v) 515 if err != nil { 516 return nil, err 517 } 518 b = appendVarint(b, wiretag) 519 b = appendVarint(b, uint64(siz)) 520 b = append(b, buf...) 521 } 522 523 return b, nil 524 } 525} 526 527func makeStdInt64ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 528 return func(ptr pointer, tagsize int) int { 529 s := ptr.getSlice(reflect.PtrTo(u.typ)) 530 n := 0 531 for i := 0; i < s.Len(); i++ { 532 elem := s.Index(i) 533 t := elem.Interface().(*int64) 534 v := &int64Value{*t} 535 siz := Size(v) 536 n += siz + SizeVarint(uint64(siz)) + tagsize 537 } 538 return n 539 }, 540 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 541 s := ptr.getSlice(reflect.PtrTo(u.typ)) 542 for i := 0; i < s.Len(); i++ { 543 elem := s.Index(i) 544 t := elem.Interface().(*int64) 545 v := &int64Value{*t} 546 siz := Size(v) 547 buf, err := Marshal(v) 548 if err != nil { 549 return nil, err 550 } 551 b = appendVarint(b, wiretag) 552 b = appendVarint(b, uint64(siz)) 553 b = append(b, buf...) 554 } 555 556 return b, nil 557 } 558} 559 560func makeStdInt64ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 561 return func(b []byte, f pointer, w int) ([]byte, error) { 562 if w != WireBytes { 563 return nil, errInternalBadWireType 564 } 565 x, n := decodeVarint(b) 566 if n == 0 { 567 return nil, io.ErrUnexpectedEOF 568 } 569 b = b[n:] 570 if x > uint64(len(b)) { 571 return nil, io.ErrUnexpectedEOF 572 } 573 m := &int64Value{} 574 if err := Unmarshal(b[:x], m); err != nil { 575 return nil, err 576 } 577 s := f.asPointerTo(sub.typ).Elem() 578 s.Set(reflect.ValueOf(m.Value)) 579 return b[x:], nil 580 } 581} 582 583func makeStdInt64ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 584 return func(b []byte, f pointer, w int) ([]byte, error) { 585 if w != WireBytes { 586 return nil, errInternalBadWireType 587 } 588 x, n := decodeVarint(b) 589 if n == 0 { 590 return nil, io.ErrUnexpectedEOF 591 } 592 b = b[n:] 593 if x > uint64(len(b)) { 594 return nil, io.ErrUnexpectedEOF 595 } 596 m := &int64Value{} 597 if err := Unmarshal(b[:x], m); err != nil { 598 return nil, err 599 } 600 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 601 s.Set(reflect.ValueOf(&m.Value)) 602 return b[x:], nil 603 } 604} 605 606func makeStdInt64ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 607 return func(b []byte, f pointer, w int) ([]byte, error) { 608 if w != WireBytes { 609 return nil, errInternalBadWireType 610 } 611 x, n := decodeVarint(b) 612 if n == 0 { 613 return nil, io.ErrUnexpectedEOF 614 } 615 b = b[n:] 616 if x > uint64(len(b)) { 617 return nil, io.ErrUnexpectedEOF 618 } 619 m := &int64Value{} 620 if err := Unmarshal(b[:x], m); err != nil { 621 return nil, err 622 } 623 slice := f.getSlice(reflect.PtrTo(sub.typ)) 624 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 625 slice.Set(newSlice) 626 return b[x:], nil 627 } 628} 629 630func makeStdInt64ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 631 return func(b []byte, f pointer, w int) ([]byte, error) { 632 if w != WireBytes { 633 return nil, errInternalBadWireType 634 } 635 x, n := decodeVarint(b) 636 if n == 0 { 637 return nil, io.ErrUnexpectedEOF 638 } 639 b = b[n:] 640 if x > uint64(len(b)) { 641 return nil, io.ErrUnexpectedEOF 642 } 643 m := &int64Value{} 644 if err := Unmarshal(b[:x], m); err != nil { 645 return nil, err 646 } 647 slice := f.getSlice(sub.typ) 648 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 649 slice.Set(newSlice) 650 return b[x:], nil 651 } 652} 653 654func makeStdUInt64ValueMarshaler(u *marshalInfo) (sizer, marshaler) { 655 return func(ptr pointer, tagsize int) int { 656 t := ptr.asPointerTo(u.typ).Interface().(*uint64) 657 v := &uint64Value{*t} 658 siz := Size(v) 659 return tagsize + SizeVarint(uint64(siz)) + siz 660 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 661 t := ptr.asPointerTo(u.typ).Interface().(*uint64) 662 v := &uint64Value{*t} 663 buf, err := Marshal(v) 664 if err != nil { 665 return nil, err 666 } 667 b = appendVarint(b, wiretag) 668 b = appendVarint(b, uint64(len(buf))) 669 b = append(b, buf...) 670 return b, nil 671 } 672} 673 674func makeStdUInt64ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 675 return func(ptr pointer, tagsize int) int { 676 if ptr.isNil() { 677 return 0 678 } 679 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64) 680 v := &uint64Value{*t} 681 siz := Size(v) 682 return tagsize + SizeVarint(uint64(siz)) + siz 683 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 684 if ptr.isNil() { 685 return b, nil 686 } 687 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64) 688 v := &uint64Value{*t} 689 buf, err := Marshal(v) 690 if err != nil { 691 return nil, err 692 } 693 b = appendVarint(b, wiretag) 694 b = appendVarint(b, uint64(len(buf))) 695 b = append(b, buf...) 696 return b, nil 697 } 698} 699 700func makeStdUInt64ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 701 return func(ptr pointer, tagsize int) int { 702 s := ptr.getSlice(u.typ) 703 n := 0 704 for i := 0; i < s.Len(); i++ { 705 elem := s.Index(i) 706 t := elem.Interface().(uint64) 707 v := &uint64Value{t} 708 siz := Size(v) 709 n += siz + SizeVarint(uint64(siz)) + tagsize 710 } 711 return n 712 }, 713 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 714 s := ptr.getSlice(u.typ) 715 for i := 0; i < s.Len(); i++ { 716 elem := s.Index(i) 717 t := elem.Interface().(uint64) 718 v := &uint64Value{t} 719 siz := Size(v) 720 buf, err := Marshal(v) 721 if err != nil { 722 return nil, err 723 } 724 b = appendVarint(b, wiretag) 725 b = appendVarint(b, uint64(siz)) 726 b = append(b, buf...) 727 } 728 729 return b, nil 730 } 731} 732 733func makeStdUInt64ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 734 return func(ptr pointer, tagsize int) int { 735 s := ptr.getSlice(reflect.PtrTo(u.typ)) 736 n := 0 737 for i := 0; i < s.Len(); i++ { 738 elem := s.Index(i) 739 t := elem.Interface().(*uint64) 740 v := &uint64Value{*t} 741 siz := Size(v) 742 n += siz + SizeVarint(uint64(siz)) + tagsize 743 } 744 return n 745 }, 746 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 747 s := ptr.getSlice(reflect.PtrTo(u.typ)) 748 for i := 0; i < s.Len(); i++ { 749 elem := s.Index(i) 750 t := elem.Interface().(*uint64) 751 v := &uint64Value{*t} 752 siz := Size(v) 753 buf, err := Marshal(v) 754 if err != nil { 755 return nil, err 756 } 757 b = appendVarint(b, wiretag) 758 b = appendVarint(b, uint64(siz)) 759 b = append(b, buf...) 760 } 761 762 return b, nil 763 } 764} 765 766func makeStdUInt64ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 767 return func(b []byte, f pointer, w int) ([]byte, error) { 768 if w != WireBytes { 769 return nil, errInternalBadWireType 770 } 771 x, n := decodeVarint(b) 772 if n == 0 { 773 return nil, io.ErrUnexpectedEOF 774 } 775 b = b[n:] 776 if x > uint64(len(b)) { 777 return nil, io.ErrUnexpectedEOF 778 } 779 m := &uint64Value{} 780 if err := Unmarshal(b[:x], m); err != nil { 781 return nil, err 782 } 783 s := f.asPointerTo(sub.typ).Elem() 784 s.Set(reflect.ValueOf(m.Value)) 785 return b[x:], nil 786 } 787} 788 789func makeStdUInt64ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 790 return func(b []byte, f pointer, w int) ([]byte, error) { 791 if w != WireBytes { 792 return nil, errInternalBadWireType 793 } 794 x, n := decodeVarint(b) 795 if n == 0 { 796 return nil, io.ErrUnexpectedEOF 797 } 798 b = b[n:] 799 if x > uint64(len(b)) { 800 return nil, io.ErrUnexpectedEOF 801 } 802 m := &uint64Value{} 803 if err := Unmarshal(b[:x], m); err != nil { 804 return nil, err 805 } 806 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 807 s.Set(reflect.ValueOf(&m.Value)) 808 return b[x:], nil 809 } 810} 811 812func makeStdUInt64ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 813 return func(b []byte, f pointer, w int) ([]byte, error) { 814 if w != WireBytes { 815 return nil, errInternalBadWireType 816 } 817 x, n := decodeVarint(b) 818 if n == 0 { 819 return nil, io.ErrUnexpectedEOF 820 } 821 b = b[n:] 822 if x > uint64(len(b)) { 823 return nil, io.ErrUnexpectedEOF 824 } 825 m := &uint64Value{} 826 if err := Unmarshal(b[:x], m); err != nil { 827 return nil, err 828 } 829 slice := f.getSlice(reflect.PtrTo(sub.typ)) 830 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 831 slice.Set(newSlice) 832 return b[x:], nil 833 } 834} 835 836func makeStdUInt64ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 837 return func(b []byte, f pointer, w int) ([]byte, error) { 838 if w != WireBytes { 839 return nil, errInternalBadWireType 840 } 841 x, n := decodeVarint(b) 842 if n == 0 { 843 return nil, io.ErrUnexpectedEOF 844 } 845 b = b[n:] 846 if x > uint64(len(b)) { 847 return nil, io.ErrUnexpectedEOF 848 } 849 m := &uint64Value{} 850 if err := Unmarshal(b[:x], m); err != nil { 851 return nil, err 852 } 853 slice := f.getSlice(sub.typ) 854 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 855 slice.Set(newSlice) 856 return b[x:], nil 857 } 858} 859 860func makeStdInt32ValueMarshaler(u *marshalInfo) (sizer, marshaler) { 861 return func(ptr pointer, tagsize int) int { 862 t := ptr.asPointerTo(u.typ).Interface().(*int32) 863 v := &int32Value{*t} 864 siz := Size(v) 865 return tagsize + SizeVarint(uint64(siz)) + siz 866 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 867 t := ptr.asPointerTo(u.typ).Interface().(*int32) 868 v := &int32Value{*t} 869 buf, err := Marshal(v) 870 if err != nil { 871 return nil, err 872 } 873 b = appendVarint(b, wiretag) 874 b = appendVarint(b, uint64(len(buf))) 875 b = append(b, buf...) 876 return b, nil 877 } 878} 879 880func makeStdInt32ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 881 return func(ptr pointer, tagsize int) int { 882 if ptr.isNil() { 883 return 0 884 } 885 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32) 886 v := &int32Value{*t} 887 siz := Size(v) 888 return tagsize + SizeVarint(uint64(siz)) + siz 889 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 890 if ptr.isNil() { 891 return b, nil 892 } 893 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32) 894 v := &int32Value{*t} 895 buf, err := Marshal(v) 896 if err != nil { 897 return nil, err 898 } 899 b = appendVarint(b, wiretag) 900 b = appendVarint(b, uint64(len(buf))) 901 b = append(b, buf...) 902 return b, nil 903 } 904} 905 906func makeStdInt32ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 907 return func(ptr pointer, tagsize int) int { 908 s := ptr.getSlice(u.typ) 909 n := 0 910 for i := 0; i < s.Len(); i++ { 911 elem := s.Index(i) 912 t := elem.Interface().(int32) 913 v := &int32Value{t} 914 siz := Size(v) 915 n += siz + SizeVarint(uint64(siz)) + tagsize 916 } 917 return n 918 }, 919 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 920 s := ptr.getSlice(u.typ) 921 for i := 0; i < s.Len(); i++ { 922 elem := s.Index(i) 923 t := elem.Interface().(int32) 924 v := &int32Value{t} 925 siz := Size(v) 926 buf, err := Marshal(v) 927 if err != nil { 928 return nil, err 929 } 930 b = appendVarint(b, wiretag) 931 b = appendVarint(b, uint64(siz)) 932 b = append(b, buf...) 933 } 934 935 return b, nil 936 } 937} 938 939func makeStdInt32ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 940 return func(ptr pointer, tagsize int) int { 941 s := ptr.getSlice(reflect.PtrTo(u.typ)) 942 n := 0 943 for i := 0; i < s.Len(); i++ { 944 elem := s.Index(i) 945 t := elem.Interface().(*int32) 946 v := &int32Value{*t} 947 siz := Size(v) 948 n += siz + SizeVarint(uint64(siz)) + tagsize 949 } 950 return n 951 }, 952 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 953 s := ptr.getSlice(reflect.PtrTo(u.typ)) 954 for i := 0; i < s.Len(); i++ { 955 elem := s.Index(i) 956 t := elem.Interface().(*int32) 957 v := &int32Value{*t} 958 siz := Size(v) 959 buf, err := Marshal(v) 960 if err != nil { 961 return nil, err 962 } 963 b = appendVarint(b, wiretag) 964 b = appendVarint(b, uint64(siz)) 965 b = append(b, buf...) 966 } 967 968 return b, nil 969 } 970} 971 972func makeStdInt32ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 973 return func(b []byte, f pointer, w int) ([]byte, error) { 974 if w != WireBytes { 975 return nil, errInternalBadWireType 976 } 977 x, n := decodeVarint(b) 978 if n == 0 { 979 return nil, io.ErrUnexpectedEOF 980 } 981 b = b[n:] 982 if x > uint64(len(b)) { 983 return nil, io.ErrUnexpectedEOF 984 } 985 m := &int32Value{} 986 if err := Unmarshal(b[:x], m); err != nil { 987 return nil, err 988 } 989 s := f.asPointerTo(sub.typ).Elem() 990 s.Set(reflect.ValueOf(m.Value)) 991 return b[x:], nil 992 } 993} 994 995func makeStdInt32ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 996 return func(b []byte, f pointer, w int) ([]byte, error) { 997 if w != WireBytes { 998 return nil, errInternalBadWireType 999 } 1000 x, n := decodeVarint(b) 1001 if n == 0 { 1002 return nil, io.ErrUnexpectedEOF 1003 } 1004 b = b[n:] 1005 if x > uint64(len(b)) { 1006 return nil, io.ErrUnexpectedEOF 1007 } 1008 m := &int32Value{} 1009 if err := Unmarshal(b[:x], m); err != nil { 1010 return nil, err 1011 } 1012 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 1013 s.Set(reflect.ValueOf(&m.Value)) 1014 return b[x:], nil 1015 } 1016} 1017 1018func makeStdInt32ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1019 return func(b []byte, f pointer, w int) ([]byte, error) { 1020 if w != WireBytes { 1021 return nil, errInternalBadWireType 1022 } 1023 x, n := decodeVarint(b) 1024 if n == 0 { 1025 return nil, io.ErrUnexpectedEOF 1026 } 1027 b = b[n:] 1028 if x > uint64(len(b)) { 1029 return nil, io.ErrUnexpectedEOF 1030 } 1031 m := &int32Value{} 1032 if err := Unmarshal(b[:x], m); err != nil { 1033 return nil, err 1034 } 1035 slice := f.getSlice(reflect.PtrTo(sub.typ)) 1036 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 1037 slice.Set(newSlice) 1038 return b[x:], nil 1039 } 1040} 1041 1042func makeStdInt32ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1043 return func(b []byte, f pointer, w int) ([]byte, error) { 1044 if w != WireBytes { 1045 return nil, errInternalBadWireType 1046 } 1047 x, n := decodeVarint(b) 1048 if n == 0 { 1049 return nil, io.ErrUnexpectedEOF 1050 } 1051 b = b[n:] 1052 if x > uint64(len(b)) { 1053 return nil, io.ErrUnexpectedEOF 1054 } 1055 m := &int32Value{} 1056 if err := Unmarshal(b[:x], m); err != nil { 1057 return nil, err 1058 } 1059 slice := f.getSlice(sub.typ) 1060 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 1061 slice.Set(newSlice) 1062 return b[x:], nil 1063 } 1064} 1065 1066func makeStdUInt32ValueMarshaler(u *marshalInfo) (sizer, marshaler) { 1067 return func(ptr pointer, tagsize int) int { 1068 t := ptr.asPointerTo(u.typ).Interface().(*uint32) 1069 v := &uint32Value{*t} 1070 siz := Size(v) 1071 return tagsize + SizeVarint(uint64(siz)) + siz 1072 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1073 t := ptr.asPointerTo(u.typ).Interface().(*uint32) 1074 v := &uint32Value{*t} 1075 buf, err := Marshal(v) 1076 if err != nil { 1077 return nil, err 1078 } 1079 b = appendVarint(b, wiretag) 1080 b = appendVarint(b, uint64(len(buf))) 1081 b = append(b, buf...) 1082 return b, nil 1083 } 1084} 1085 1086func makeStdUInt32ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 1087 return func(ptr pointer, tagsize int) int { 1088 if ptr.isNil() { 1089 return 0 1090 } 1091 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32) 1092 v := &uint32Value{*t} 1093 siz := Size(v) 1094 return tagsize + SizeVarint(uint64(siz)) + siz 1095 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1096 if ptr.isNil() { 1097 return b, nil 1098 } 1099 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32) 1100 v := &uint32Value{*t} 1101 buf, err := Marshal(v) 1102 if err != nil { 1103 return nil, err 1104 } 1105 b = appendVarint(b, wiretag) 1106 b = appendVarint(b, uint64(len(buf))) 1107 b = append(b, buf...) 1108 return b, nil 1109 } 1110} 1111 1112func makeStdUInt32ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1113 return func(ptr pointer, tagsize int) int { 1114 s := ptr.getSlice(u.typ) 1115 n := 0 1116 for i := 0; i < s.Len(); i++ { 1117 elem := s.Index(i) 1118 t := elem.Interface().(uint32) 1119 v := &uint32Value{t} 1120 siz := Size(v) 1121 n += siz + SizeVarint(uint64(siz)) + tagsize 1122 } 1123 return n 1124 }, 1125 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1126 s := ptr.getSlice(u.typ) 1127 for i := 0; i < s.Len(); i++ { 1128 elem := s.Index(i) 1129 t := elem.Interface().(uint32) 1130 v := &uint32Value{t} 1131 siz := Size(v) 1132 buf, err := Marshal(v) 1133 if err != nil { 1134 return nil, err 1135 } 1136 b = appendVarint(b, wiretag) 1137 b = appendVarint(b, uint64(siz)) 1138 b = append(b, buf...) 1139 } 1140 1141 return b, nil 1142 } 1143} 1144 1145func makeStdUInt32ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1146 return func(ptr pointer, tagsize int) int { 1147 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1148 n := 0 1149 for i := 0; i < s.Len(); i++ { 1150 elem := s.Index(i) 1151 t := elem.Interface().(*uint32) 1152 v := &uint32Value{*t} 1153 siz := Size(v) 1154 n += siz + SizeVarint(uint64(siz)) + tagsize 1155 } 1156 return n 1157 }, 1158 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1159 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1160 for i := 0; i < s.Len(); i++ { 1161 elem := s.Index(i) 1162 t := elem.Interface().(*uint32) 1163 v := &uint32Value{*t} 1164 siz := Size(v) 1165 buf, err := Marshal(v) 1166 if err != nil { 1167 return nil, err 1168 } 1169 b = appendVarint(b, wiretag) 1170 b = appendVarint(b, uint64(siz)) 1171 b = append(b, buf...) 1172 } 1173 1174 return b, nil 1175 } 1176} 1177 1178func makeStdUInt32ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1179 return func(b []byte, f pointer, w int) ([]byte, error) { 1180 if w != WireBytes { 1181 return nil, errInternalBadWireType 1182 } 1183 x, n := decodeVarint(b) 1184 if n == 0 { 1185 return nil, io.ErrUnexpectedEOF 1186 } 1187 b = b[n:] 1188 if x > uint64(len(b)) { 1189 return nil, io.ErrUnexpectedEOF 1190 } 1191 m := &uint32Value{} 1192 if err := Unmarshal(b[:x], m); err != nil { 1193 return nil, err 1194 } 1195 s := f.asPointerTo(sub.typ).Elem() 1196 s.Set(reflect.ValueOf(m.Value)) 1197 return b[x:], nil 1198 } 1199} 1200 1201func makeStdUInt32ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1202 return func(b []byte, f pointer, w int) ([]byte, error) { 1203 if w != WireBytes { 1204 return nil, errInternalBadWireType 1205 } 1206 x, n := decodeVarint(b) 1207 if n == 0 { 1208 return nil, io.ErrUnexpectedEOF 1209 } 1210 b = b[n:] 1211 if x > uint64(len(b)) { 1212 return nil, io.ErrUnexpectedEOF 1213 } 1214 m := &uint32Value{} 1215 if err := Unmarshal(b[:x], m); err != nil { 1216 return nil, err 1217 } 1218 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 1219 s.Set(reflect.ValueOf(&m.Value)) 1220 return b[x:], nil 1221 } 1222} 1223 1224func makeStdUInt32ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1225 return func(b []byte, f pointer, w int) ([]byte, error) { 1226 if w != WireBytes { 1227 return nil, errInternalBadWireType 1228 } 1229 x, n := decodeVarint(b) 1230 if n == 0 { 1231 return nil, io.ErrUnexpectedEOF 1232 } 1233 b = b[n:] 1234 if x > uint64(len(b)) { 1235 return nil, io.ErrUnexpectedEOF 1236 } 1237 m := &uint32Value{} 1238 if err := Unmarshal(b[:x], m); err != nil { 1239 return nil, err 1240 } 1241 slice := f.getSlice(reflect.PtrTo(sub.typ)) 1242 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 1243 slice.Set(newSlice) 1244 return b[x:], nil 1245 } 1246} 1247 1248func makeStdUInt32ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1249 return func(b []byte, f pointer, w int) ([]byte, error) { 1250 if w != WireBytes { 1251 return nil, errInternalBadWireType 1252 } 1253 x, n := decodeVarint(b) 1254 if n == 0 { 1255 return nil, io.ErrUnexpectedEOF 1256 } 1257 b = b[n:] 1258 if x > uint64(len(b)) { 1259 return nil, io.ErrUnexpectedEOF 1260 } 1261 m := &uint32Value{} 1262 if err := Unmarshal(b[:x], m); err != nil { 1263 return nil, err 1264 } 1265 slice := f.getSlice(sub.typ) 1266 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 1267 slice.Set(newSlice) 1268 return b[x:], nil 1269 } 1270} 1271 1272func makeStdBoolValueMarshaler(u *marshalInfo) (sizer, marshaler) { 1273 return func(ptr pointer, tagsize int) int { 1274 t := ptr.asPointerTo(u.typ).Interface().(*bool) 1275 v := &boolValue{*t} 1276 siz := Size(v) 1277 return tagsize + SizeVarint(uint64(siz)) + siz 1278 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1279 t := ptr.asPointerTo(u.typ).Interface().(*bool) 1280 v := &boolValue{*t} 1281 buf, err := Marshal(v) 1282 if err != nil { 1283 return nil, err 1284 } 1285 b = appendVarint(b, wiretag) 1286 b = appendVarint(b, uint64(len(buf))) 1287 b = append(b, buf...) 1288 return b, nil 1289 } 1290} 1291 1292func makeStdBoolValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 1293 return func(ptr pointer, tagsize int) int { 1294 if ptr.isNil() { 1295 return 0 1296 } 1297 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool) 1298 v := &boolValue{*t} 1299 siz := Size(v) 1300 return tagsize + SizeVarint(uint64(siz)) + siz 1301 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1302 if ptr.isNil() { 1303 return b, nil 1304 } 1305 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool) 1306 v := &boolValue{*t} 1307 buf, err := Marshal(v) 1308 if err != nil { 1309 return nil, err 1310 } 1311 b = appendVarint(b, wiretag) 1312 b = appendVarint(b, uint64(len(buf))) 1313 b = append(b, buf...) 1314 return b, nil 1315 } 1316} 1317 1318func makeStdBoolValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1319 return func(ptr pointer, tagsize int) int { 1320 s := ptr.getSlice(u.typ) 1321 n := 0 1322 for i := 0; i < s.Len(); i++ { 1323 elem := s.Index(i) 1324 t := elem.Interface().(bool) 1325 v := &boolValue{t} 1326 siz := Size(v) 1327 n += siz + SizeVarint(uint64(siz)) + tagsize 1328 } 1329 return n 1330 }, 1331 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1332 s := ptr.getSlice(u.typ) 1333 for i := 0; i < s.Len(); i++ { 1334 elem := s.Index(i) 1335 t := elem.Interface().(bool) 1336 v := &boolValue{t} 1337 siz := Size(v) 1338 buf, err := Marshal(v) 1339 if err != nil { 1340 return nil, err 1341 } 1342 b = appendVarint(b, wiretag) 1343 b = appendVarint(b, uint64(siz)) 1344 b = append(b, buf...) 1345 } 1346 1347 return b, nil 1348 } 1349} 1350 1351func makeStdBoolValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1352 return func(ptr pointer, tagsize int) int { 1353 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1354 n := 0 1355 for i := 0; i < s.Len(); i++ { 1356 elem := s.Index(i) 1357 t := elem.Interface().(*bool) 1358 v := &boolValue{*t} 1359 siz := Size(v) 1360 n += siz + SizeVarint(uint64(siz)) + tagsize 1361 } 1362 return n 1363 }, 1364 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1365 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1366 for i := 0; i < s.Len(); i++ { 1367 elem := s.Index(i) 1368 t := elem.Interface().(*bool) 1369 v := &boolValue{*t} 1370 siz := Size(v) 1371 buf, err := Marshal(v) 1372 if err != nil { 1373 return nil, err 1374 } 1375 b = appendVarint(b, wiretag) 1376 b = appendVarint(b, uint64(siz)) 1377 b = append(b, buf...) 1378 } 1379 1380 return b, nil 1381 } 1382} 1383 1384func makeStdBoolValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1385 return func(b []byte, f pointer, w int) ([]byte, error) { 1386 if w != WireBytes { 1387 return nil, errInternalBadWireType 1388 } 1389 x, n := decodeVarint(b) 1390 if n == 0 { 1391 return nil, io.ErrUnexpectedEOF 1392 } 1393 b = b[n:] 1394 if x > uint64(len(b)) { 1395 return nil, io.ErrUnexpectedEOF 1396 } 1397 m := &boolValue{} 1398 if err := Unmarshal(b[:x], m); err != nil { 1399 return nil, err 1400 } 1401 s := f.asPointerTo(sub.typ).Elem() 1402 s.Set(reflect.ValueOf(m.Value)) 1403 return b[x:], nil 1404 } 1405} 1406 1407func makeStdBoolValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1408 return func(b []byte, f pointer, w int) ([]byte, error) { 1409 if w != WireBytes { 1410 return nil, errInternalBadWireType 1411 } 1412 x, n := decodeVarint(b) 1413 if n == 0 { 1414 return nil, io.ErrUnexpectedEOF 1415 } 1416 b = b[n:] 1417 if x > uint64(len(b)) { 1418 return nil, io.ErrUnexpectedEOF 1419 } 1420 m := &boolValue{} 1421 if err := Unmarshal(b[:x], m); err != nil { 1422 return nil, err 1423 } 1424 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 1425 s.Set(reflect.ValueOf(&m.Value)) 1426 return b[x:], nil 1427 } 1428} 1429 1430func makeStdBoolValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1431 return func(b []byte, f pointer, w int) ([]byte, error) { 1432 if w != WireBytes { 1433 return nil, errInternalBadWireType 1434 } 1435 x, n := decodeVarint(b) 1436 if n == 0 { 1437 return nil, io.ErrUnexpectedEOF 1438 } 1439 b = b[n:] 1440 if x > uint64(len(b)) { 1441 return nil, io.ErrUnexpectedEOF 1442 } 1443 m := &boolValue{} 1444 if err := Unmarshal(b[:x], m); err != nil { 1445 return nil, err 1446 } 1447 slice := f.getSlice(reflect.PtrTo(sub.typ)) 1448 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 1449 slice.Set(newSlice) 1450 return b[x:], nil 1451 } 1452} 1453 1454func makeStdBoolValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1455 return func(b []byte, f pointer, w int) ([]byte, error) { 1456 if w != WireBytes { 1457 return nil, errInternalBadWireType 1458 } 1459 x, n := decodeVarint(b) 1460 if n == 0 { 1461 return nil, io.ErrUnexpectedEOF 1462 } 1463 b = b[n:] 1464 if x > uint64(len(b)) { 1465 return nil, io.ErrUnexpectedEOF 1466 } 1467 m := &boolValue{} 1468 if err := Unmarshal(b[:x], m); err != nil { 1469 return nil, err 1470 } 1471 slice := f.getSlice(sub.typ) 1472 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 1473 slice.Set(newSlice) 1474 return b[x:], nil 1475 } 1476} 1477 1478func makeStdStringValueMarshaler(u *marshalInfo) (sizer, marshaler) { 1479 return func(ptr pointer, tagsize int) int { 1480 t := ptr.asPointerTo(u.typ).Interface().(*string) 1481 v := &stringValue{*t} 1482 siz := Size(v) 1483 return tagsize + SizeVarint(uint64(siz)) + siz 1484 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1485 t := ptr.asPointerTo(u.typ).Interface().(*string) 1486 v := &stringValue{*t} 1487 buf, err := Marshal(v) 1488 if err != nil { 1489 return nil, err 1490 } 1491 b = appendVarint(b, wiretag) 1492 b = appendVarint(b, uint64(len(buf))) 1493 b = append(b, buf...) 1494 return b, nil 1495 } 1496} 1497 1498func makeStdStringValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 1499 return func(ptr pointer, tagsize int) int { 1500 if ptr.isNil() { 1501 return 0 1502 } 1503 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string) 1504 v := &stringValue{*t} 1505 siz := Size(v) 1506 return tagsize + SizeVarint(uint64(siz)) + siz 1507 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1508 if ptr.isNil() { 1509 return b, nil 1510 } 1511 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string) 1512 v := &stringValue{*t} 1513 buf, err := Marshal(v) 1514 if err != nil { 1515 return nil, err 1516 } 1517 b = appendVarint(b, wiretag) 1518 b = appendVarint(b, uint64(len(buf))) 1519 b = append(b, buf...) 1520 return b, nil 1521 } 1522} 1523 1524func makeStdStringValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1525 return func(ptr pointer, tagsize int) int { 1526 s := ptr.getSlice(u.typ) 1527 n := 0 1528 for i := 0; i < s.Len(); i++ { 1529 elem := s.Index(i) 1530 t := elem.Interface().(string) 1531 v := &stringValue{t} 1532 siz := Size(v) 1533 n += siz + SizeVarint(uint64(siz)) + tagsize 1534 } 1535 return n 1536 }, 1537 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1538 s := ptr.getSlice(u.typ) 1539 for i := 0; i < s.Len(); i++ { 1540 elem := s.Index(i) 1541 t := elem.Interface().(string) 1542 v := &stringValue{t} 1543 siz := Size(v) 1544 buf, err := Marshal(v) 1545 if err != nil { 1546 return nil, err 1547 } 1548 b = appendVarint(b, wiretag) 1549 b = appendVarint(b, uint64(siz)) 1550 b = append(b, buf...) 1551 } 1552 1553 return b, nil 1554 } 1555} 1556 1557func makeStdStringValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1558 return func(ptr pointer, tagsize int) int { 1559 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1560 n := 0 1561 for i := 0; i < s.Len(); i++ { 1562 elem := s.Index(i) 1563 t := elem.Interface().(*string) 1564 v := &stringValue{*t} 1565 siz := Size(v) 1566 n += siz + SizeVarint(uint64(siz)) + tagsize 1567 } 1568 return n 1569 }, 1570 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1571 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1572 for i := 0; i < s.Len(); i++ { 1573 elem := s.Index(i) 1574 t := elem.Interface().(*string) 1575 v := &stringValue{*t} 1576 siz := Size(v) 1577 buf, err := Marshal(v) 1578 if err != nil { 1579 return nil, err 1580 } 1581 b = appendVarint(b, wiretag) 1582 b = appendVarint(b, uint64(siz)) 1583 b = append(b, buf...) 1584 } 1585 1586 return b, nil 1587 } 1588} 1589 1590func makeStdStringValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1591 return func(b []byte, f pointer, w int) ([]byte, error) { 1592 if w != WireBytes { 1593 return nil, errInternalBadWireType 1594 } 1595 x, n := decodeVarint(b) 1596 if n == 0 { 1597 return nil, io.ErrUnexpectedEOF 1598 } 1599 b = b[n:] 1600 if x > uint64(len(b)) { 1601 return nil, io.ErrUnexpectedEOF 1602 } 1603 m := &stringValue{} 1604 if err := Unmarshal(b[:x], m); err != nil { 1605 return nil, err 1606 } 1607 s := f.asPointerTo(sub.typ).Elem() 1608 s.Set(reflect.ValueOf(m.Value)) 1609 return b[x:], nil 1610 } 1611} 1612 1613func makeStdStringValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1614 return func(b []byte, f pointer, w int) ([]byte, error) { 1615 if w != WireBytes { 1616 return nil, errInternalBadWireType 1617 } 1618 x, n := decodeVarint(b) 1619 if n == 0 { 1620 return nil, io.ErrUnexpectedEOF 1621 } 1622 b = b[n:] 1623 if x > uint64(len(b)) { 1624 return nil, io.ErrUnexpectedEOF 1625 } 1626 m := &stringValue{} 1627 if err := Unmarshal(b[:x], m); err != nil { 1628 return nil, err 1629 } 1630 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 1631 s.Set(reflect.ValueOf(&m.Value)) 1632 return b[x:], nil 1633 } 1634} 1635 1636func makeStdStringValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1637 return func(b []byte, f pointer, w int) ([]byte, error) { 1638 if w != WireBytes { 1639 return nil, errInternalBadWireType 1640 } 1641 x, n := decodeVarint(b) 1642 if n == 0 { 1643 return nil, io.ErrUnexpectedEOF 1644 } 1645 b = b[n:] 1646 if x > uint64(len(b)) { 1647 return nil, io.ErrUnexpectedEOF 1648 } 1649 m := &stringValue{} 1650 if err := Unmarshal(b[:x], m); err != nil { 1651 return nil, err 1652 } 1653 slice := f.getSlice(reflect.PtrTo(sub.typ)) 1654 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 1655 slice.Set(newSlice) 1656 return b[x:], nil 1657 } 1658} 1659 1660func makeStdStringValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1661 return func(b []byte, f pointer, w int) ([]byte, error) { 1662 if w != WireBytes { 1663 return nil, errInternalBadWireType 1664 } 1665 x, n := decodeVarint(b) 1666 if n == 0 { 1667 return nil, io.ErrUnexpectedEOF 1668 } 1669 b = b[n:] 1670 if x > uint64(len(b)) { 1671 return nil, io.ErrUnexpectedEOF 1672 } 1673 m := &stringValue{} 1674 if err := Unmarshal(b[:x], m); err != nil { 1675 return nil, err 1676 } 1677 slice := f.getSlice(sub.typ) 1678 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 1679 slice.Set(newSlice) 1680 return b[x:], nil 1681 } 1682} 1683 1684func makeStdBytesValueMarshaler(u *marshalInfo) (sizer, marshaler) { 1685 return func(ptr pointer, tagsize int) int { 1686 t := ptr.asPointerTo(u.typ).Interface().(*[]byte) 1687 v := &bytesValue{*t} 1688 siz := Size(v) 1689 return tagsize + SizeVarint(uint64(siz)) + siz 1690 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1691 t := ptr.asPointerTo(u.typ).Interface().(*[]byte) 1692 v := &bytesValue{*t} 1693 buf, err := Marshal(v) 1694 if err != nil { 1695 return nil, err 1696 } 1697 b = appendVarint(b, wiretag) 1698 b = appendVarint(b, uint64(len(buf))) 1699 b = append(b, buf...) 1700 return b, nil 1701 } 1702} 1703 1704func makeStdBytesValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) { 1705 return func(ptr pointer, tagsize int) int { 1706 if ptr.isNil() { 1707 return 0 1708 } 1709 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte) 1710 v := &bytesValue{*t} 1711 siz := Size(v) 1712 return tagsize + SizeVarint(uint64(siz)) + siz 1713 }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1714 if ptr.isNil() { 1715 return b, nil 1716 } 1717 t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte) 1718 v := &bytesValue{*t} 1719 buf, err := Marshal(v) 1720 if err != nil { 1721 return nil, err 1722 } 1723 b = appendVarint(b, wiretag) 1724 b = appendVarint(b, uint64(len(buf))) 1725 b = append(b, buf...) 1726 return b, nil 1727 } 1728} 1729 1730func makeStdBytesValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1731 return func(ptr pointer, tagsize int) int { 1732 s := ptr.getSlice(u.typ) 1733 n := 0 1734 for i := 0; i < s.Len(); i++ { 1735 elem := s.Index(i) 1736 t := elem.Interface().([]byte) 1737 v := &bytesValue{t} 1738 siz := Size(v) 1739 n += siz + SizeVarint(uint64(siz)) + tagsize 1740 } 1741 return n 1742 }, 1743 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1744 s := ptr.getSlice(u.typ) 1745 for i := 0; i < s.Len(); i++ { 1746 elem := s.Index(i) 1747 t := elem.Interface().([]byte) 1748 v := &bytesValue{t} 1749 siz := Size(v) 1750 buf, err := Marshal(v) 1751 if err != nil { 1752 return nil, err 1753 } 1754 b = appendVarint(b, wiretag) 1755 b = appendVarint(b, uint64(siz)) 1756 b = append(b, buf...) 1757 } 1758 1759 return b, nil 1760 } 1761} 1762 1763func makeStdBytesValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { 1764 return func(ptr pointer, tagsize int) int { 1765 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1766 n := 0 1767 for i := 0; i < s.Len(); i++ { 1768 elem := s.Index(i) 1769 t := elem.Interface().(*[]byte) 1770 v := &bytesValue{*t} 1771 siz := Size(v) 1772 n += siz + SizeVarint(uint64(siz)) + tagsize 1773 } 1774 return n 1775 }, 1776 func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { 1777 s := ptr.getSlice(reflect.PtrTo(u.typ)) 1778 for i := 0; i < s.Len(); i++ { 1779 elem := s.Index(i) 1780 t := elem.Interface().(*[]byte) 1781 v := &bytesValue{*t} 1782 siz := Size(v) 1783 buf, err := Marshal(v) 1784 if err != nil { 1785 return nil, err 1786 } 1787 b = appendVarint(b, wiretag) 1788 b = appendVarint(b, uint64(siz)) 1789 b = append(b, buf...) 1790 } 1791 1792 return b, nil 1793 } 1794} 1795 1796func makeStdBytesValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1797 return func(b []byte, f pointer, w int) ([]byte, error) { 1798 if w != WireBytes { 1799 return nil, errInternalBadWireType 1800 } 1801 x, n := decodeVarint(b) 1802 if n == 0 { 1803 return nil, io.ErrUnexpectedEOF 1804 } 1805 b = b[n:] 1806 if x > uint64(len(b)) { 1807 return nil, io.ErrUnexpectedEOF 1808 } 1809 m := &bytesValue{} 1810 if err := Unmarshal(b[:x], m); err != nil { 1811 return nil, err 1812 } 1813 s := f.asPointerTo(sub.typ).Elem() 1814 s.Set(reflect.ValueOf(m.Value)) 1815 return b[x:], nil 1816 } 1817} 1818 1819func makeStdBytesValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1820 return func(b []byte, f pointer, w int) ([]byte, error) { 1821 if w != WireBytes { 1822 return nil, errInternalBadWireType 1823 } 1824 x, n := decodeVarint(b) 1825 if n == 0 { 1826 return nil, io.ErrUnexpectedEOF 1827 } 1828 b = b[n:] 1829 if x > uint64(len(b)) { 1830 return nil, io.ErrUnexpectedEOF 1831 } 1832 m := &bytesValue{} 1833 if err := Unmarshal(b[:x], m); err != nil { 1834 return nil, err 1835 } 1836 s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() 1837 s.Set(reflect.ValueOf(&m.Value)) 1838 return b[x:], nil 1839 } 1840} 1841 1842func makeStdBytesValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1843 return func(b []byte, f pointer, w int) ([]byte, error) { 1844 if w != WireBytes { 1845 return nil, errInternalBadWireType 1846 } 1847 x, n := decodeVarint(b) 1848 if n == 0 { 1849 return nil, io.ErrUnexpectedEOF 1850 } 1851 b = b[n:] 1852 if x > uint64(len(b)) { 1853 return nil, io.ErrUnexpectedEOF 1854 } 1855 m := &bytesValue{} 1856 if err := Unmarshal(b[:x], m); err != nil { 1857 return nil, err 1858 } 1859 slice := f.getSlice(reflect.PtrTo(sub.typ)) 1860 newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) 1861 slice.Set(newSlice) 1862 return b[x:], nil 1863 } 1864} 1865 1866func makeStdBytesValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler { 1867 return func(b []byte, f pointer, w int) ([]byte, error) { 1868 if w != WireBytes { 1869 return nil, errInternalBadWireType 1870 } 1871 x, n := decodeVarint(b) 1872 if n == 0 { 1873 return nil, io.ErrUnexpectedEOF 1874 } 1875 b = b[n:] 1876 if x > uint64(len(b)) { 1877 return nil, io.ErrUnexpectedEOF 1878 } 1879 m := &bytesValue{} 1880 if err := Unmarshal(b[:x], m); err != nil { 1881 return nil, err 1882 } 1883 slice := f.getSlice(sub.typ) 1884 newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) 1885 slice.Set(newSlice) 1886 return b[x:], nil 1887 } 1888} 1889