MCPcopy Create free account
hub / github.com/DoNewsCode/core / NewCodec

Function NewCodec

codec/json/json.go:28–44  ·  view source on GitHub ↗

NewCodec creates a new json codec

(opts ...Option)

Source from the content-addressed store, hash-verified

26
27// NewCodec creates a new json codec
28func NewCodec(opts ...Option) Codec {
29 var (
30 codec Codec
31 marshalOptions = protojson.MarshalOptions{
32 EmitUnpopulated: true,
33 }
34 unmarshalOptions = protojson.UnmarshalOptions{
35 DiscardUnknown: true,
36 }
37 )
38 codec.marshalOptions = marshalOptions
39 codec.unmarshalOptions = unmarshalOptions
40 for _, f := range opts {
41 f(&codec)
42 }
43 return codec
44}
45
46// WithIndent allows the codec to indent json output while marshalling. It is
47// useful when the json output is meant for humans to read.

Callers 2

getHandlerFunction · 0.92
TestJSON_MarshalFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestJSON_MarshalFunction · 0.68