53
func (a *InternalMessageInfo) Unmarshal(msg Message, b []byte) error {
56
u := atomicLoadUnmarshalInfo(&a.unmarshal)
59
u = getUnmarshalInfo(reflect.TypeOf(msg).Elem())
60
atomicStoreUnmarshalInfo(&a.unmarshal, u)
63
err := u.unmarshal(toPointer(&msg), b)
67
type unmarshalInfo struct {
74
dense []unmarshalFieldInfo
75
sparse map[uint64]unmarshalFieldInfo
81
extensionRanges []ExtensionRange
91
type unmarshaler func(b []byte, f pointer, w int) ([]byte, error)
93
type unmarshalFieldInfo struct {
107
unmarshalInfoMap = map[reflect.Type]*unmarshalInfo{}
108
unmarshalInfoLock sync.Mutex
114
func getUnmarshalInfo(t reflect.Type) *unmarshalInfo {
119
unmarshalInfoLock.Lock()
120
defer unmarshalInfoLock.Unlock()
121
u := unmarshalInfoMap[t]
123
u = &unmarshalInfo{typ: t}
126
unmarshalInfoMap[t] = u
136
func (u *unmarshalInfo) unmarshal(m pointer, b []byte) error {
137
if atomic.LoadInt32(&u.initialized) == 0 {
138
u.computeUnmarshalInfo()
141
return unmarshalMessageSet(b, m.offset(u.extensions).toExtensions())
152
} else if len(b) >= 2 && b[1] < 128 {
153
x = uint64(b[0]&0x7f) + uint64(b[1])<<7
157
x, n = decodeVarint(b)
159
return io.ErrUnexpectedEOF
167
var f unmarshalFieldInfo
168
if tag < uint64(len(u.dense)) {
173
if fn := f.unmarshal; fn != nil {
175
b, err = fn(b, m.offset(f.field), wire)
180
if r, ok := err.(*RequiredNotSetError); ok {
189
if err != errInternalBadWireType {
190
if err == errInvalidUTF8 {
192
fullName := revProtoTypes[reflect.PtrTo(u.typ)] + "." + f.name
193
errLater = &invalidUTF8Error{fullName}
203
if !u.unrecognized.IsValid() {
206
b, err = skipField(b, wire)
214
z := m.offset(u.unrecognized).toBytes()
215
var emap map[int32]Extension
217
for _, r := range u.extensionRanges {
218
if uint64(r.Start) <= tag && tag <= uint64(r.End) {
219
if u.extensions.IsValid() {
220
mp := m.offset(u.extensions).toExtensions()
221
emap = mp.extensionsWrite()
226
if u.oldExtensions.IsValid() {
227
p := m.offset(u.oldExtensions).toOldExtensions()
230
emap = map[int32]Extension{}
237
if u.bytesExtensions.IsValid() {
238
z = m.offset(u.bytesExtensions).toBytes()
241
panic("no extensions field available")
247
b, err = skipField(b, wire)
251
*z = encodeVarint(*z, tag<<3|uint64(wire))
252
*z = append(*z, b0[:len(b0)-len(b)]...)
258
if reqMask != u.reqMask && errLater == nil {
260
for _, n := range u.reqFields {
262
errLater = &RequiredNotSetError{n}
272
func (u *unmarshalInfo) computeUnmarshalInfo() {
274
defer u.lock.Unlock()
275
if u.initialized != 0 {
283
u.unrecognized = invalidField
284
u.extensions = invalidField
285
u.oldExtensions = invalidField
286
u.bytesExtensions = invalidField
289
type oneofField struct {
293
var oneofFields []oneofField
295
for i := 0; i < n; i++ {
297
if f.Name == "XXX_unrecognized" {
299
if f.Type != reflect.TypeOf(([]byte)(nil)) {
300
panic("bad type for XXX_unrecognized field: " + f.Type.Name())
302
u.unrecognized = toField(&f)
305
if f.Name == "XXX_InternalExtensions" {
307
if f.Type != reflect.TypeOf(XXX_InternalExtensions{}) {
308
panic("bad type for XXX_InternalExtensions field: " + f.Type.Name())
310
u.extensions = toField(&f)
311
if f.Tag.Get("protobuf_messageset") == "1" {
312
u.isMessageSet = true
316
if f.Name == "XXX_extensions" {
318
if f.Type == reflect.TypeOf((map[int32]Extension)(nil)) {
319
u.oldExtensions = toField(&f)
321
} else if f.Type == reflect.TypeOf(([]byte)(nil)) {
322
u.bytesExtensions = toField(&f)
325
panic("bad type for XXX_extensions field: " + f.Type.Name())
327
if f.Name == "XXX_NoUnkeyedLiteral" || f.Name == "XXX_sizecache" {
331
oneof := f.Tag.Get("protobuf_oneof")
333
oneofFields = append(oneofFields, oneofField{f.Type, toField(&f)})
338
tags := f.Tag.Get("protobuf")
339
tagArray := strings.Split(tags, ",")
340
if len(tagArray) < 2 {
341
panic("protobuf tag not enough fields in " + t.Name() + "." + f.Name + ": " + tags)
343
tag, err := strconv.Atoi(tagArray[1])
345
panic("protobuf tag field not an integer: " + tagArray[1])
349
for _, tag := range tagArray[3:] {
350
if strings.HasPrefix(tag, "name=") {
356
unmarshal := fieldUnmarshaler(&f)
360
if tagArray[2] == "req" {
361
bit := len(u.reqFields)
362
u.reqFields = append(u.reqFields, name)
363
reqMask = uint64(1) << uint(bit)
370
u.setTag(tag, toField(&f), unmarshal, reqMask, name)
375
if len(oneofFields) > 0 {
376
var oneofImplementers []interface{}
377
switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) {
378
case oneofFuncsIface:
379
_, _, _, oneofImplementers = m.XXX_OneofFuncs()
380
case oneofWrappersIface:
381
oneofImplementers = m.XXX_OneofWrappers()
383
for _, v := range oneofImplementers {
384
tptr := reflect.TypeOf(v)
388
baseUnmarshal := fieldUnmarshaler(&f)
389
tags := strings.Split(f.Tag.Get("protobuf"), ",")
390
fieldNum, err := strconv.Atoi(tags[1])
392
panic("protobuf tag field not an integer: " + tags[1])
395
for _, tag := range tags {
396
if strings.HasPrefix(tag, "name=") {
397
name = strings.TrimPrefix(tag, "name=")
404
for _, of := range oneofFields {
405
if tptr.Implements(of.ityp) {
409
unmarshal := makeUnmarshalOneof(typ, of.ityp, baseUnmarshal)
410
u.setTag(fieldNum, of.field, unmarshal, 0, name)
418
fn := reflect.Zero(reflect.PtrTo(t)).MethodByName("ExtensionRangeArray")
420
if !u.extensions.IsValid() && !u.oldExtensions.IsValid() && !u.bytesExtensions.IsValid() {
421
panic("a message with extensions, but no extensions field in " + t.Name())
423
u.extensionRanges = fn.Call(nil)[0].Interface().([]ExtensionRange)
430
u.setTag(0, zeroField, func(b []byte, f pointer, w int) ([]byte, error) {
431
return nil, fmt.Errorf("proto: %s: illegal tag 0 (wire type %d)", t, w)
435
u.reqMask = uint64(1)<<uint(len(u.reqFields)) - 1
437
atomic.StoreInt32(&u.initialized, 1)
445
func (u *unmarshalInfo) setTag(tag int, field field, unmarshal unmarshaler, reqMask uint64, name string) {
446
i := unmarshalFieldInfo{field: field, unmarshal: unmarshal, reqMask: reqMask, name: name}
447
n := u.typ.NumField()
448
if tag >= 0 && (tag < 16 || tag < 2*n) {
449
for len(u.dense) <= tag {
450
u.dense = append(u.dense, unmarshalFieldInfo{})
456
u.sparse = map[uint64]unmarshalFieldInfo{}
458
u.sparse[uint64(tag)] = i
462
func fieldUnmarshaler(f *reflect.StructField) unmarshaler {
463
if f.Type.Kind() == reflect.Map {
464
return makeUnmarshalMap(f)
466
return typeUnmarshaler(f.Type, f.Tag.Get("protobuf"))
470
func typeUnmarshaler(t reflect.Type, tags string) unmarshaler {
471
tagArray := strings.Split(tags, ",")
472
encoding := tagArray[0]
477
isWktPointer := false
480
for _, tag := range tagArray[3:] {
481
if strings.HasPrefix(tag, "name=") {
487
if strings.HasPrefix(tag, "customtype=") {
490
if tag == "stdtime" {
493
if tag == "stdduration" {
500
validateUTF8 = validateUTF8 && proto3
505
if t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 {
509
if t.Kind() == reflect.Ptr {
515
if reflect.PtrTo(t).Implements(customType) {
517
return makeUnmarshalCustomSlice(getUnmarshalInfo(t), name)
520
return makeUnmarshalCustomPtr(getUnmarshalInfo(t), name)
522
return makeUnmarshalCustom(getUnmarshalInfo(t), name)
524
panic(fmt.Sprintf("custom type: type: %v, does not implement the proto.custom interface", t))
531
return makeUnmarshalTimePtrSlice(getUnmarshalInfo(t), name)
533
return makeUnmarshalTimePtr(getUnmarshalInfo(t), name)
536
return makeUnmarshalTimeSlice(getUnmarshalInfo(t), name)
538
return makeUnmarshalTime(getUnmarshalInfo(t), name)
544
return makeUnmarshalDurationPtrSlice(getUnmarshalInfo(t), name)
546
return makeUnmarshalDurationPtr(getUnmarshalInfo(t), name)
549
return makeUnmarshalDurationSlice(getUnmarshalInfo(t), name)
551
return makeUnmarshalDuration(getUnmarshalInfo(t), name)
556
case reflect.Float64:
559
return makeStdDoubleValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
561
return makeStdDoubleValuePtrUnmarshaler(getUnmarshalInfo(t), name)
564
return makeStdDoubleValueSliceUnmarshaler(getUnmarshalInfo(t), name)
566
return makeStdDoubleValueUnmarshaler(getUnmarshalInfo(t), name)
567
case reflect.Float32:
570
return makeStdFloatValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
572
return makeStdFloatValuePtrUnmarshaler(getUnmarshalInfo(t), name)
575
return makeStdFloatValueSliceUnmarshaler(getUnmarshalInfo(t), name)
577
return makeStdFloatValueUnmarshaler(getUnmarshalInfo(t), name)
581
return makeStdInt64ValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
583
return makeStdInt64ValuePtrUnmarshaler(getUnmarshalInfo(t), name)
586
return makeStdInt64ValueSliceUnmarshaler(getUnmarshalInfo(t), name)
588
return makeStdInt64ValueUnmarshaler(getUnmarshalInfo(t), name)
592
return makeStdUInt64ValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
594
return makeStdUInt64ValuePtrUnmarshaler(getUnmarshalInfo(t), name)
597
return makeStdUInt64ValueSliceUnmarshaler(getUnmarshalInfo(t), name)
599
return makeStdUInt64ValueUnmarshaler(getUnmarshalInfo(t), name)
603
return makeStdInt32ValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
605
return makeStdInt32ValuePtrUnmarshaler(getUnmarshalInfo(t), name)
608
return makeStdInt32ValueSliceUnmarshaler(getUnmarshalInfo(t), name)
610
return makeStdInt32ValueUnmarshaler(getUnmarshalInfo(t), name)
614
return makeStdUInt32ValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
616
return makeStdUInt32ValuePtrUnmarshaler(getUnmarshalInfo(t), name)
619
return makeStdUInt32ValueSliceUnmarshaler(getUnmarshalInfo(t), name)
621
return makeStdUInt32ValueUnmarshaler(getUnmarshalInfo(t), name)
625
return makeStdBoolValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
627
return makeStdBoolValuePtrUnmarshaler(getUnmarshalInfo(t), name)
630
return makeStdBoolValueSliceUnmarshaler(getUnmarshalInfo(t), name)
632
return makeStdBoolValueUnmarshaler(getUnmarshalInfo(t), name)
636
return makeStdStringValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
638
return makeStdStringValuePtrUnmarshaler(getUnmarshalInfo(t), name)
641
return makeStdStringValueSliceUnmarshaler(getUnmarshalInfo(t), name)
643
return makeStdStringValueUnmarshaler(getUnmarshalInfo(t), name)
647
return makeStdBytesValuePtrSliceUnmarshaler(getUnmarshalInfo(t), name)
649
return makeStdBytesValuePtrUnmarshaler(getUnmarshalInfo(t), name)
652
return makeStdBytesValueSliceUnmarshaler(getUnmarshalInfo(t), name)
654
return makeStdBytesValueUnmarshaler(getUnmarshalInfo(t), name)
656
panic(fmt.Sprintf("unknown wktpointer type %#v", t))
661
if pointer && slice && t.Kind() != reflect.Struct {
662
panic("both pointer and slice for basic type in " + t.Name())
668
return unmarshalBoolPtr
671
return unmarshalBoolSlice
673
return unmarshalBoolValue
678
return unmarshalFixedS32Ptr
681
return unmarshalFixedS32Slice
683
return unmarshalFixedS32Value
687
return unmarshalInt32Ptr
690
return unmarshalInt32Slice
692
return unmarshalInt32Value
695
return unmarshalSint32Ptr
698
return unmarshalSint32Slice
700
return unmarshalSint32Value
706
return unmarshalFixedS64Ptr
709
return unmarshalFixedS64Slice
711
return unmarshalFixedS64Value
714
return unmarshalInt64Ptr
717
return unmarshalInt64Slice
719
return unmarshalInt64Value
722
return unmarshalSint64Ptr
725
return unmarshalSint64Slice
727
return unmarshalSint64Value
733
return unmarshalFixed32Ptr
736
return unmarshalFixed32Slice
738
return unmarshalFixed32Value
741
return unmarshalUint32Ptr
744
return unmarshalUint32Slice
746
return unmarshalUint32Value
752
return unmarshalFixed64Ptr
755
return unmarshalFixed64Slice
757
return unmarshalFixed64Value
760
return unmarshalUint64Ptr
763
return unmarshalUint64Slice
765
return unmarshalUint64Value
767
case reflect.Float32:
769
return unmarshalFloat32Ptr
772
return unmarshalFloat32Slice
774
return unmarshalFloat32Value
775
case reflect.Float64:
777
return unmarshalFloat64Ptr
780
return unmarshalFloat64Slice
782
return unmarshalFloat64Value
784
panic("map type in typeUnmarshaler in " + t.Name())
787
panic("bad pointer in slice case in " + t.Name())
790
return unmarshalBytesSlice
792
return unmarshalBytesValue
796
return unmarshalUTF8StringPtr
799
return unmarshalUTF8StringSlice
801
return unmarshalUTF8StringValue
804
return unmarshalStringPtr
807
return unmarshalStringSlice
809
return unmarshalStringValue
816
return makeUnmarshalMessageSlice(getUnmarshalInfo(t), name)
818
return makeUnmarshalMessage(getUnmarshalInfo(t), name)
824
return makeUnmarshalMessageSlicePtr(getUnmarshalInfo(t), name)
826
return makeUnmarshalMessagePtr(getUnmarshalInfo(t), name)
829
return makeUnmarshalGroupSlicePtr(getUnmarshalInfo(t), name)
831
return makeUnmarshalGroupPtr(getUnmarshalInfo(t), name)
834
panic(fmt.Sprintf("unmarshaler not found type:%s encoding:%s", t, encoding))
839
func unmarshalInt64Value(b []byte, f pointer, w int) ([]byte, error) {
841
return b, errInternalBadWireType
843
x, n := decodeVarint(b)
845
return nil, io.ErrUnexpectedEOF
853
func unmarshalInt64Ptr(b []byte, f pointer, w int) ([]byte, error) {
855
return b, errInternalBadWireType
857
x, n := decodeVarint(b)
859
return nil, io.ErrUnexpectedEOF
867
func unmarshalInt64Slice(b []byte, f pointer, w int) ([]byte, error) {
869
x, n := decodeVarint(b)
871
return nil, io.ErrUnexpectedEOF
874
if x > uint64(len(b)) {
875
return nil, io.ErrUnexpectedEOF
880
x, n = decodeVarint(b)
882
return nil, io.ErrUnexpectedEOF
886
s := f.toInt64Slice()
892
return b, errInternalBadWireType
894
x, n := decodeVarint(b)
896
return nil, io.ErrUnexpectedEOF
900
s := f.toInt64Slice()
905
func unmarshalSint64Value(b []byte, f pointer, w int) ([]byte, error) {
907
return b, errInternalBadWireType
909
x, n := decodeVarint(b)
911
return nil, io.ErrUnexpectedEOF
914
v := int64(x>>1) ^ int64(x)<<63>>63
919
func unmarshalSint64Ptr(b []byte, f pointer, w int) ([]byte, error) {
921
return b, errInternalBadWireType
923
x, n := decodeVarint(b)
925
return nil, io.ErrUnexpectedEOF
928
v := int64(x>>1) ^ int64(x)<<63>>63
933
func unmarshalSint64Slice(b []byte, f pointer, w int) ([]byte, error) {
935
x, n := decodeVarint(b)
937
return nil, io.ErrUnexpectedEOF
940
if x > uint64(len(b)) {
941
return nil, io.ErrUnexpectedEOF
946
x, n = decodeVarint(b)
948
return nil, io.ErrUnexpectedEOF
951
v := int64(x>>1) ^ int64(x)<<63>>63
952
s := f.toInt64Slice()
958
return b, errInternalBadWireType
960
x, n := decodeVarint(b)
962
return nil, io.ErrUnexpectedEOF
965
v := int64(x>>1) ^ int64(x)<<63>>63
966
s := f.toInt64Slice()
971
func unmarshalUint64Value(b []byte, f pointer, w int) ([]byte, error) {
973
return b, errInternalBadWireType
975
x, n := decodeVarint(b)
977
return nil, io.ErrUnexpectedEOF
985
func unmarshalUint64Ptr(b []byte, f pointer, w int) ([]byte, error) {
987
return b, errInternalBadWireType
989
x, n := decodeVarint(b)
991
return nil, io.ErrUnexpectedEOF
995
*f.toUint64Ptr() = &v
999
func unmarshalUint64Slice(b []byte, f pointer, w int) ([]byte, error) {
1001
x, n := decodeVarint(b)
1003
return nil, io.ErrUnexpectedEOF
1006
if x > uint64(len(b)) {
1007
return nil, io.ErrUnexpectedEOF
1012
x, n = decodeVarint(b)
1014
return nil, io.ErrUnexpectedEOF
1018
s := f.toUint64Slice()
1023
if w != WireVarint {
1024
return b, errInternalBadWireType
1026
x, n := decodeVarint(b)
1028
return nil, io.ErrUnexpectedEOF
1032
s := f.toUint64Slice()
1037
func unmarshalInt32Value(b []byte, f pointer, w int) ([]byte, error) {
1038
if w != WireVarint {
1039
return b, errInternalBadWireType
1041
x, n := decodeVarint(b)
1043
return nil, io.ErrUnexpectedEOF
1051
func unmarshalInt32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1052
if w != WireVarint {
1053
return b, errInternalBadWireType
1055
x, n := decodeVarint(b)
1057
return nil, io.ErrUnexpectedEOF
1065
func unmarshalInt32Slice(b []byte, f pointer, w int) ([]byte, error) {
1067
x, n := decodeVarint(b)
1069
return nil, io.ErrUnexpectedEOF
1072
if x > uint64(len(b)) {
1073
return nil, io.ErrUnexpectedEOF
1078
x, n = decodeVarint(b)
1080
return nil, io.ErrUnexpectedEOF
1084
f.appendInt32Slice(v)
1088
if w != WireVarint {
1089
return b, errInternalBadWireType
1091
x, n := decodeVarint(b)
1093
return nil, io.ErrUnexpectedEOF
1097
f.appendInt32Slice(v)
1101
func unmarshalSint32Value(b []byte, f pointer, w int) ([]byte, error) {
1102
if w != WireVarint {
1103
return b, errInternalBadWireType
1105
x, n := decodeVarint(b)
1107
return nil, io.ErrUnexpectedEOF
1110
v := int32(x>>1) ^ int32(x)<<31>>31
1115
func unmarshalSint32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1116
if w != WireVarint {
1117
return b, errInternalBadWireType
1119
x, n := decodeVarint(b)
1121
return nil, io.ErrUnexpectedEOF
1124
v := int32(x>>1) ^ int32(x)<<31>>31
1129
func unmarshalSint32Slice(b []byte, f pointer, w int) ([]byte, error) {
1131
x, n := decodeVarint(b)
1133
return nil, io.ErrUnexpectedEOF
1136
if x > uint64(len(b)) {
1137
return nil, io.ErrUnexpectedEOF
1142
x, n = decodeVarint(b)
1144
return nil, io.ErrUnexpectedEOF
1147
v := int32(x>>1) ^ int32(x)<<31>>31
1148
f.appendInt32Slice(v)
1152
if w != WireVarint {
1153
return b, errInternalBadWireType
1155
x, n := decodeVarint(b)
1157
return nil, io.ErrUnexpectedEOF
1160
v := int32(x>>1) ^ int32(x)<<31>>31
1161
f.appendInt32Slice(v)
1165
func unmarshalUint32Value(b []byte, f pointer, w int) ([]byte, error) {
1166
if w != WireVarint {
1167
return b, errInternalBadWireType
1169
x, n := decodeVarint(b)
1171
return nil, io.ErrUnexpectedEOF
1179
func unmarshalUint32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1180
if w != WireVarint {
1181
return b, errInternalBadWireType
1183
x, n := decodeVarint(b)
1185
return nil, io.ErrUnexpectedEOF
1189
*f.toUint32Ptr() = &v
1193
func unmarshalUint32Slice(b []byte, f pointer, w int) ([]byte, error) {
1195
x, n := decodeVarint(b)
1197
return nil, io.ErrUnexpectedEOF
1200
if x > uint64(len(b)) {
1201
return nil, io.ErrUnexpectedEOF
1206
x, n = decodeVarint(b)
1208
return nil, io.ErrUnexpectedEOF
1212
s := f.toUint32Slice()
1217
if w != WireVarint {
1218
return b, errInternalBadWireType
1220
x, n := decodeVarint(b)
1222
return nil, io.ErrUnexpectedEOF
1226
s := f.toUint32Slice()
1231
func unmarshalFixed64Value(b []byte, f pointer, w int) ([]byte, error) {
1232
if w != WireFixed64 {
1233
return b, errInternalBadWireType
1236
return nil, io.ErrUnexpectedEOF
1238
v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
1243
func unmarshalFixed64Ptr(b []byte, f pointer, w int) ([]byte, error) {
1244
if w != WireFixed64 {
1245
return b, errInternalBadWireType
1248
return nil, io.ErrUnexpectedEOF
1250
v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
1251
*f.toUint64Ptr() = &v
1255
func unmarshalFixed64Slice(b []byte, f pointer, w int) ([]byte, error) {
1257
x, n := decodeVarint(b)
1259
return nil, io.ErrUnexpectedEOF
1262
if x > uint64(len(b)) {
1263
return nil, io.ErrUnexpectedEOF
1269
return nil, io.ErrUnexpectedEOF
1271
v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
1272
s := f.toUint64Slice()
1278
if w != WireFixed64 {
1279
return b, errInternalBadWireType
1282
return nil, io.ErrUnexpectedEOF
1284
v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
1285
s := f.toUint64Slice()
1290
func unmarshalFixedS64Value(b []byte, f pointer, w int) ([]byte, error) {
1291
if w != WireFixed64 {
1292
return b, errInternalBadWireType
1295
return nil, io.ErrUnexpectedEOF
1297
v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
1302
func unmarshalFixedS64Ptr(b []byte, f pointer, w int) ([]byte, error) {
1303
if w != WireFixed64 {
1304
return b, errInternalBadWireType
1307
return nil, io.ErrUnexpectedEOF
1309
v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
1310
*f.toInt64Ptr() = &v
1314
func unmarshalFixedS64Slice(b []byte, f pointer, w int) ([]byte, error) {
1316
x, n := decodeVarint(b)
1318
return nil, io.ErrUnexpectedEOF
1321
if x > uint64(len(b)) {
1322
return nil, io.ErrUnexpectedEOF
1328
return nil, io.ErrUnexpectedEOF
1330
v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
1331
s := f.toInt64Slice()
1337
if w != WireFixed64 {
1338
return b, errInternalBadWireType
1341
return nil, io.ErrUnexpectedEOF
1343
v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
1344
s := f.toInt64Slice()
1349
func unmarshalFixed32Value(b []byte, f pointer, w int) ([]byte, error) {
1350
if w != WireFixed32 {
1351
return b, errInternalBadWireType
1354
return nil, io.ErrUnexpectedEOF
1356
v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
1361
func unmarshalFixed32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1362
if w != WireFixed32 {
1363
return b, errInternalBadWireType
1366
return nil, io.ErrUnexpectedEOF
1368
v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
1369
*f.toUint32Ptr() = &v
1373
func unmarshalFixed32Slice(b []byte, f pointer, w int) ([]byte, error) {
1375
x, n := decodeVarint(b)
1377
return nil, io.ErrUnexpectedEOF
1380
if x > uint64(len(b)) {
1381
return nil, io.ErrUnexpectedEOF
1387
return nil, io.ErrUnexpectedEOF
1389
v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
1390
s := f.toUint32Slice()
1396
if w != WireFixed32 {
1397
return b, errInternalBadWireType
1400
return nil, io.ErrUnexpectedEOF
1402
v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
1403
s := f.toUint32Slice()
1408
func unmarshalFixedS32Value(b []byte, f pointer, w int) ([]byte, error) {
1409
if w != WireFixed32 {
1410
return b, errInternalBadWireType
1413
return nil, io.ErrUnexpectedEOF
1415
v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
1420
func unmarshalFixedS32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1421
if w != WireFixed32 {
1422
return b, errInternalBadWireType
1425
return nil, io.ErrUnexpectedEOF
1427
v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
1432
func unmarshalFixedS32Slice(b []byte, f pointer, w int) ([]byte, error) {
1434
x, n := decodeVarint(b)
1436
return nil, io.ErrUnexpectedEOF
1439
if x > uint64(len(b)) {
1440
return nil, io.ErrUnexpectedEOF
1446
return nil, io.ErrUnexpectedEOF
1448
v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
1449
f.appendInt32Slice(v)
1454
if w != WireFixed32 {
1455
return b, errInternalBadWireType
1458
return nil, io.ErrUnexpectedEOF
1460
v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
1461
f.appendInt32Slice(v)
1465
func unmarshalBoolValue(b []byte, f pointer, w int) ([]byte, error) {
1466
if w != WireVarint {
1467
return b, errInternalBadWireType
1472
x, n := decodeVarint(b)
1474
return nil, io.ErrUnexpectedEOF
1482
func unmarshalBoolPtr(b []byte, f pointer, w int) ([]byte, error) {
1483
if w != WireVarint {
1484
return b, errInternalBadWireType
1486
x, n := decodeVarint(b)
1488
return nil, io.ErrUnexpectedEOF
1495
func unmarshalBoolSlice(b []byte, f pointer, w int) ([]byte, error) {
1497
x, n := decodeVarint(b)
1499
return nil, io.ErrUnexpectedEOF
1502
if x > uint64(len(b)) {
1503
return nil, io.ErrUnexpectedEOF
1508
x, n = decodeVarint(b)
1510
return nil, io.ErrUnexpectedEOF
1513
s := f.toBoolSlice()
1519
if w != WireVarint {
1520
return b, errInternalBadWireType
1522
x, n := decodeVarint(b)
1524
return nil, io.ErrUnexpectedEOF
1527
s := f.toBoolSlice()
1532
func unmarshalFloat64Value(b []byte, f pointer, w int) ([]byte, error) {
1533
if w != WireFixed64 {
1534
return b, errInternalBadWireType
1537
return nil, io.ErrUnexpectedEOF
1539
v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
1544
func unmarshalFloat64Ptr(b []byte, f pointer, w int) ([]byte, error) {
1545
if w != WireFixed64 {
1546
return b, errInternalBadWireType
1549
return nil, io.ErrUnexpectedEOF
1551
v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
1552
*f.toFloat64Ptr() = &v
1556
func unmarshalFloat64Slice(b []byte, f pointer, w int) ([]byte, error) {
1558
x, n := decodeVarint(b)
1560
return nil, io.ErrUnexpectedEOF
1563
if x > uint64(len(b)) {
1564
return nil, io.ErrUnexpectedEOF
1570
return nil, io.ErrUnexpectedEOF
1572
v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
1573
s := f.toFloat64Slice()
1579
if w != WireFixed64 {
1580
return b, errInternalBadWireType
1583
return nil, io.ErrUnexpectedEOF
1585
v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
1586
s := f.toFloat64Slice()
1591
func unmarshalFloat32Value(b []byte, f pointer, w int) ([]byte, error) {
1592
if w != WireFixed32 {
1593
return b, errInternalBadWireType
1596
return nil, io.ErrUnexpectedEOF
1598
v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
1603
func unmarshalFloat32Ptr(b []byte, f pointer, w int) ([]byte, error) {
1604
if w != WireFixed32 {
1605
return b, errInternalBadWireType
1608
return nil, io.ErrUnexpectedEOF
1610
v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
1611
*f.toFloat32Ptr() = &v
1615
func unmarshalFloat32Slice(b []byte, f pointer, w int) ([]byte, error) {
1617
x, n := decodeVarint(b)
1619
return nil, io.ErrUnexpectedEOF
1622
if x > uint64(len(b)) {
1623
return nil, io.ErrUnexpectedEOF
1629
return nil, io.ErrUnexpectedEOF
1631
v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
1632
s := f.toFloat32Slice()
1638
if w != WireFixed32 {
1639
return b, errInternalBadWireType
1642
return nil, io.ErrUnexpectedEOF
1644
v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
1645
s := f.toFloat32Slice()
1650
func unmarshalStringValue(b []byte, f pointer, w int) ([]byte, error) {
1652
return b, errInternalBadWireType
1654
x, n := decodeVarint(b)
1656
return nil, io.ErrUnexpectedEOF
1659
if x > uint64(len(b)) {
1660
return nil, io.ErrUnexpectedEOF
1667
func unmarshalStringPtr(b []byte, f pointer, w int) ([]byte, error) {
1669
return b, errInternalBadWireType
1671
x, n := decodeVarint(b)
1673
return nil, io.ErrUnexpectedEOF
1676
if x > uint64(len(b)) {
1677
return nil, io.ErrUnexpectedEOF
1680
*f.toStringPtr() = &v
1684
func unmarshalStringSlice(b []byte, f pointer, w int) ([]byte, error) {
1686
return b, errInternalBadWireType
1688
x, n := decodeVarint(b)
1690
return nil, io.ErrUnexpectedEOF
1693
if x > uint64(len(b)) {
1694
return nil, io.ErrUnexpectedEOF
1697
s := f.toStringSlice()
1702
func unmarshalUTF8StringValue(b []byte, f pointer, w int) ([]byte, error) {
1704
return b, errInternalBadWireType
1706
x, n := decodeVarint(b)
1708
return nil, io.ErrUnexpectedEOF
1711
if x > uint64(len(b)) {
1712
return nil, io.ErrUnexpectedEOF
1716
if !utf8.ValidString(v) {
1717
return b[x:], errInvalidUTF8
1722
func unmarshalUTF8StringPtr(b []byte, f pointer, w int) ([]byte, error) {
1724
return b, errInternalBadWireType
1726
x, n := decodeVarint(b)
1728
return nil, io.ErrUnexpectedEOF
1731
if x > uint64(len(b)) {
1732
return nil, io.ErrUnexpectedEOF
1735
*f.toStringPtr() = &v
1736
if !utf8.ValidString(v) {
1737
return b[x:], errInvalidUTF8
1742
func unmarshalUTF8StringSlice(b []byte, f pointer, w int) ([]byte, error) {
1744
return b, errInternalBadWireType
1746
x, n := decodeVarint(b)
1748
return nil, io.ErrUnexpectedEOF
1751
if x > uint64(len(b)) {
1752
return nil, io.ErrUnexpectedEOF
1755
s := f.toStringSlice()
1757
if !utf8.ValidString(v) {
1758
return b[x:], errInvalidUTF8
1765
func unmarshalBytesValue(b []byte, f pointer, w int) ([]byte, error) {
1767
return b, errInternalBadWireType
1769
x, n := decodeVarint(b)
1771
return nil, io.ErrUnexpectedEOF
1774
if x > uint64(len(b)) {
1775
return nil, io.ErrUnexpectedEOF
1781
v := append(emptyBuf[:], b[:x]...)
1786
func unmarshalBytesSlice(b []byte, f pointer, w int) ([]byte, error) {
1788
return b, errInternalBadWireType
1790
x, n := decodeVarint(b)
1792
return nil, io.ErrUnexpectedEOF
1795
if x > uint64(len(b)) {
1796
return nil, io.ErrUnexpectedEOF
1798
v := append(emptyBuf[:], b[:x]...)
1799
s := f.toBytesSlice()
1804
func makeUnmarshalMessagePtr(sub *unmarshalInfo, name string) unmarshaler {
1805
return func(b []byte, f pointer, w int) ([]byte, error) {
1807
return b, errInternalBadWireType
1809
x, n := decodeVarint(b)
1811
return nil, io.ErrUnexpectedEOF
1814
if x > uint64(len(b)) {
1815
return nil, io.ErrUnexpectedEOF
1823
v = valToPointer(reflect.New(sub.typ))
1826
err := sub.unmarshal(v, b[:x])
1828
if r, ok := err.(*RequiredNotSetError); ok {
1829
r.field = name + "." + r.field
1838
func makeUnmarshalMessageSlicePtr(sub *unmarshalInfo, name string) unmarshaler {
1839
return func(b []byte, f pointer, w int) ([]byte, error) {
1841
return b, errInternalBadWireType
1843
x, n := decodeVarint(b)
1845
return nil, io.ErrUnexpectedEOF
1848
if x > uint64(len(b)) {
1849
return nil, io.ErrUnexpectedEOF
1851
v := valToPointer(reflect.New(sub.typ))
1852
err := sub.unmarshal(v, b[:x])
1854
if r, ok := err.(*RequiredNotSetError); ok {
1855
r.field = name + "." + r.field
1865
func makeUnmarshalGroupPtr(sub *unmarshalInfo, name string) unmarshaler {
1866
return func(b []byte, f pointer, w int) ([]byte, error) {
1867
if w != WireStartGroup {
1868
return b, errInternalBadWireType
1870
x, y := findEndGroup(b)
1872
return nil, io.ErrUnexpectedEOF
1876
v = valToPointer(reflect.New(sub.typ))
1879
err := sub.unmarshal(v, b[:x])
1881
if r, ok := err.(*RequiredNotSetError); ok {
1882
r.field = name + "." + r.field
1891
func makeUnmarshalGroupSlicePtr(sub *unmarshalInfo, name string) unmarshaler {
1892
return func(b []byte, f pointer, w int) ([]byte, error) {
1893
if w != WireStartGroup {
1894
return b, errInternalBadWireType
1896
x, y := findEndGroup(b)
1898
return nil, io.ErrUnexpectedEOF
1900
v := valToPointer(reflect.New(sub.typ))
1901
err := sub.unmarshal(v, b[:x])
1903
if r, ok := err.(*RequiredNotSetError); ok {
1904
r.field = name + "." + r.field
1914
func makeUnmarshalMap(f *reflect.StructField) unmarshaler {
1918
tagArray := strings.Split(f.Tag.Get("protobuf"), ",")
1919
valTags := strings.Split(f.Tag.Get("protobuf_val"), ",")
1920
for _, t := range tagArray {
1921
if strings.HasPrefix(t, "customtype=") {
1922
valTags = append(valTags, t)
1925
valTags = append(valTags, t)
1927
if t == "stdduration" {
1928
valTags = append(valTags, t)
1931
valTags = append(valTags, t)
1934
unmarshalKey := typeUnmarshaler(kt, f.Tag.Get("protobuf_key"))
1935
unmarshalVal := typeUnmarshaler(vt, strings.Join(valTags, ","))
1936
return func(b []byte, f pointer, w int) ([]byte, error) {
1939
return nil, fmt.Errorf("proto: bad wiretype for map field: got %d want %d", w, WireBytes)
1941
x, n := decodeVarint(b)
1943
return nil, io.ErrUnexpectedEOF
1946
if x > uint64(len(b)) {
1947
return nil, io.ErrUnexpectedEOF
1958
k := reflect.New(kt)
1959
v := reflect.New(vt)
1961
x, n := decodeVarint(b)
1963
return nil, io.ErrUnexpectedEOF
1971
b, err = unmarshalKey(b, valToPointer(k), wire)
1973
b, err = unmarshalVal(b, valToPointer(v), wire)
1975
err = errInternalBadWireType
1978
if nerr.Merge(err) {
1981
if err != errInternalBadWireType {
1986
b, err = skipField(b, wire)
1993
m := f.asPointerTo(t).Elem()
1995
m.Set(reflect.MakeMap(t))
1999
m.SetMapIndex(k.Elem(), v.Elem())
2017
func makeUnmarshalOneof(typ, ityp reflect.Type, unmarshal unmarshaler) unmarshaler {
2019
field0 := toField(&sf)
2020
return func(b []byte, f pointer, w int) ([]byte, error) {
2022
v := reflect.New(typ)
2028
b, err = unmarshal(b, valToPointer(v).offset(field0), w)
2029
if !nerr.Merge(err) {
2034
f.asPointerTo(ityp).Elem().Set(v)
2041
var errInternalBadWireType = errors.New("proto: internal error: bad wiretype")
2044
func skipField(b []byte, wire int) ([]byte, error) {
2047
_, k := decodeVarint(b)
2049
return b, io.ErrUnexpectedEOF
2054
return b, io.ErrUnexpectedEOF
2059
return b, io.ErrUnexpectedEOF
2063
m, k := decodeVarint(b)
2064
if k == 0 || uint64(len(b)-k) < m {
2065
return b, io.ErrUnexpectedEOF
2068
case WireStartGroup:
2069
_, i := findEndGroup(b)
2071
return b, io.ErrUnexpectedEOF
2075
return b, fmt.Errorf("proto: can't skip unknown wire type %d", wire)
2085
func findEndGroup(b []byte) (int, int) {
2089
x, n := decodeVarint(b[i:])
2097
_, k := decodeVarint(b[i:])
2113
m, k := decodeVarint(b[i:])
2118
if uint64(len(b)-i) < m {
2122
case WireStartGroup:
2136
func encodeVarint(b []byte, x uint64) []byte {
2138
b = append(b, byte(x&0x7f|0x80))
2141
return append(b, byte(x))
2147
func decodeVarint(b []byte) (uint64, int) {