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{})
| 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. |
| 42 | func 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 |
no test coverage detected
searching dependent graphs…