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

Method encodeSlice

common/codec/jsonpb.go:91–111  ·  view source on GitHub ↗

Due to the lack of generics in go this function accepts callback which should return particular item by it index.

(
	len int,
	item func(i int) proto.Message,
)

Source from the content-addressed store, hash-verified

89// Due to the lack of generics in go
90// this function accepts callback which should return particular item by it index.
91func (e *JSONPBEncoder) encodeSlice(
92 len int,
93 item func(i int) proto.Message,
94) ([]byte, error) {
95 var buf bytes.Buffer
96 buf.WriteString("[")
97 for i := range len {
98 pb := item(i)
99 bs, err := e.marshaler.Marshal(pb)
100 if err != nil {
101 return nil, err
102 }
103 buf.Write(bs)
104
105 if i < len-1 {
106 buf.WriteString(",")
107 }
108 }
109 buf.WriteString("]")
110 return buf.Bytes(), nil
111}
112
113// constructor callback must create empty object, add it to result slice, and return it.
114func (e *JSONPBEncoder) DecodeSlice(

Callers 2

EncodeHistoryEventsMethod · 0.95
EncodeHistoriesMethod · 0.95

Calls 3

BytesMethod · 0.80
MarshalMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected