Atlas › Test

TestEncodeHistories

Exact test identity: go.temporal.io/server/common/codec/TestJSONPBEncoderSuite/TestEncodeHistories

Package
go.temporal.io/server/common/codec
Suite / test hierarchy
TestJSONPBEncoderSuite/TestEncodeHistories
Test
TestEncodeHistories
Introduced at
TestEncodeHistories Frontier kind: Test frontier
Covered ranges
7
Covered lines
21
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/codec/jsonpb.go 21 covered LOC · 7 ranges

Open complete file

23
24 // NewJSONPBEncoder creates a new JSONPBEncoder.
25 > func NewJSONPBEncoder() JSONPBEncoder { jsonpb.go
26 > return JSONPBEncoder{}
27 > }
28
29 // NewJSONPBIndentEncoder creates a new JSONPBEncoder with indent.
54
55 // Encode History slice to bytes.
56 > func (e *JSONPBEncoder) EncodeHistories(histories []*historypb.History) ([]byte, error) { jsonpb.go
57 > return e.encodeSlice(
58 > len(histories),
59 > func(i int) proto.Message { return histories[i] })
60 }
61
92 len int,
93 item func(i int) proto.Message,
94 > ) ([]byte, error) { jsonpb.go
95 > var buf bytes.Buffer
96 > buf.WriteString("[")
97 > for i := range len {
98 > pb := item(i) jsonpb.go
99 > bs, err := e.marshaler.Marshal(pb)
100 > if err != nil {
101 return nil, err
102 }
103 > buf.Write(bs) jsonpb.go
104 >
105 > if i < len-1 {
106 > buf.WriteString(",") jsonpb.go
107 > }
108 }
109 > buf.WriteString("]") jsonpb.go
110 > return buf.Bytes(), nil
111 }
112