(t reflect.Type, si structInfo)
| 57 | const noPresence = 0xffffffff |
| 58 | |
| 59 | func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) { |
| 60 | mi.sizecacheOffset = invalidOffset |
| 61 | mi.unknownOffset = invalidOffset |
| 62 | mi.extensionOffset = invalidOffset |
| 63 | mi.lazyOffset = invalidOffset |
| 64 | mi.presenceOffset = si.presenceOffset |
| 65 | |
| 66 | if si.sizecacheOffset.IsValid() && si.sizecacheType == sizecacheType { |
| 67 | mi.sizecacheOffset = si.sizecacheOffset |
| 68 | } |
| 69 | if si.unknownOffset.IsValid() && (si.unknownType == unknownFieldsAType || si.unknownType == unknownFieldsBType) { |
| 70 | mi.unknownOffset = si.unknownOffset |
| 71 | mi.unknownPtrKind = si.unknownType.Kind() == reflect.Ptr |
| 72 | } |
| 73 | if si.extensionOffset.IsValid() && si.extensionType == extensionFieldsType { |
| 74 | mi.extensionOffset = si.extensionOffset |
| 75 | } |
| 76 | |
| 77 | mi.coderFields = make(map[protowire.Number]*coderFieldInfo) |
| 78 | fields := mi.Desc.Fields() |
| 79 | preallocFields := make([]coderFieldInfo, fields.Len()) |
| 80 | for i := 0; i < fields.Len(); i++ { |
| 81 | fd := fields.Get(i) |
| 82 | |
| 83 | fs := si.fieldsByNumber[fd.Number()] |
| 84 | isOneof := fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic() |
| 85 | if isOneof { |
| 86 | fs = si.oneofsByName[fd.ContainingOneof().Name()] |
| 87 | } |
| 88 | ft := fs.Type |
| 89 | var wiretag uint64 |
| 90 | if !fd.IsPacked() { |
| 91 | wiretag = protowire.EncodeTag(fd.Number(), wireTypes[fd.Kind()]) |
| 92 | } else { |
| 93 | wiretag = protowire.EncodeTag(fd.Number(), protowire.BytesType) |
| 94 | } |
| 95 | var fieldOffset offset |
| 96 | var funcs pointerCoderFuncs |
| 97 | var childMessage *MessageInfo |
| 98 | switch { |
| 99 | case ft == nil: |
| 100 | // This never occurs for generated message types. |
| 101 | // It implies that a hand-crafted type has missing Go fields |
| 102 | // for specific protobuf message fields. |
| 103 | funcs = pointerCoderFuncs{ |
| 104 | size: func(p pointer, f *coderFieldInfo, opts marshalOptions) int { |
| 105 | return 0 |
| 106 | }, |
| 107 | marshal: func(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 108 | return nil, nil |
| 109 | }, |
| 110 | unmarshal: func(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (unmarshalOutput, error) { |
| 111 | panic("missing Go struct field for " + string(fd.FullName())) |
| 112 | }, |
| 113 | isInit: func(p pointer, f *coderFieldInfo) error { |
| 114 | panic("missing Go struct field for " + string(fd.FullName())) |
| 115 | }, |
| 116 | merge: func(dst, src pointer, f *coderFieldInfo, opts mergeOptions) { |
no test coverage detected