Documentation ¶
Overview ¶
Package easyjson contains marshaler/unmarshaler interfaces and helper functions.
Index ¶
- func Marshal(v Marshaler) ([]byte, error)
- func MarshalToHTTPResponseWriter(v Marshaler, w http.ResponseWriter) (started bool, written int, err error)
- func MarshalToWriter(v Marshaler, w io.Writer) (written int, err error)
- func Unmarshal(data []byte, v Unmarshaler) error
- func UnmarshalFromReader(r io.Reader, v Unmarshaler) error
- type JsonMapping
- func (j *JsonMapping) Add(name string, jsonVal string) *JsonMapping
- func (j *JsonMapping) Added() map[string]string
- func (j *JsonMapping) Name(field, jsonName string) string
- func (j *JsonMapping) Omit(fields ...string) *JsonMapping
- func (j *JsonMapping) Only(fields ...string) *JsonMapping
- func (j *JsonMapping) Rename(field, to string) *JsonMapping
- type Marshaler
- type Optional
- type RawMessage
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal returns data as a single byte slice. Method is suboptimal as the data is likely to be copied from a chain of smaller chunks.
func MarshalToHTTPResponseWriter ¶
func MarshalToHTTPResponseWriter(v Marshaler, w http.ResponseWriter) (started bool, written int, err error)
MarshalToHTTPResponseWriter sets Content-Length and Content-Type headers for the http.ResponseWriter, and send the data to the writer. started will be equal to false if an error occurred before any http.ResponseWriter methods were actually invoked (in this case a 500 reply is possible).
func MarshalToWriter ¶
MarshalToWriter marshals the data to an io.Writer.
func Unmarshal ¶
func Unmarshal(data []byte, v Unmarshaler) error
Unmarshal decodes the JSON in data into the object.
func UnmarshalFromReader ¶
func UnmarshalFromReader(r io.Reader, v Unmarshaler) error
UnmarshalFromReader reads all the data in the reader and decodes as JSON into the object.
Types ¶
type JsonMapping ¶
type JsonMapping struct {
// contains filtered or unexported fields
}
JsonMapping allows hiding/renaming/adding Json fields during runtime encoding
func (*JsonMapping) Add ¶
func (j *JsonMapping) Add(name string, jsonVal string) *JsonMapping
Add tells the encoder to add some extra items when encoding jsonVal is assumed already JSON encoded, ie: "true", "5", "\"foo\""
func (*JsonMapping) Added ¶
func (j *JsonMapping) Added() map[string]string
Added returns the added items
func (*JsonMapping) Name ¶
func (j *JsonMapping) Name(field, jsonName string) string
Name returns the mapped name for a field a returned value of empty string means Omit the field
func (*JsonMapping) Omit ¶
func (j *JsonMapping) Omit(fields ...string) *JsonMapping
Drop tells the encoder to omit the given field (by name)
func (*JsonMapping) Only ¶
func (j *JsonMapping) Only(fields ...string) *JsonMapping
Only tells the encoder to only include the given fields (by name) incompatible with Omit()
func (*JsonMapping) Rename ¶
func (j *JsonMapping) Rename(field, to string) *JsonMapping
Rename tells the encoder to use a different name for a given field.
type Optional ¶
type Optional interface {
IsDefined() bool
}
Optional defines an undefined-test method for a type to integrate with 'omitempty' logic.
type RawMessage ¶
type RawMessage []byte
RawMessage is a raw piece of JSON (number, string, bool, object, array or null) that is extracted without parsing and output as is during marshalling.
func (*RawMessage) IsDefined ¶
func (v *RawMessage) IsDefined() bool
IsDefined is required for integration with omitempty easyjson logic.
func (*RawMessage) MarshalEasyJSON ¶
func (v *RawMessage) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON does JSON marshaling using easyjson interface.
func (RawMessage) MarshalJSON ¶
func (v RawMessage) MarshalJSON() ([]byte, error)
MarshalJSON implements encoding/json.Marshaler interface.
func (*RawMessage) UnmarshalEasyJSON ¶
func (v *RawMessage) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON does JSON unmarshaling using easyjson interface.
func (*RawMessage) UnmarshalJSON ¶
func (v *RawMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON implements encoding/json.Unmarshaler interface.
type Unmarshaler ¶
Marshaler is an easyjson-compatible unmarshaler interface.
Directories ¶
Path | Synopsis |
---|---|
Package benchmark provides a simple benchmark for easyjson against default serialization and ffjson.
|
Package benchmark provides a simple benchmark for easyjson against default serialization and ffjson. |
Package bootstrap implements the bootstrapping logic: generation of a .go file to launch the actual generator and launching the generator itself.
|
Package bootstrap implements the bootstrapping logic: generation of a .go file to launch the actual generator and launching the generator itself. |
Package buffer implements a buffer for serialization, consisting of a chain of []byte-s to reduce copying and to allow reuse of individual chunks.
|
Package buffer implements a buffer for serialization, consisting of a chain of []byte-s to reduce copying and to allow reuse of individual chunks. |
Package jlexer contains a JSON lexer implementation.
|
Package jlexer contains a JSON lexer implementation. |
Package jwriter contains a JSON writer.
|
Package jwriter contains a JSON writer. |