MCPcopy
hub / github.com/golang/protobuf / UnmarshalJSONEnum

Function UnmarshalJSONEnum

proto/deprecated.go:66–85  ·  view source on GitHub ↗

Deprecated: Do not use.

(m map[string]int32, data []byte, enumName string)

Source from the content-addressed store, hash-verified

64
65// Deprecated: Do not use.
66func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
67 if data[0] == '"' {
68 // New style: enums are strings.
69 var repr string
70 if err := json.Unmarshal(data, &repr); err != nil {
71 return -1, err
72 }
73 val, ok := m[repr]
74 if !ok {
75 return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
76 }
77 return val, nil
78 }
79 // Old style: enums are ints.
80 var val int32
81 if err := json.Unmarshal(data, &val); err != nil {
82 return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
83 }
84 return val, nil
85}
86
87// Deprecated: Do not use; this type existed for intenal-use only.
88type InternalMessageInfo struct{}

Callers 7

UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92
UnmarshalJSONMethod · 0.92

Calls 1

UnmarshalMethod · 0.65

Tested by

no test coverage detected