MCPcopy Create free account
hub / github.com/temporalio/temporal / DecodeSlice

Method DecodeSlice

common/codec/jsonpb.go:114–147  ·  view source on GitHub ↗

constructor callback must create empty object, add it to result slice, and return it.

(
	data []byte,
	constructor func() proto.Message)

Source from the content-addressed store, hash-verified

112
113// constructor callback must create empty object, add it to result slice, and return it.
114func (e *JSONPBEncoder) DecodeSlice(
115 data []byte,
116 constructor func() proto.Message) error {
117
118 dec := json.NewDecoder(bytes.NewReader(data))
119
120 tok, err := dec.Token()
121 if err != nil {
122 return err
123 }
124 if delim, ok := tok.(json.Delim); !ok || delim != '[' {
125 return fmt.Errorf("invalid json: expected [ but found %v", tok)
126 }
127
128 // We need DiscardUnknown here as the history json may have been written by a
129 // different proto revision
130 unmarshaller := temporalproto.CustomJSONUnmarshalOptions{
131 DiscardUnknown: true,
132 }
133
134 var buf json.RawMessage
135 for dec.More() {
136 if err := dec.Decode(&buf); err != nil {
137 return err
138 }
139 pb := constructor()
140 if err := unmarshaller.Unmarshal([]byte(buf), pb); err != nil {
141 return err
142 }
143 buf = buf[:0]
144 }
145
146 return nil
147}

Callers 3

listQueuesMethod · 0.95
DecodeHistoryEventsMethod · 0.95
DecodeHistoriesMethod · 0.95

Calls 5

NewDecoderMethod · 0.80
NewReaderMethod · 0.65
DecodeMethod · 0.65
ErrorfMethod · 0.45
UnmarshalMethod · 0.45

Tested by 1

listQueuesMethod · 0.76