MCPcopy
hub / github.com/pquerna/ffjson / Marshal

Function Marshal

ffjson/marshal.go:42–62  ·  view source on GitHub ↗

Marshal will act the same way as json.Marshal, except it will choose the ffjson marshal function before falling back to using json.Marshal. Using this function will bypass the internal copying and parsing the json library normally does, which greatly speeds up encoding time. It is ok to call this fu

(v interface{})

Source from the content-addressed store, hash-verified

40// It is ok to call this function even if no ffjson code has been
41// generated for the data type you pass in the interface.
42func Marshal(v interface{}) ([]byte, error) {
43 f, ok := v.(marshalerFaster)
44 if ok {
45 buf := fflib.Buffer{}
46 err := f.MarshalJSONBuf(&buf)
47 b := buf.Bytes()
48 if err != nil {
49 if len(b) > 0 {
50 Pool(b)
51 }
52 return nil, err
53 }
54 return b, nil
55 }
56
57 j, ok := v.(json.Marshaler)
58 if ok {
59 return j.MarshalJSON()
60 }
61 return json.Marshal(v)
62}
63
64// MarshalFast will marshal the data if fast marshal is available.
65// This function can be used if you want to be sure the fast

Callers 1

MarshalFastFunction · 0.85

Calls 4

BytesMethod · 0.95
PoolFunction · 0.70
MarshalJSONBufMethod · 0.65
MarshalJSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…