Documentation ¶
Overview ¶
Package gojay implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions.
It aims at performance and usability by relying on simple interfaces to decode and encode structures, slices, arrays and even channels.
On top of the simple interfaces to implement, gojay provides lots of helpers to decode and encode multiple of different types natively such as bit.Int, sql.NullString or time.Time
Example (DecodeEncode) ¶
package main import ( "fmt" "log" "os" "strings" "github.com/francoispqt/gojay" ) type User struct { ID int Name string Email string } func (u *User) UnmarshalJSONObject(dec *gojay.Decoder, k string) error { switch k { case "id": return dec.Int(&u.ID) case "name": return dec.String(&u.Name) case "email": return dec.String(&u.Email) } return nil } func (u *User) NKeys() int { return 3 } func (u *User) MarshalJSONObject(enc *gojay.Encoder) { enc.IntKey("id", u.ID) enc.StringKey("name", u.Name) enc.StringKey("email", u.Email) } func (u *User) IsNil() bool { return u == nil } func main() { reader := strings.NewReader(`{ "id": 1, "name": "John Doe", "email": "john.doe@email.com" }`) dec := gojay.BorrowDecoder(reader) defer dec.Release() u := &User{} err := dec.Decode(u) if err != nil { log.Fatal(err) } enc := gojay.BorrowEncoder(os.Stdout) err = enc.Encode(u) if err != nil { log.Fatal(err) } fmt.Printf("\nUser ID: %d\nName: %s\nEmail: %s\n", u.ID, u.Name, u.Email) }
Output: {"id":1,"name":"John Doe","email":"john.doe@email.com"} User ID: 1 Name: John Doe Email: john.doe@email.com
Index ¶
- Variables
- func Marshal(v interface{}) ([]byte, error)
- func MarshalAny(v interface{}) ([]byte, error)
- func MarshalJSONArray(v MarshalerJSONArray) ([]byte, error)
- func MarshalJSONObject(v MarshalerJSONObject) ([]byte, error)
- func Unmarshal(data []byte, v interface{}) error
- func UnmarshalJSONArray(data []byte, v UnmarshalerJSONArray) error
- func UnmarshalJSONObject(data []byte, v UnmarshalerJSONObject) error
- func UnmarshalJSONObjectWithPool(data []byte, v UnmarshalerJSONObject) error
- type ByteBuffer
- type DecodeArrayFunc
- type DecodeObjectFunc
- type Decoder
- func (dec *Decoder) AddArray(v UnmarshalerJSONArray) error
- func (dec *Decoder) AddArrayNull(v interface{}) error
- func (dec *Decoder) AddBool(v *bool) error
- func (dec *Decoder) AddBoolNull(v **bool) error
- func (dec *Decoder) AddEmbeddedJSON(v *EmbeddedJSON) error
- func (dec *Decoder) AddFloat(v *float64) error
- func (dec *Decoder) AddFloat32(v *float32) error
- func (dec *Decoder) AddFloat32Null(v **float32) error
- func (dec *Decoder) AddFloat64(v *float64) error
- func (dec *Decoder) AddFloat64Null(v **float64) error
- func (dec *Decoder) AddFloatNull(v **float64) error
- func (dec *Decoder) AddInt(v *int) error
- func (dec *Decoder) AddInt16(v *int16) error
- func (dec *Decoder) AddInt16Null(v **int16) error
- func (dec *Decoder) AddInt32(v *int32) error
- func (dec *Decoder) AddInt32Null(v **int32) error
- func (dec *Decoder) AddInt64(v *int64) error
- func (dec *Decoder) AddInt64Null(v **int64) error
- func (dec *Decoder) AddInt8(v *int8) error
- func (dec *Decoder) AddInt8Null(v **int8) error
- func (dec *Decoder) AddIntNull(v **int) error
- func (dec *Decoder) AddInterface(v *interface{}) error
- func (dec *Decoder) AddObject(v UnmarshalerJSONObject) error
- func (dec *Decoder) AddObjectNull(v interface{}) error
- func (dec *Decoder) AddSQLNullBool(v *sql.NullBool) error
- func (dec *Decoder) AddSQLNullFloat64(v *sql.NullFloat64) error
- func (dec *Decoder) AddSQLNullInt64(v *sql.NullInt64) error
- func (dec *Decoder) AddSQLNullString(v *sql.NullString) error
- func (dec *Decoder) AddSliceBool(s *[]bool) error
- func (dec *Decoder) AddSliceFloat64(s *[]float64) error
- func (dec *Decoder) AddSliceInt(s *[]int) error
- func (dec *Decoder) AddSliceString(s *[]string) error
- func (dec *Decoder) AddString(v *string) error
- func (dec *Decoder) AddStringNull(v **string) error
- func (dec *Decoder) AddTime(v *time.Time, format string) error
- func (dec *Decoder) AddUint16(v *uint16) error
- func (dec *Decoder) AddUint16Null(v **uint16) error
- func (dec *Decoder) AddUint32(v *uint32) error
- func (dec *Decoder) AddUint32Null(v **uint32) error
- func (dec *Decoder) AddUint64(v *uint64) error
- func (dec *Decoder) AddUint64Null(v **uint64) error
- func (dec *Decoder) AddUint8(v *uint8) error
- func (dec *Decoder) AddUint8Null(v **uint8) error
- func (dec *Decoder) Array(v UnmarshalerJSONArray) error
- func (dec *Decoder) ArrayNull(v interface{}) error
- func (dec *Decoder) Bool(v *bool) error
- func (dec *Decoder) BoolNull(v **bool) error
- func (dec *Decoder) Decode(v interface{}) error
- func (dec *Decoder) DecodeArray(v UnmarshalerJSONArray) error
- func (dec *Decoder) DecodeBool(v *bool) error
- func (dec *Decoder) DecodeFloat32(v *float32) error
- func (dec *Decoder) DecodeFloat64(v *float64) error
- func (dec *Decoder) DecodeInt(v *int) error
- func (dec *Decoder) DecodeInt16(v *int16) error
- func (dec *Decoder) DecodeInt32(v *int32) error
- func (dec *Decoder) DecodeInt64(v *int64) error
- func (dec *Decoder) DecodeInt8(v *int8) error
- func (dec *Decoder) DecodeInterface(i *interface{}) error
- func (dec *Decoder) DecodeObject(j UnmarshalerJSONObject) error
- func (dec *Decoder) DecodeSQLNullBool(v *sql.NullBool) error
- func (dec *Decoder) DecodeSQLNullFloat64(v *sql.NullFloat64) error
- func (dec *Decoder) DecodeSQLNullInt64(v *sql.NullInt64) error
- func (dec *Decoder) DecodeSQLNullString(v *sql.NullString) error
- func (dec *Decoder) DecodeString(v *string) error
- func (dec *Decoder) DecodeTime(v *time.Time, format string) error
- func (dec *Decoder) DecodeUint16(v *uint16) error
- func (dec *Decoder) DecodeUint32(v *uint32) error
- func (dec *Decoder) DecodeUint64(v *uint64) error
- func (dec *Decoder) DecodeUint8(v *uint8) error
- func (dec *Decoder) EmbeddedJSON(v *EmbeddedJSON) error
- func (dec *Decoder) Float(v *float64) error
- func (dec *Decoder) Float32(v *float32) error
- func (dec *Decoder) Float32Null(v **float32) error
- func (dec *Decoder) Float64(v *float64) error
- func (dec *Decoder) Float64Null(v **float64) error
- func (dec *Decoder) FloatNull(v **float64) error
- func (dec *Decoder) Index() int
- func (dec *Decoder) Int(v *int) error
- func (dec *Decoder) Int16(v *int16) error
- func (dec *Decoder) Int16Null(v **int16) error
- func (dec *Decoder) Int32(v *int32) error
- func (dec *Decoder) Int32Null(v **int32) error
- func (dec *Decoder) Int64(v *int64) error
- func (dec *Decoder) Int64Null(v **int64) error
- func (dec *Decoder) Int8(v *int8) error
- func (dec *Decoder) Int8Null(v **int8) error
- func (dec *Decoder) IntNull(v **int) error
- func (dec *Decoder) Interface(value *interface{}) error
- func (dec *Decoder) Object(value UnmarshalerJSONObject) error
- func (dec *Decoder) ObjectNull(v interface{}) error
- func (dec *Decoder) Release()
- func (dec *Decoder) SQLNullBool(v *sql.NullBool) error
- func (dec *Decoder) SQLNullFloat64(v *sql.NullFloat64) error
- func (dec *Decoder) SQLNullInt64(v *sql.NullInt64) error
- func (dec *Decoder) SQLNullString(v *sql.NullString) error
- func (dec *Decoder) SliceBool(s *[]bool) error
- func (dec *Decoder) SliceFloat64(s *[]float64) error
- func (dec *Decoder) SliceInt(s *[]int) error
- func (dec *Decoder) SliceString(s *[]string) error
- func (dec *Decoder) String(v *string) error
- func (dec *Decoder) StringNull(v **string) error
- func (dec *Decoder) Time(v *time.Time, format string) error
- func (dec *Decoder) Uint16(v *uint16) error
- func (dec *Decoder) Uint16Null(v **uint16) error
- func (dec *Decoder) Uint32(v *uint32) error
- func (dec *Decoder) Uint32Null(v **uint32) error
- func (dec *Decoder) Uint64(v *uint64) error
- func (dec *Decoder) Uint64Null(v **uint64) error
- func (dec *Decoder) Uint8(v *uint8) error
- func (dec *Decoder) Uint8Null(v **uint8) error
- type EmbeddedJSON
- type EncodeArrayFunc
- type EncodeObjectFunc
- type Encoder
- func (enc *Encoder) AddArray(v MarshalerJSONArray)
- func (enc *Encoder) AddArrayKey(key string, v MarshalerJSONArray)
- func (enc *Encoder) AddArrayKeyNullEmpty(key string, v MarshalerJSONArray)
- func (enc *Encoder) AddArrayKeyOmitEmpty(key string, v MarshalerJSONArray)
- func (enc *Encoder) AddArrayNullEmpty(v MarshalerJSONArray)
- func (enc *Encoder) AddArrayOmitEmpty(v MarshalerJSONArray)
- func (enc *Encoder) AddBool(v bool)
- func (enc *Encoder) AddBoolKey(key string, v bool)
- func (enc *Encoder) AddBoolKeyNullEmpty(key string, v bool)
- func (enc *Encoder) AddBoolKeyOmitEmpty(key string, v bool)
- func (enc *Encoder) AddBoolNullEmpty(v bool)
- func (enc *Encoder) AddBoolOmitEmpty(v bool)
- func (enc *Encoder) AddEmbeddedJSON(v *EmbeddedJSON)
- func (enc *Encoder) AddEmbeddedJSONKey(key string, v *EmbeddedJSON)
- func (enc *Encoder) AddEmbeddedJSONKeyOmitEmpty(key string, v *EmbeddedJSON)
- func (enc *Encoder) AddEmbeddedJSONOmitEmpty(v *EmbeddedJSON)
- func (enc *Encoder) AddFloat(v float64)
- func (enc *Encoder) AddFloat32(v float32)
- func (enc *Encoder) AddFloat32Key(key string, v float32)
- func (enc *Encoder) AddFloat32KeyNullEmpty(key string, v float32)
- func (enc *Encoder) AddFloat32KeyOmitEmpty(key string, v float32)
- func (enc *Encoder) AddFloat32NullEmpty(v float32)
- func (enc *Encoder) AddFloat32OmitEmpty(v float32)
- func (enc *Encoder) AddFloat64(v float64)
- func (enc *Encoder) AddFloat64Key(key string, v float64)
- func (enc *Encoder) AddFloat64KeyOmitEmpty(key string, v float64)
- func (enc *Encoder) AddFloat64OmitEmpty(v float64)
- func (enc *Encoder) AddFloatKey(key string, v float64)
- func (enc *Encoder) AddFloatKeyNullEmpty(key string, v float64)
- func (enc *Encoder) AddFloatKeyOmitEmpty(key string, v float64)
- func (enc *Encoder) AddFloatNullEmpty(v float64)
- func (enc *Encoder) AddFloatOmitEmpty(v float64)
- func (enc *Encoder) AddInt(v int)
- func (enc *Encoder) AddInt16(v int16)
- func (enc *Encoder) AddInt16Key(key string, v int16)
- func (enc *Encoder) AddInt16KeyNullEmpty(key string, v int16)
- func (enc *Encoder) AddInt16KeyOmitEmpty(key string, v int16)
- func (enc *Encoder) AddInt16OmitEmpty(v int16)
- func (enc *Encoder) AddInt32(v int32)
- func (enc *Encoder) AddInt32Key(key string, v int32)
- func (enc *Encoder) AddInt32KeyOmitEmpty(key string, v int32)
- func (enc *Encoder) AddInt32NullEmpty(v int32)
- func (enc *Encoder) AddInt32OmitEmpty(v int32)
- func (enc *Encoder) AddInt64(v int64)
- func (enc *Encoder) AddInt64Key(key string, v int64)
- func (enc *Encoder) AddInt64KeyNullEmpty(key string, v int64)
- func (enc *Encoder) AddInt64KeyOmitEmpty(key string, v int64)
- func (enc *Encoder) AddInt64NullEmpty(v int64)
- func (enc *Encoder) AddInt64OmitEmpty(v int64)
- func (enc *Encoder) AddInt8(v int8)
- func (enc *Encoder) AddInt8Key(key string, v int8)
- func (enc *Encoder) AddInt8KeyNullEmpty(key string, v int8)
- func (enc *Encoder) AddInt8KeyOmitEmpty(key string, v int8)
- func (enc *Encoder) AddInt8NullEmpty(v int8)
- func (enc *Encoder) AddInt8OmitEmpty(v int8)
- func (enc *Encoder) AddIntKey(key string, v int)
- func (enc *Encoder) AddIntKeyNullEmpty(key string, v int)
- func (enc *Encoder) AddIntKeyOmitEmpty(key string, v int)
- func (enc *Encoder) AddIntNullEmpty(v int)
- func (enc *Encoder) AddIntOmitEmpty(v int)
- func (enc *Encoder) AddInterface(value interface{})
- func (enc *Encoder) AddInterfaceKey(key string, value interface{})
- func (enc *Encoder) AddInterfaceKeyOmitEmpty(key string, v interface{})
- func (enc *Encoder) AddNull()
- func (enc *Encoder) AddNullKey(key string)
- func (enc *Encoder) AddObject(v MarshalerJSONObject)
- func (enc *Encoder) AddObjectKey(key string, v MarshalerJSONObject)
- func (enc *Encoder) AddObjectKeyNullEmpty(key string, v MarshalerJSONObject)
- func (enc *Encoder) AddObjectKeyOmitEmpty(key string, v MarshalerJSONObject)
- func (enc *Encoder) AddObjectNullEmpty(v MarshalerJSONObject)
- func (enc *Encoder) AddObjectOmitEmpty(v MarshalerJSONObject)
- func (enc *Encoder) AddSQLNullBool(v *sql.NullBool)
- func (enc *Encoder) AddSQLNullBoolKey(key string, v *sql.NullBool)
- func (enc *Encoder) AddSQLNullBoolKeyNullEmpty(key string, v *sql.NullBool)
- func (enc *Encoder) AddSQLNullBoolKeyOmitEmpty(key string, v *sql.NullBool)
- func (enc *Encoder) AddSQLNullBoolOmitEmpty(v *sql.NullBool)
- func (enc *Encoder) AddSQLNullFloat64(v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullFloat64Key(key string, v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullFloat64NullEmpty(v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullFloat64OmitEmpty(v *sql.NullFloat64)
- func (enc *Encoder) AddSQLNullInt64(v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullInt64Key(key string, v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullInt64KeyNullEmpty(key string, v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullInt64KeyOmitEmpty(key string, v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullInt64NullEmpty(v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullInt64OmitEmpty(v *sql.NullInt64)
- func (enc *Encoder) AddSQLNullString(v *sql.NullString)
- func (enc *Encoder) AddSQLNullStringKey(key string, v *sql.NullString)
- func (enc *Encoder) AddSQLNullStringKeyOmitEmpty(key string, v *sql.NullString)
- func (enc *Encoder) AddSQLNullStringNullEmpty(v *sql.NullString)
- func (enc *Encoder) AddSQLNullStringOmitEmpty(v *sql.NullString)
- func (enc *Encoder) AddSliceBool(s []bool)
- func (enc *Encoder) AddSliceBoolKey(k string, s []bool)
- func (enc *Encoder) AddSliceFloat64(s []float64)
- func (enc *Encoder) AddSliceFloat64Key(k string, s []float64)
- func (enc *Encoder) AddSliceInt(s []int)
- func (enc *Encoder) AddSliceIntKey(k string, s []int)
- func (enc *Encoder) AddSliceString(s []string)
- func (enc *Encoder) AddSliceStringKey(k string, s []string)
- func (enc *Encoder) AddString(v string)
- func (enc *Encoder) AddStringKey(key, v string)
- func (enc *Encoder) AddStringKeyNullEmpty(key, v string)
- func (enc *Encoder) AddStringKeyOmitEmpty(key, v string)
- func (enc *Encoder) AddStringNullEmpty(v string)
- func (enc *Encoder) AddStringOmitEmpty(v string)
- func (enc *Encoder) AddTime(t *time.Time, format string)
- func (enc *Encoder) AddTimeKey(key string, t *time.Time, format string)
- func (enc *Encoder) AddUint16(v uint16)
- func (enc *Encoder) AddUint16Key(key string, v uint16)
- func (enc *Encoder) AddUint16KeyNullEmpty(key string, v uint16)
- func (enc *Encoder) AddUint16KeyOmitEmpty(key string, v uint16)
- func (enc *Encoder) AddUint16NullEmpty(v uint16)
- func (enc *Encoder) AddUint16OmitEmpty(v uint16)
- func (enc *Encoder) AddUint32(v uint32)
- func (enc *Encoder) AddUint32Key(key string, v uint32)
- func (enc *Encoder) AddUint32KeyNullEmpty(key string, v uint32)
- func (enc *Encoder) AddUint32KeyOmitEmpty(key string, v uint32)
- func (enc *Encoder) AddUint32NullEmpty(v uint32)
- func (enc *Encoder) AddUint32OmitEmpty(v uint32)
- func (enc *Encoder) AddUint64(v uint64)
- func (enc *Encoder) AddUint64Key(key string, v uint64)
- func (enc *Encoder) AddUint64KeyNullEmpty(key string, v uint64)
- func (enc *Encoder) AddUint64KeyOmitEmpty(key string, v uint64)
- func (enc *Encoder) AddUint64NullEmpty(v uint64)
- func (enc *Encoder) AddUint64OmitEmpty(v uint64)
- func (enc *Encoder) AddUint8(v uint8)
- func (enc *Encoder) AddUint8Key(key string, v uint8)
- func (enc *Encoder) AddUint8KeyNullEmpty(key string, v uint8)
- func (enc *Encoder) AddUint8KeyOmitEmpty(key string, v uint8)
- func (enc *Encoder) AddUint8NullEmpty(v uint8)
- func (enc *Encoder) AddUint8OmitEmpty(v uint8)
- func (enc *Encoder) AppendByte(b byte)
- func (enc *Encoder) AppendBytes(b []byte)
- func (enc *Encoder) AppendString(v string)
- func (enc *Encoder) Array(v MarshalerJSONArray)
- func (enc *Encoder) ArrayKey(key string, v MarshalerJSONArray)
- func (enc *Encoder) ArrayKeyNullEmpty(key string, v MarshalerJSONArray)
- func (enc *Encoder) ArrayKeyOmitEmpty(key string, v MarshalerJSONArray)
- func (enc *Encoder) ArrayNullEmpty(v MarshalerJSONArray)
- func (enc *Encoder) ArrayOmitEmpty(v MarshalerJSONArray)
- func (enc *Encoder) Bool(v bool)
- func (enc *Encoder) BoolKey(key string, value bool)
- func (enc *Encoder) BoolKeyNullEmpty(key string, v bool)
- func (enc *Encoder) BoolKeyOmitEmpty(key string, v bool)
- func (enc *Encoder) BoolNullEmpty(v bool)
- func (enc *Encoder) BoolOmitEmpty(v bool)
- func (enc *Encoder) Buf() []byte
- func (enc *Encoder) Encode(v interface{}) error
- func (enc *Encoder) EncodeArray(v MarshalerJSONArray) error
- func (enc *Encoder) EncodeBool(v bool) error
- func (enc *Encoder) EncodeEmbeddedJSON(v *EmbeddedJSON) error
- func (enc *Encoder) EncodeFloat(n float64) error
- func (enc *Encoder) EncodeFloat32(n float32) error
- func (enc *Encoder) EncodeInt(n int) error
- func (enc *Encoder) EncodeInt64(n int64) error
- func (enc *Encoder) EncodeObject(v MarshalerJSONObject) error
- func (enc *Encoder) EncodeObjectKeys(v MarshalerJSONObject, keys []string) error
- func (enc *Encoder) EncodeSQLNullBool(v *sql.NullBool) error
- func (enc *Encoder) EncodeSQLNullFloat64(v *sql.NullFloat64) error
- func (enc *Encoder) EncodeSQLNullInt64(v *sql.NullInt64) error
- func (enc *Encoder) EncodeSQLNullString(v *sql.NullString) error
- func (enc *Encoder) EncodeString(s string) error
- func (enc *Encoder) EncodeTime(t *time.Time, format string) error
- func (enc *Encoder) EncodeUint64(n uint64) error
- func (enc *Encoder) Float(v float64)
- func (enc *Encoder) Float32(v float32)
- func (enc *Encoder) Float32Key(key string, v float32)
- func (enc *Encoder) Float32KeyNullEmpty(key string, v float32)
- func (enc *Encoder) Float32KeyOmitEmpty(key string, v float32)
- func (enc *Encoder) Float32NullEmpty(v float32)
- func (enc *Encoder) Float32OmitEmpty(v float32)
- func (enc *Encoder) Float64(v float64)
- func (enc *Encoder) Float64Key(key string, value float64)
- func (enc *Encoder) Float64KeyNullEmpty(key string, v float64)
- func (enc *Encoder) Float64KeyOmitEmpty(key string, v float64)
- func (enc *Encoder) Float64NullEmpty(v float64)
- func (enc *Encoder) Float64OmitEmpty(v float64)
- func (enc *Encoder) FloatKey(key string, v float64)
- func (enc *Encoder) FloatKeyNullEmpty(key string, v float64)
- func (enc *Encoder) FloatKeyOmitEmpty(key string, v float64)
- func (enc *Encoder) FloatNullEmpty(v float64)
- func (enc *Encoder) FloatOmitEmpty(v float64)
- func (enc *Encoder) Int(v int)
- func (enc *Encoder) Int16(v int16)
- func (enc *Encoder) Int16Key(key string, v int16)
- func (enc *Encoder) Int16KeyNullEmpty(key string, v int16)
- func (enc *Encoder) Int16KeyOmitEmpty(key string, v int16)
- func (enc *Encoder) Int16NullEmpty(v int16)
- func (enc *Encoder) Int16OmitEmpty(v int16)
- func (enc *Encoder) Int32(v int32)
- func (enc *Encoder) Int32Key(key string, v int32)
- func (enc *Encoder) Int32KeyNullEmpty(key string, v int32)
- func (enc *Encoder) Int32KeyOmitEmpty(key string, v int32)
- func (enc *Encoder) Int32NullEmpty(v int32)
- func (enc *Encoder) Int32OmitEmpty(v int32)
- func (enc *Encoder) Int64(v int64)
- func (enc *Encoder) Int64Key(key string, v int64)
- func (enc *Encoder) Int64KeyNullEmpty(key string, v int64)
- func (enc *Encoder) Int64KeyOmitEmpty(key string, v int64)
- func (enc *Encoder) Int64NullEmpty(v int64)
- func (enc *Encoder) Int64OmitEmpty(v int64)
- func (enc *Encoder) Int8(v int8)
- func (enc *Encoder) Int8Key(key string, v int8)
- func (enc *Encoder) Int8KeyNullEmpty(key string, v int8)
- func (enc *Encoder) Int8KeyOmitEmpty(key string, v int8)
- func (enc *Encoder) Int8NullEmpty(v int8)
- func (enc *Encoder) Int8OmitEmpty(v int8)
- func (enc *Encoder) IntKey(key string, v int)
- func (enc *Encoder) IntKeyNullEmpty(key string, v int)
- func (enc *Encoder) IntKeyOmitEmpty(key string, v int)
- func (enc *Encoder) IntNullEmpty(v int)
- func (enc *Encoder) IntOmitEmpty(v int)
- func (enc *Encoder) Null()
- func (enc *Encoder) NullKey(key string)
- func (enc *Encoder) Object(v MarshalerJSONObject)
- func (enc *Encoder) ObjectKey(key string, v MarshalerJSONObject)
- func (enc *Encoder) ObjectKeyNullEmpty(key string, v MarshalerJSONObject)
- func (enc *Encoder) ObjectKeyOmitEmpty(key string, v MarshalerJSONObject)
- func (enc *Encoder) ObjectKeyWithKeys(key string, value MarshalerJSONObject, keys []string)
- func (enc *Encoder) ObjectNullEmpty(v MarshalerJSONObject)
- func (enc *Encoder) ObjectOmitEmpty(v MarshalerJSONObject)
- func (enc *Encoder) ObjectWithKeys(v MarshalerJSONObject, keys []string)
- func (enc *Encoder) Release()
- func (enc *Encoder) SQLNullBool(v *sql.NullBool)
- func (enc *Encoder) SQLNullBoolKey(key string, v *sql.NullBool)
- func (enc *Encoder) SQLNullBoolKeyNullEmpty(key string, v *sql.NullBool)
- func (enc *Encoder) SQLNullBoolKeyOmitEmpty(key string, v *sql.NullBool)
- func (enc *Encoder) SQLNullBoolNullEmpty(v *sql.NullBool)
- func (enc *Encoder) SQLNullBoolOmitEmpty(v *sql.NullBool)
- func (enc *Encoder) SQLNullFloat64(v *sql.NullFloat64)
- func (enc *Encoder) SQLNullFloat64Key(key string, v *sql.NullFloat64)
- func (enc *Encoder) SQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64)
- func (enc *Encoder) SQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64)
- func (enc *Encoder) SQLNullFloat64NullEmpty(v *sql.NullFloat64)
- func (enc *Encoder) SQLNullFloat64OmitEmpty(v *sql.NullFloat64)
- func (enc *Encoder) SQLNullInt64(v *sql.NullInt64)
- func (enc *Encoder) SQLNullInt64Key(key string, v *sql.NullInt64)
- func (enc *Encoder) SQLNullInt64KeyNullEmpty(key string, v *sql.NullInt64)
- func (enc *Encoder) SQLNullInt64KeyOmitEmpty(key string, v *sql.NullInt64)
- func (enc *Encoder) SQLNullInt64NullEmpty(v *sql.NullInt64)
- func (enc *Encoder) SQLNullInt64OmitEmpty(v *sql.NullInt64)
- func (enc *Encoder) SQLNullString(v *sql.NullString)
- func (enc *Encoder) SQLNullStringKey(key string, v *sql.NullString)
- func (enc *Encoder) SQLNullStringKeyNullEmpty(key string, v *sql.NullString)
- func (enc *Encoder) SQLNullStringKeyOmitEmpty(key string, v *sql.NullString)
- func (enc *Encoder) SQLNullStringNullEmpty(v *sql.NullString)
- func (enc *Encoder) SQLNullStringOmitEmpty(v *sql.NullString)
- func (enc *Encoder) SliceBool(s []bool)
- func (enc *Encoder) SliceBoolKey(k string, s []bool)
- func (enc *Encoder) SliceFloat64(s []float64)
- func (enc *Encoder) SliceFloat64Key(k string, s []float64)
- func (enc *Encoder) SliceInt(s []int)
- func (enc *Encoder) SliceIntKey(k string, s []int)
- func (enc *Encoder) SliceString(s []string)
- func (enc *Encoder) SliceStringKey(k string, s []string)
- func (enc *Encoder) String(v string)
- func (enc *Encoder) StringKey(key, v string)
- func (enc *Encoder) StringKeyNullEmpty(key, v string)
- func (enc *Encoder) StringKeyOmitEmpty(key, v string)
- func (enc *Encoder) StringNullEmpty(v string)
- func (enc *Encoder) StringOmitEmpty(v string)
- func (enc *Encoder) Time(t *time.Time, format string)
- func (enc *Encoder) TimeKey(key string, t *time.Time, format string)
- func (enc *Encoder) Uint16(v uint16)
- func (enc *Encoder) Uint16Key(key string, v uint16)
- func (enc *Encoder) Uint16KeyNullEmpty(key string, v uint16)
- func (enc *Encoder) Uint16KeyOmitEmpty(key string, v uint16)
- func (enc *Encoder) Uint16NullEmpty(v uint16)
- func (enc *Encoder) Uint16OmitEmpty(v uint16)
- func (enc *Encoder) Uint32(v uint32)
- func (enc *Encoder) Uint32Key(key string, v uint32)
- func (enc *Encoder) Uint32KeyNullEmpty(key string, v uint32)
- func (enc *Encoder) Uint32KeyOmitEmpty(key string, v uint32)
- func (enc *Encoder) Uint32NullEmpty(v uint32)
- func (enc *Encoder) Uint32OmitEmpty(v uint32)
- func (enc *Encoder) Uint64(v uint64)
- func (enc *Encoder) Uint64Key(key string, v uint64)
- func (enc *Encoder) Uint64KeyNullEmpty(key string, v uint64)
- func (enc *Encoder) Uint64KeyOmitEmpty(key string, v uint64)
- func (enc *Encoder) Uint64NullEmpty(v uint64)
- func (enc *Encoder) Uint64OmitEmpty(v uint64)
- func (enc *Encoder) Uint8(v uint8)
- func (enc *Encoder) Uint8Key(key string, v uint8)
- func (enc *Encoder) Uint8KeyNullEmpty(key string, v uint8)
- func (enc *Encoder) Uint8KeyOmitEmpty(key string, v uint8)
- func (enc *Encoder) Uint8NullEmpty(v uint8)
- func (enc *Encoder) Uint8OmitEmpty(v uint8)
- func (enc *Encoder) Write() (int, error)
- type InvalidJSONError
- type InvalidMarshalError
- type InvalidUnmarshalError
- type InvalidUsagePooledDecoderError
- type InvalidUsagePooledEncoderError
- type MarshalerJSONArray
- type MarshalerJSONObject
- type MarshalerStream
- type NoReaderError
- type StreamDecoder
- func (dec *StreamDecoder) Deadline() (time.Time, bool)
- func (dec *StreamDecoder) DecodeStream(c UnmarshalerStream) error
- func (dec *StreamDecoder) Done() <-chan struct{}
- func (dec *StreamDecoder) Err() error
- func (dec *StreamDecoder) Release()
- func (dec *StreamDecoder) SetDeadline(t time.Time)
- func (dec *StreamDecoder) Value(key interface{}) interface{}
- type StreamEncoder
- func (s *StreamEncoder) AddArray(v MarshalerJSONArray)
- func (s *StreamEncoder) AddFloat(value float64)
- func (s *StreamEncoder) AddFloat64(value float64)
- func (s *StreamEncoder) AddInt(value int)
- func (s *StreamEncoder) AddObject(v MarshalerJSONObject)
- func (s *StreamEncoder) AddString(v string)
- func (s *StreamEncoder) Cancel(err error)
- func (s *StreamEncoder) CommaDelimited() *StreamEncoder
- func (s *StreamEncoder) Deadline() (time.Time, bool)
- func (s *StreamEncoder) Done() <-chan struct{}
- func (s *StreamEncoder) EncodeStream(m MarshalerStream)
- func (s *StreamEncoder) Err() error
- func (s *StreamEncoder) LineDelimited() *StreamEncoder
- func (s *StreamEncoder) NConsumer(n int) *StreamEncoder
- func (s *StreamEncoder) Release()
- func (s *StreamEncoder) SetDeadline(t time.Time)
- func (s *StreamEncoder) Value(key interface{}) interface{}
- type UnmarshalerJSONArray
- type UnmarshalerJSONObject
- type UnmarshalerStream
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnmarshalPtrExpected = errors.New("Cannot unmarshal to given value, a pointer is expected")
ErrUnmarshalPtrExpected is the error returned when unmarshal expects a pointer value, When using `dec.ObjectNull` or `dec.ArrayNull` for example.
var Stream = stream{}
Stream is a struct holding the Stream api
var Unsafe = decUnsafe{}
Unsafe is the structure holding the unsafe version of the API. The difference between unsafe api and regular api is that the regular API copies the buffer passed to Unmarshal functions to a new internal buffer. Making it safer because internally GoJay uses unsafe.Pointer to transform slice of bytes into a string.
Functions ¶
func Marshal ¶
Marshal returns the JSON encoding of v.
If v is nil, not an implementation MarshalerJSONObject or MarshalerJSONArray or not one of the following types:
string, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float64, float32, bool
Marshal returns an InvalidMarshalError.
Example (Bool) ¶
package main import ( "fmt" "log" "github.com/francoispqt/gojay" ) func main() { b := true d, err := gojay.Marshal(b) if err != nil { log.Fatal(err) } fmt.Println(string(d)) // true }
Output:
Example (String) ¶
package main import ( "fmt" "log" "github.com/francoispqt/gojay" ) func main() { str := "gojay" d, err := gojay.Marshal(str) if err != nil { log.Fatal(err) } fmt.Println(string(d)) // "gojay" }
Output:
func MarshalAny ¶
MarshalAny returns the JSON encoding of v.
If v is nil, not an implementation MarshalerJSONObject or MarshalerJSONArray or not one of the following types:
string, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float64, float32, bool
MarshalAny falls back to "json/encoding" package to marshal the value.
func MarshalJSONArray ¶
func MarshalJSONArray(v MarshalerJSONArray) ([]byte, error)
MarshalJSONArray returns the JSON encoding of v, an implementation of MarshalerJSONArray.
Example:
type TestSlice []*TestStruct func (t TestSlice) MarshalJSONArray(enc *Encoder) { for _, e := range t { enc.AddObject(e) } } func main() { test := &TestSlice{ &TestStruct{123456}, &TestStruct{7890}, } b, _ := Marshal(test) fmt.Println(b) // [{"id":123456},{"id":7890}] }
func MarshalJSONObject ¶
func MarshalJSONObject(v MarshalerJSONObject) ([]byte, error)
MarshalJSONObject returns the JSON encoding of v, an implementation of MarshalerJSONObject.
Example:
type Object struct { id int } func (s *Object) MarshalJSONObject(enc *gojay.Encoder) { enc.IntKey("id", s.id) } func (s *Object) IsNil() bool { return s == nil } func main() { test := &Object{ id: 123456, } b, _ := gojay.Marshal(test) fmt.Println(b) // {"id":123456} }
func Unmarshal ¶
Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil, not an implementation of UnmarshalerJSONObject or UnmarshalerJSONArray or not one of the following types:
*string, **string, *int, **int, *int8, **int8, *int16, **int16, *int32, **int32, *int64, **int64, *uint8, **uint8, *uint16, **uint16, *uint32, **uint32, *uint64, **uint64, *float64, **float64, *float32, **float32, *bool, **bool
Unmarshal returns an InvalidUnmarshalError.
If a JSON value is not appropriate for a given target type, or if a JSON number overflows the target type, Unmarshal skips that field and completes the unmarshaling as best it can. If no more serious errors are encountered, Unmarshal returns an UnmarshalTypeError describing the earliest such error. In any case, it's not guaranteed that all the remaining fields following the problematic one will be unmarshaled into the target object.
Example (Bool) ¶
package main import ( "fmt" "log" "github.com/francoispqt/gojay" ) func main() { data := []byte(`true`) var b bool err := gojay.Unmarshal(data, &b) if err != nil { log.Fatal(err) } fmt.Println(b) // true }
Output:
Example (InvalidType) ¶
package main import ( "fmt" "github.com/francoispqt/gojay" ) func main() { data := []byte(`"gojay"`) someStruct := struct{}{} err := gojay.Unmarshal(data, &someStruct) fmt.Println(err) // "Cannot unmarshal JSON to type '*struct{}'" }
Output:
Example (String) ¶
package main import ( "fmt" "log" "github.com/francoispqt/gojay" ) func main() { data := []byte(`"gojay"`) var str string err := gojay.Unmarshal(data, &str) if err != nil { log.Fatal(err) } fmt.Println(str) // true }
Output:
func UnmarshalJSONArray ¶
func UnmarshalJSONArray(data []byte, v UnmarshalerJSONArray) error
UnmarshalJSONArray parses the JSON-encoded data and stores the result in the value pointed to by v.
v must implement UnmarshalerJSONArray.
If a JSON value is not appropriate for a given target type, or if a JSON number overflows the target type, UnmarshalJSONArray skips that field and completes the unmarshaling as best it can.
func UnmarshalJSONObject ¶
func UnmarshalJSONObject(data []byte, v UnmarshalerJSONObject) error
UnmarshalJSONObject parses the JSON-encoded data and stores the result in the value pointed to by v.
v must implement UnmarshalerJSONObject.
If a JSON value is not appropriate for a given target type, or if a JSON number overflows the target type, UnmarshalJSONObject skips that field and completes the unmarshaling as best it can.
func UnmarshalJSONObjectWithPool ¶ added in v1.2.14
func UnmarshalJSONObjectWithPool(data []byte, v UnmarshalerJSONObject) error
UnmarshalJSONObjectWithPool Same as UnmarshalJSONObject but with using of bytebufferpool to get less memory allocations
v must implement UnmarshalerJSONObject.
Types ¶
type ByteBuffer ¶ added in v1.2.16
type ByteBuffer struct { B []byte // contains filtered or unexported fields }
func (*ByteBuffer) Len ¶ added in v1.2.16
func (b *ByteBuffer) Len() int
func (*ByteBuffer) Release ¶ added in v1.2.16
func (b *ByteBuffer) Release()
func (*ByteBuffer) Set ¶ added in v1.2.16
func (b *ByteBuffer) Set(p []byte)
type DecodeArrayFunc ¶
Example ¶
package main import ( "fmt" "log" "strings" "github.com/francoispqt/gojay" ) func main() { reader := strings.NewReader(`[ "foo", "bar" ]`) dec := gojay.NewDecoder(reader) strSlice := make([]string, 0) err := dec.DecodeArray(gojay.DecodeArrayFunc(func(dec *gojay.Decoder) error { var str string if err := dec.AddString(&str); err != nil { return err } strSlice = append(strSlice, str) return nil })) if err != nil { log.Fatal(err) } fmt.Print(strSlice) }
Output: [foo bar]
func (DecodeArrayFunc) IsNil ¶
func (f DecodeArrayFunc) IsNil() bool
IsNil implements UnmarshalerJSONArray.
func (DecodeArrayFunc) UnmarshalJSONArray ¶
func (f DecodeArrayFunc) UnmarshalJSONArray(dec *Decoder) error
UnmarshalJSONArray implements UnmarshalerJSONArray.
type DecodeObjectFunc ¶
DecodeObjectFunc is a func type implementing UnmarshalerJSONObject. Use it to cast a `func(*Decoder, k string) error` to Unmarshal an object on the fly.
Example ¶
package main import ( "fmt" "strings" "github.com/francoispqt/gojay" ) func main() { reader := strings.NewReader(`{ "name": "John Doe", "email": "john.doe@email.com" }`) dec := gojay.NewDecoder(reader) user := struct { name string email string }{} dec.DecodeObject(gojay.DecodeObjectFunc(func(dec *gojay.Decoder, k string) error { switch k { case "name": return dec.String(&user.name) case "email": return dec.String(&user.email) } return nil })) fmt.Printf("User\nname: %s\nemail: %s", user.name, user.email) }
Output: User name: John Doe email: john.doe@email.com
func (DecodeObjectFunc) NKeys ¶
func (f DecodeObjectFunc) NKeys() int
NKeys implements UnmarshalerJSONObject.
func (DecodeObjectFunc) UnmarshalJSONObject ¶
func (f DecodeObjectFunc) UnmarshalJSONObject(dec *Decoder, k string) error
UnmarshalJSONObject implements UnmarshalerJSONObject.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes JSON values from an input stream.
func BorrowDecoder ¶
BorrowDecoder borrows a Decoder from the pool. It takes an io.Reader implementation as data input.
In order to benefit from the pool, a borrowed decoder must be released after usage.
Example ¶
package main import ( "fmt" "log" "strings" "github.com/francoispqt/gojay" ) func main() { reader := strings.NewReader(`"gojay"`) dec := gojay.BorrowDecoder(reader) defer dec.Release() var str string err := dec.DecodeString(&str) if err != nil { log.Fatal(err) } fmt.Println(str) }
Output: gojay
func NewDecoder ¶
NewDecoder returns a new decoder. It takes an io.Reader implementation as data input.
Example ¶
package main import ( "fmt" "log" "strings" "github.com/francoispqt/gojay" ) func main() { reader := strings.NewReader(`"gojay"`) dec := gojay.NewDecoder(reader) var str string err := dec.DecodeString(&str) if err != nil { log.Fatal(err) } fmt.Println(str) }
Output: gojay
func (*Decoder) AddArray ¶
func (dec *Decoder) AddArray(v UnmarshalerJSONArray) error
AddArray decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (*Decoder) AddArrayNull ¶
AddArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (*Decoder) AddBool ¶
AddBool decodes the JSON value within an object or an array to a *bool. If next key is neither null nor a JSON boolean, an InvalidUnmarshalError will be returned. If next key is null, bool will be false.
func (*Decoder) AddBoolNull ¶
AddBoolNull decodes the JSON value within an object or an array to a *bool. If next key is neither null nor a JSON boolean, an InvalidUnmarshalError will be returned. If next key is null, bool will be false. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddEmbeddedJSON ¶
func (dec *Decoder) AddEmbeddedJSON(v *EmbeddedJSON) error
AddEmbeddedJSON adds an EmbeddedsJSON to the value pointed by v. It can be used to delay JSON decoding or precompute a JSON encoding.
func (*Decoder) AddFloat ¶
AddFloat decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddFloat32 ¶
AddFloat32 decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddFloat32Null ¶
AddFloat32Null decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddFloat64 ¶
AddFloat64 decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddFloat64Null ¶
AddFloat64Null decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddFloatNull ¶
AddFloatNull decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddInt ¶
AddInt decodes the JSON value within an object or an array to an *int. If next key value overflows int, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddInt16 ¶
AddInt16 decodes the JSON value within an object or an array to an *int. If next key value overflows int16, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddInt16Null ¶
AddInt16Null decodes the JSON value within an object or an array to an *int. If next key value overflows int16, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddInt32 ¶
AddInt32 decodes the JSON value within an object or an array to an *int. If next key value overflows int32, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddInt32Null ¶
AddInt32Null decodes the JSON value within an object or an array to an *int. If next key value overflows int32, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddInt64 ¶
AddInt64 decodes the JSON value within an object or an array to an *int. If next key value overflows int64, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddInt64Null ¶
AddInt64Null decodes the JSON value within an object or an array to an *int. If next key value overflows int64, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddInt8 ¶
AddInt8 decodes the JSON value within an object or an array to an *int. If next key value overflows int8, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddInt8Null ¶
AddInt8Null decodes the JSON value within an object or an array to an *int. If next key value overflows int8, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddIntNull ¶
AddIntNull decodes the JSON value within an object or an array to an *int. If next key value overflows int, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddInterface ¶
AddInterface decodes the JSON value within an object or an array to a interface{}.
func (*Decoder) AddObject ¶
func (dec *Decoder) AddObject(v UnmarshalerJSONObject) error
AddObject decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (*Decoder) AddObjectNull ¶
AddObjectNull decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (*Decoder) AddSQLNullBool ¶
AddSQLNullBool decodes the JSON value within an object or an array to an *sql.NullBool
func (*Decoder) AddSQLNullFloat64 ¶
func (dec *Decoder) AddSQLNullFloat64(v *sql.NullFloat64) error
AddSQLNullFloat64 decodes the JSON value within an object or an array to qn *sql.NullFloat64
func (*Decoder) AddSQLNullInt64 ¶
AddSQLNullInt64 decodes the JSON value within an object or an array to qn *sql.NullInt64
func (*Decoder) AddSQLNullString ¶
func (dec *Decoder) AddSQLNullString(v *sql.NullString) error
AddSQLNullString decodes the JSON value within an object or an array to qn *sql.NullString
func (*Decoder) AddSliceBool ¶
AddBool unmarshals the next JSON array of boolegers to the given *[]bool s
func (*Decoder) AddSliceFloat64 ¶
AddFloat64 unmarshals the next JSON array of floats to the given *[]float64 s
func (*Decoder) AddSliceInt ¶
AddSliceInt unmarshals the next JSON array of integers to the given *[]int s
func (*Decoder) AddSliceString ¶
AddSliceString unmarshals the next JSON array of strings to the given *[]string s
func (*Decoder) AddString ¶
AddString decodes the JSON value within an object or an array to a *string. If next key is not a JSON string nor null, InvalidUnmarshalError will be returned.
func (*Decoder) AddStringNull ¶
AddStringNull decodes the JSON value within an object or an array to a *string. If next key is not a JSON string nor null, InvalidUnmarshalError will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddTime ¶
AddTime decodes the JSON value within an object or an array to a *time.Time with the given format
func (*Decoder) AddUint16 ¶
AddUint16 decodes the JSON value within an object or an array to an *int. If next key value overflows uint16, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddUint16Null ¶
AddUint16Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint16, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddUint32 ¶
AddUint32 decodes the JSON value within an object or an array to an *int. If next key value overflows uint32, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddUint32Null ¶
AddUint32Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint32, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddUint64 ¶
AddUint64 decodes the JSON value within an object or an array to an *int. If next key value overflows uint64, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddUint64Null ¶
AddUint64Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint64, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) AddUint8 ¶
AddUint8 decodes the JSON value within an object or an array to an *int. If next key value overflows uint8, an InvalidUnmarshalError error will be returned.
func (*Decoder) AddUint8Null ¶
AddUint8Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint8, an InvalidUnmarshalError error will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) Array ¶
func (dec *Decoder) Array(v UnmarshalerJSONArray) error
Array decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (*Decoder) ArrayNull ¶
ArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray. v should be a pointer to an UnmarshalerJSONArray, if `null` value is encountered in JSON, it will leave the value v untouched, else it will create a new instance of the UnmarshalerJSONArray behind v.
func (*Decoder) Bool ¶
Bool decodes the JSON value within an object or an array to a *bool. If next key is neither null nor a JSON boolean, an InvalidUnmarshalError will be returned. If next key is null, bool will be false.
func (*Decoder) BoolNull ¶
BoolNull decodes the JSON value within an object or an array to a *bool. If next key is neither null nor a JSON boolean, an InvalidUnmarshalError will be returned. If next key is null, bool will be false.
func (*Decoder) Decode ¶
Decode reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value. The differences between Decode and Unmarshal are:
- Decode reads from an io.Reader in the Decoder, whereas Unmarshal reads from a []byte
- Decode leaves to the user the option of borrowing and releasing a Decoder, whereas Unmarshal internally always borrows a Decoder and releases it when the unmarshaling is completed
Example (String) ¶
package main import ( "fmt" "log" "strings" "github.com/francoispqt/gojay" ) func main() { var str string dec := gojay.BorrowDecoder(strings.NewReader(`"gojay"`)) err := dec.Decode(&str) dec.Release() if err != nil { log.Fatal(err) } fmt.Println(str) // "gojay" }
Output:
func (*Decoder) DecodeArray ¶
func (dec *Decoder) DecodeArray(v UnmarshalerJSONArray) error
DecodeArray reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by v.
v must implement UnmarshalerJSONArray.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeBool ¶
DecodeBool reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the boolean pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
Example ¶
package main import ( "fmt" "log" "strings" "github.com/francoispqt/gojay" ) func main() { reader := strings.NewReader(`true`) dec := gojay.NewDecoder(reader) var b bool err := dec.DecodeBool(&b) if err != nil { log.Fatal(err) } fmt.Println(b) }
Output: true
func (*Decoder) DecodeFloat32 ¶
DecodeFloat32 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the float32 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeFloat64 ¶
DecodeFloat64 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the float64 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInt ¶
DecodeInt reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the int pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInt16 ¶
DecodeInt16 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the int16 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInt32 ¶
DecodeInt32 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the int32 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInt64 ¶
DecodeInt64 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the int64 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInt8 ¶
DecodeInt8 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the int8 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeInterface ¶
DecodeInterface reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by i.
i must be an interface poiter
func (*Decoder) DecodeObject ¶
func (dec *Decoder) DecodeObject(j UnmarshalerJSONObject) error
DecodeObject reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by v.
v must implement UnmarshalerJSONObject.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeSQLNullBool ¶
DecodeSQLNullBool decodes a sql.NullString with the given format
func (*Decoder) DecodeSQLNullFloat64 ¶
func (dec *Decoder) DecodeSQLNullFloat64(v *sql.NullFloat64) error
DecodeSQLNullFloat64 decodes a sql.NullString with the given format
func (*Decoder) DecodeSQLNullInt64 ¶
DecodeSQLNullInt64 decodes a sql.NullInt64
func (*Decoder) DecodeSQLNullString ¶
func (dec *Decoder) DecodeSQLNullString(v *sql.NullString) error
DecodeSQLNullString decodes a sql.NullString
func (*Decoder) DecodeString ¶
DecodeString reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the string pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeTime ¶
DecodeTime decodes time with the given format
func (*Decoder) DecodeUint16 ¶
DecodeUint16 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the uint16 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeUint32 ¶
DecodeUint32 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the uint32 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeUint64 ¶
DecodeUint64 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the uint64 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) DecodeUint8 ¶
DecodeUint8 reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the uint8 pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) EmbeddedJSON ¶
func (dec *Decoder) EmbeddedJSON(v *EmbeddedJSON) error
EmbeddedJSON adds an EmbeddedsJSON to the value pointed by v. It can be used to delay JSON decoding or precompute a JSON encoding.
func (*Decoder) Float ¶
Float decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Float32 ¶
Float32 decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Float32Null ¶
Float32Null decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Float64 ¶
Float64 decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Float64Null ¶
Float64Null decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) FloatNull ¶
FloatNull decodes the JSON value within an object or an array to a *float64. If next key value overflows float64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int ¶
Int decodes the JSON value within an object or an array to an *int. If next key value overflows int, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int16 ¶
Int16 decodes the JSON value within an object or an array to an *int. If next key value overflows int16, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int16Null ¶
Int16Null decodes the JSON value within an object or an array to an *int. If next key value overflows int16, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int32 ¶
Int32 decodes the JSON value within an object or an array to an *int. If next key value overflows int32, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int32Null ¶
Int32Null decodes the JSON value within an object or an array to an *int. If next key value overflows int32, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int64 ¶
Int64 decodes the JSON value within an object or an array to an *int. If next key value overflows int64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int64Null ¶
Int64Null decodes the JSON value within an object or an array to an *int. If next key value overflows int64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int8 ¶
Int8 decodes the JSON value within an object or an array to an *int. If next key value overflows int8, an InvalidUnmarshalError error will be returned.
func (*Decoder) Int8Null ¶
Int8Null decodes the JSON value within an object or an array to an *int. If next key value overflows int8, an InvalidUnmarshalError error will be returned.
func (*Decoder) IntNull ¶
IntNull decodes the JSON value within an object or an array to an *int. If next key value overflows int, an InvalidUnmarshalError error will be returned.
func (*Decoder) Interface ¶
Interface decodes the JSON value within an object or an array to an interface{}.
func (*Decoder) Object ¶
func (dec *Decoder) Object(value UnmarshalerJSONObject) error
Object decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (*Decoder) ObjectNull ¶
ObjectNull decodes the JSON value within an object or an array to a UnmarshalerJSONObject. v should be a pointer to an UnmarshalerJSONObject, if `null` value is encountered in JSON, it will leave the value v untouched, else it will create a new instance of the UnmarshalerJSONObject behind v.
func (*Decoder) Release ¶
func (dec *Decoder) Release()
Release sends back a Decoder to the pool. If a decoder is used after calling Release a panic will be raised with an InvalidUsagePooledDecoderError error.
func (*Decoder) SQLNullBool ¶
SQLNullBool decodes the JSON value within an object or an array to an *sql.NullBool
func (*Decoder) SQLNullFloat64 ¶
func (dec *Decoder) SQLNullFloat64(v *sql.NullFloat64) error
SQLNullFloat64 decodes the JSON value within an object or an array to an *sql.NullFloat64
func (*Decoder) SQLNullInt64 ¶
SQLNullInt64 decodes the JSON value within an object or an array to an *sql.NullInt64
func (*Decoder) SQLNullString ¶
func (dec *Decoder) SQLNullString(v *sql.NullString) error
SQLNullString decodes the JSON value within an object or an array to an *sql.NullString
func (*Decoder) SliceBool ¶
SliceBool unmarshals the next JSON array of boolegers to the given *[]bool s
func (*Decoder) SliceFloat64 ¶
SliceFloat64 unmarshals the next JSON array of floats to the given *[]float64 s
func (*Decoder) SliceInt ¶
SliceInt unmarshals the next JSON array of integers to the given *[]int s
func (*Decoder) SliceString ¶
SliceString unmarshals the next JSON array of strings to the given *[]string s
func (*Decoder) String ¶
String decodes the JSON value within an object or an array to a *string. If next key is not a JSON string nor null, InvalidUnmarshalError will be returned.
func (*Decoder) StringNull ¶
StringNull decodes the JSON value within an object or an array to a **string. If next key is not a JSON string nor null, InvalidUnmarshalError will be returned. If a `null` is encountered, gojay does not change the value of the pointer.
func (*Decoder) Time ¶
Time decodes the JSON value within an object or an array to a *time.Time with the given format
func (*Decoder) Uint16 ¶
Uint16 decodes the JSON value within an object or an array to an *int. If next key value overflows uint16, an InvalidUnmarshalError error will be returned.
func (*Decoder) Uint16Null ¶
Uint16Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint16, an InvalidUnmarshalError error will be returned.
func (*Decoder) Uint32 ¶
Uint32 decodes the JSON value within an object or an array to an *int. If next key value overflows uint32, an InvalidUnmarshalError error will be returned.
func (*Decoder) Uint32Null ¶
Uint32Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint32, an InvalidUnmarshalError error will be returned.
func (*Decoder) Uint64 ¶
Uint64 decodes the JSON value within an object or an array to an *int. If next key value overflows uint64, an InvalidUnmarshalError error will be returned.
func (*Decoder) Uint64Null ¶
Uint64Null decodes the JSON value within an object or an array to an *int. If next key value overflows uint64, an InvalidUnmarshalError error will be returned.
type EmbeddedJSON ¶
type EmbeddedJSON []byte
EmbeddedJSON is a raw encoded JSON value. It can be used to delay JSON decoding or precompute a JSON encoding.
type EncodeArrayFunc ¶
type EncodeArrayFunc func(*Encoder)
EncodeArrayFunc is a custom func type implementing MarshaleArray. Use it to cast a func(*Encoder) to Marshal an object.
enc := gojay.NewEncoder(io.Writer) enc.EncodeArray(gojay.EncodeArrayFunc(func(enc *gojay.Encoder) { enc.AddStringKey("hello", "world") }))
func (EncodeArrayFunc) IsNil ¶
func (f EncodeArrayFunc) IsNil() bool
IsNil implements MarshalerJSONArray.
func (EncodeArrayFunc) MarshalJSONArray ¶
func (f EncodeArrayFunc) MarshalJSONArray(enc *Encoder)
MarshalJSONArray implements MarshalerJSONArray.
type EncodeObjectFunc ¶
type EncodeObjectFunc func(*Encoder)
EncodeObjectFunc is a custom func type implementing MarshaleObject. Use it to cast a func(*Encoder) to Marshal an object.
enc := gojay.NewEncoder(io.Writer) enc.EncodeObject(gojay.EncodeObjectFunc(func(enc *gojay.Encoder) { enc.AddStringKey("hello", "world") }))
func (EncodeObjectFunc) IsNil ¶
func (f EncodeObjectFunc) IsNil() bool
IsNil implements MarshalerJSONObject.
func (EncodeObjectFunc) MarshalJSONObject ¶
func (f EncodeObjectFunc) MarshalJSONObject(enc *Encoder)
MarshalJSONObject implements MarshalerJSONObject.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes JSON values to an output stream.
func BorrowEncoder ¶
BorrowEncoder borrows an Encoder from the pool.
Example ¶
package main import ( "log" "os" "github.com/francoispqt/gojay" ) func main() { enc := gojay.BorrowEncoder(os.Stdout) defer enc.Release() var str = "gojay" err := enc.EncodeString(str) if err != nil { log.Fatal(err) } }
Output: "gojay"
func NewEncoder ¶
NewEncoder returns a new encoder or borrows one from the pool
Example ¶
package main import ( "log" "os" "github.com/francoispqt/gojay" ) func main() { enc := gojay.BorrowEncoder(os.Stdout) var str = "gojay" err := enc.EncodeString(str) if err != nil { log.Fatal(err) } }
Output: "gojay"
func (*Encoder) AddArray ¶
func (enc *Encoder) AddArray(v MarshalerJSONArray)
AddArray adds an implementation of MarshalerJSONArray to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement Marshaler
func (*Encoder) AddArrayKey ¶
func (enc *Encoder) AddArrayKey(key string, v MarshalerJSONArray)
AddArrayKey adds an array or slice to be encoded, must be used inside an object as it will encode a key value must implement Marshaler
func (*Encoder) AddArrayKeyNullEmpty ¶
func (enc *Encoder) AddArrayKeyNullEmpty(key string, v MarshalerJSONArray)
AddArrayKeyNullEmpty adds an array or slice to be encoded and skips it if it is nil. Must be called inside an object as it will encode a key. `null` will be encoded`
func (*Encoder) AddArrayKeyOmitEmpty ¶
func (enc *Encoder) AddArrayKeyOmitEmpty(key string, v MarshalerJSONArray)
AddArrayKeyOmitEmpty adds an array or slice to be encoded and skips it if it is nil. Must be called inside an object as it will encode a key.
func (*Encoder) AddArrayNullEmpty ¶
func (enc *Encoder) AddArrayNullEmpty(v MarshalerJSONArray)
AddArrayNullEmpty adds an array or slice to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement Marshaler, if v is empty, `null` will be encoded`
func (*Encoder) AddArrayOmitEmpty ¶
func (enc *Encoder) AddArrayOmitEmpty(v MarshalerJSONArray)
AddArrayOmitEmpty adds an array or slice to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerAddArrayOmitEmpty
func (*Encoder) AddBool ¶
AddBool adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddBoolKey ¶
AddBoolKey adds a bool to be encoded, must be used inside an object as it will encode a key.
func (*Encoder) AddBoolKeyNullEmpty ¶
AddBoolKeyNullEmpty adds a bool to be encoded and encodes `null` if it is zero value. Must be used inside an object as it will encode a key.
func (*Encoder) AddBoolKeyOmitEmpty ¶
AddBoolKeyOmitEmpty adds a bool to be encoded and skips if it is zero value. Must be used inside an object as it will encode a key.
func (*Encoder) AddBoolNullEmpty ¶
AddBoolNullEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddBoolOmitEmpty ¶
AddBoolOmitEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddEmbeddedJSON ¶
func (enc *Encoder) AddEmbeddedJSON(v *EmbeddedJSON)
AddEmbeddedJSON adds an EmbeddedJSON to be encoded.
It basically blindly writes the bytes to the final buffer. Therefore, it expects the JSON to be of proper format.
func (*Encoder) AddEmbeddedJSONKey ¶
func (enc *Encoder) AddEmbeddedJSONKey(key string, v *EmbeddedJSON)
AddEmbeddedJSONKey adds an EmbeddedJSON and a key to be encoded.
It basically blindly writes the bytes to the final buffer. Therefore, it expects the JSON to be of proper format.
func (*Encoder) AddEmbeddedJSONKeyOmitEmpty ¶
func (enc *Encoder) AddEmbeddedJSONKeyOmitEmpty(key string, v *EmbeddedJSON)
AddEmbeddedJSONKeyOmitEmpty adds an EmbeddedJSON and a key to be encoded or skips it if nil pointer or empty.
It basically blindly writes the bytes to the final buffer. Therefore, it expects the JSON to be of proper format.
func (*Encoder) AddEmbeddedJSONOmitEmpty ¶
func (enc *Encoder) AddEmbeddedJSONOmitEmpty(v *EmbeddedJSON)
AddEmbeddedJSONOmitEmpty adds an EmbeddedJSON to be encoded or skips it if nil pointer or empty.
It basically blindly writes the bytes to the final buffer. Therefore, it expects the JSON to be of proper format.
func (*Encoder) AddFloat ¶
AddFloat adds a float64 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddFloat32 ¶
AddFloat32 adds a float32 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddFloat32Key ¶
AddFloat32Key adds a float32 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddFloat32KeyNullEmpty ¶
AddFloat32KeyNullEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) AddFloat32KeyOmitEmpty ¶
AddFloat32KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) AddFloat32NullEmpty ¶
AddFloat32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddFloat32OmitEmpty ¶
AddFloat32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddFloat64 ¶
AddFloat64 adds a float64 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddFloat64Key ¶
AddFloat64Key adds a float64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddFloat64KeyOmitEmpty ¶
AddFloat64KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) AddFloat64OmitEmpty ¶
AddFloat64OmitEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddFloatKey ¶
AddFloatKey adds a float64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddFloatKeyNullEmpty ¶
AddFloatKeyNullEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) AddFloatKeyOmitEmpty ¶
AddFloatKeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) AddFloatNullEmpty ¶
AddFloatNullEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddFloatOmitEmpty ¶
AddFloatOmitEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt ¶
AddInt adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInt16 ¶
AddInt16 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInt16Key ¶
AddInt16Key adds an int16 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddInt16KeyNullEmpty ¶
AddInt16KeyNullEmpty adds an int16 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt16KeyOmitEmpty ¶
AddInt16KeyOmitEmpty adds an int16 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt16OmitEmpty ¶
AddInt16OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt32 ¶
AddInt32 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInt32Key ¶
AddInt32Key adds an int32 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddInt32KeyOmitEmpty ¶
AddInt32KeyOmitEmpty adds an int32 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt32NullEmpty ¶
AddInt32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt32OmitEmpty ¶
AddInt32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt64 ¶
AddInt64 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInt64Key ¶
AddInt64Key adds an int64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddInt64KeyNullEmpty ¶
AddInt64KeyNullEmpty adds an int64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt64KeyOmitEmpty ¶
AddInt64KeyOmitEmpty adds an int64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt64NullEmpty ¶
AddInt64NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt64OmitEmpty ¶
AddInt64OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt8 ¶
AddInt8 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInt8Key ¶
AddInt8Key adds an int8 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddInt8KeyNullEmpty ¶
AddInt8KeyNullEmpty adds an int8 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt8KeyOmitEmpty ¶
AddInt8KeyOmitEmpty adds an int8 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddInt8NullEmpty ¶
AddInt8NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInt8OmitEmpty ¶
AddInt8OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddIntKey ¶
AddIntKey adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddIntKeyNullEmpty ¶
AddIntKeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddIntKeyOmitEmpty ¶
AddIntKeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddIntNullEmpty ¶
AddIntNullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddIntOmitEmpty ¶
AddIntOmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddInterface ¶
func (enc *Encoder) AddInterface(value interface{})
AddInterface adds an interface{} to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddInterfaceKey ¶
AddInterfaceKey adds an interface{} to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddInterfaceKeyOmitEmpty ¶
AddInterfaceKeyOmitEmpty adds an interface{} to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddNull ¶
func (enc *Encoder) AddNull()
AddNull adds a `null` to be encoded. Must be used while encoding an array.`
func (*Encoder) AddNullKey ¶
AddNullKey adds a `null` to be encoded. Must be used while encoding an array.`
func (*Encoder) AddObject ¶
func (enc *Encoder) AddObject(v MarshalerJSONObject)
AddObject adds an object to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) AddObjectKey ¶
func (enc *Encoder) AddObjectKey(key string, v MarshalerJSONObject)
AddObjectKey adds a struct to be encoded, must be used inside an object as it will encode a key value must implement MarshalerJSONObject
func (*Encoder) AddObjectKeyNullEmpty ¶
func (enc *Encoder) AddObjectKeyNullEmpty(key string, v MarshalerJSONObject)
AddObjectKeyNullEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) AddObjectKeyOmitEmpty ¶
func (enc *Encoder) AddObjectKeyOmitEmpty(key string, v MarshalerJSONObject)
AddObjectKeyOmitEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) AddObjectNullEmpty ¶
func (enc *Encoder) AddObjectNullEmpty(v MarshalerJSONObject)
AddObjectNullEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) AddObjectOmitEmpty ¶
func (enc *Encoder) AddObjectOmitEmpty(v MarshalerJSONObject)
AddObjectOmitEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) AddSQLNullBool ¶
AddSQLNullBool adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullBoolKey ¶
AddSQLNullBoolKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullBoolKeyNullEmpty ¶
AddSQLNullBoolKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullBoolKeyOmitEmpty ¶
AddSQLNullBoolKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullBoolOmitEmpty ¶
AddSQLNullBoolOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullFloat64 ¶
func (enc *Encoder) AddSQLNullFloat64(v *sql.NullFloat64)
AddSQLNullFloat64 adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullFloat64Key ¶
func (enc *Encoder) AddSQLNullFloat64Key(key string, v *sql.NullFloat64)
AddSQLNullFloat64Key adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullFloat64KeyNullEmpty ¶
func (enc *Encoder) AddSQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64)
AddSQLNullFloat64KeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullFloat64KeyOmitEmpty ¶
func (enc *Encoder) AddSQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64)
AddSQLNullFloat64KeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullFloat64NullEmpty ¶
func (enc *Encoder) AddSQLNullFloat64NullEmpty(v *sql.NullFloat64)
AddSQLNullFloat64NullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullFloat64OmitEmpty ¶
func (enc *Encoder) AddSQLNullFloat64OmitEmpty(v *sql.NullFloat64)
AddSQLNullFloat64OmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullInt64 ¶
AddSQLNullInt64 adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullInt64Key ¶
AddSQLNullInt64Key adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullInt64KeyNullEmpty ¶
AddSQLNullInt64KeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullInt64KeyOmitEmpty ¶
AddSQLNullInt64KeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullInt64NullEmpty ¶
AddSQLNullInt64NullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullInt64OmitEmpty ¶
AddSQLNullInt64OmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullString ¶
func (enc *Encoder) AddSQLNullString(v *sql.NullString)
AddSQLNullString adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullStringKey ¶
func (enc *Encoder) AddSQLNullStringKey(key string, v *sql.NullString)
AddSQLNullStringKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullStringKeyOmitEmpty ¶
func (enc *Encoder) AddSQLNullStringKeyOmitEmpty(key string, v *sql.NullString)
AddSQLNullStringKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddSQLNullStringNullEmpty ¶
func (enc *Encoder) AddSQLNullStringNullEmpty(v *sql.NullString)
AddSQLNullStringNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSQLNullStringOmitEmpty ¶
func (enc *Encoder) AddSQLNullStringOmitEmpty(v *sql.NullString)
AddSQLNullStringOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddSliceBool ¶
AddSliceBool marshals the given []bool s
func (*Encoder) AddSliceBoolKey ¶
AddSliceBoolKey marshals the given []bool s
func (*Encoder) AddSliceFloat64 ¶
AddSliceFloat64 marshals the given []float64 s
func (*Encoder) AddSliceFloat64Key ¶
AddSliceFloat64Key marshals the given []float64 s
func (*Encoder) AddSliceInt ¶
AddSliceInt marshals the given []int s
func (*Encoder) AddSliceIntKey ¶
AddSliceIntKey marshals the given []int s
func (*Encoder) AddSliceString ¶
AddSliceString marshals the given []string s
func (*Encoder) AddSliceStringKey ¶
AddSliceStringKey marshals the given []string s
func (*Encoder) AddString ¶
AddString adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddStringKey ¶
AddStringKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddStringKeyNullEmpty ¶
AddStringKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddStringKeyOmitEmpty ¶
AddStringKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) AddStringNullEmpty ¶
AddStringNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddStringOmitEmpty ¶
AddStringOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddTime ¶
AddTime adds an *time.Time to be encoded with the given format, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddTimeKey ¶
AddTimeKey adds an *time.Time to be encoded with the given format, must be used inside an object as it will encode a key
func (*Encoder) AddUint16 ¶
AddUint16 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddUint16Key ¶
AddUint16Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddUint16KeyNullEmpty ¶
AddUint16KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint16KeyOmitEmpty ¶
AddUint16KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint16NullEmpty ¶
AddUint16NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint16OmitEmpty ¶
AddUint16OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint32 ¶
AddUint32 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddUint32Key ¶
AddUint32Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddUint32KeyNullEmpty ¶
AddUint32KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint32KeyOmitEmpty ¶
AddUint32KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint32NullEmpty ¶
AddUint32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint32OmitEmpty ¶
AddUint32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint64 ¶
AddUint64 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddUint64Key ¶
AddUint64Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddUint64KeyNullEmpty ¶
AddUint64KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint64KeyOmitEmpty ¶
AddUint64KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint64NullEmpty ¶
AddUint64NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint64OmitEmpty ¶
AddUint64OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint8 ¶
AddUint8 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) AddUint8Key ¶
AddUint8Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) AddUint8KeyNullEmpty ¶
AddUint8KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint8KeyOmitEmpty ¶
AddUint8KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) AddUint8NullEmpty ¶
AddUint8NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AddUint8OmitEmpty ¶
AddUint8OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) AppendByte ¶
AppendByte allows a modular usage by appending a single byte manually to the current state of the buffer.
func (*Encoder) AppendBytes ¶
AppendBytes allows a modular usage by appending bytes manually to the current state of the buffer.
func (*Encoder) AppendString ¶
AppendString appends a string to the buffer
func (*Encoder) Array ¶
func (enc *Encoder) Array(v MarshalerJSONArray)
Array adds an implementation of MarshalerJSONArray to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement Marshaler
func (*Encoder) ArrayKey ¶
func (enc *Encoder) ArrayKey(key string, v MarshalerJSONArray)
ArrayKey adds an array or slice to be encoded, must be used inside an object as it will encode a key value must implement Marshaler
func (*Encoder) ArrayKeyNullEmpty ¶
func (enc *Encoder) ArrayKeyNullEmpty(key string, v MarshalerJSONArray)
ArrayKeyNullEmpty adds an array or slice to be encoded and encodes `null“ if it is nil. Must be called inside an object as it will encode a key.
func (*Encoder) ArrayKeyOmitEmpty ¶
func (enc *Encoder) ArrayKeyOmitEmpty(key string, v MarshalerJSONArray)
ArrayKeyOmitEmpty adds an array or slice to be encoded and skips if it is nil. Must be called inside an object as it will encode a key.
func (*Encoder) ArrayNullEmpty ¶
func (enc *Encoder) ArrayNullEmpty(v MarshalerJSONArray)
ArrayNullEmpty adds an array or slice to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement Marshaler
func (*Encoder) ArrayOmitEmpty ¶
func (enc *Encoder) ArrayOmitEmpty(v MarshalerJSONArray)
ArrayOmitEmpty adds an array or slice to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement Marshaler
func (*Encoder) Bool ¶
Bool adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) BoolKey ¶
BoolKey adds a bool to be encoded, must be used inside an object as it will encode a key.
func (*Encoder) BoolKeyNullEmpty ¶
BoolKeyNullEmpty adds a bool to be encoded and skips it if it is zero value. Must be used inside an object as it will encode a key.
func (*Encoder) BoolKeyOmitEmpty ¶
BoolKeyOmitEmpty adds a bool to be encoded and skips it if it is zero value. Must be used inside an object as it will encode a key.
func (*Encoder) BoolNullEmpty ¶
BoolNullEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) BoolOmitEmpty ¶
BoolOmitEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Encode ¶
Encode encodes a value to JSON.
If Encode cannot find a way to encode the type to JSON it will return an InvalidMarshalError.
func (*Encoder) EncodeArray ¶
func (enc *Encoder) EncodeArray(v MarshalerJSONArray) error
EncodeArray encodes an implementation of MarshalerJSONArray to JSON
func (*Encoder) EncodeBool ¶
EncodeBool encodes a bool to JSON
func (*Encoder) EncodeEmbeddedJSON ¶
func (enc *Encoder) EncodeEmbeddedJSON(v *EmbeddedJSON) error
EncodeEmbeddedJSON encodes an embedded JSON. is basically sets the internal buf as the value pointed by v and calls the io.Writer.Write()
func (*Encoder) EncodeFloat ¶
EncodeFloat encodes a float64 to JSON
func (*Encoder) EncodeFloat32 ¶
EncodeFloat32 encodes a float32 to JSON
func (*Encoder) EncodeInt64 ¶
EncodeInt64 encodes an int64 to JSON
func (*Encoder) EncodeObject ¶
func (enc *Encoder) EncodeObject(v MarshalerJSONObject) error
EncodeObject encodes an object to JSON
func (*Encoder) EncodeObjectKeys ¶
func (enc *Encoder) EncodeObjectKeys(v MarshalerJSONObject, keys []string) error
EncodeObjectKeys encodes an object to JSON
func (*Encoder) EncodeSQLNullBool ¶
EncodeSQLNullBool encodes a string to
func (*Encoder) EncodeSQLNullFloat64 ¶
func (enc *Encoder) EncodeSQLNullFloat64(v *sql.NullFloat64) error
EncodeSQLNullFloat64 encodes a string to
func (*Encoder) EncodeSQLNullInt64 ¶
EncodeSQLNullInt64 encodes a string to
func (*Encoder) EncodeSQLNullString ¶
func (enc *Encoder) EncodeSQLNullString(v *sql.NullString) error
EncodeSQLNullString encodes a string to
func (*Encoder) EncodeString ¶
EncodeString encodes a string to
Example ¶
package main import ( "log" "os" "github.com/francoispqt/gojay" ) func main() { enc := gojay.BorrowEncoder(os.Stdout) defer enc.Release() var str = "gojay" err := enc.EncodeString(str) if err != nil { log.Fatal(err) } }
Output: "gojay"
func (*Encoder) EncodeTime ¶
EncodeTime encodes a *time.Time to JSON with the given format
func (*Encoder) EncodeUint64 ¶
EncodeUint64 encodes an int64 to JSON
func (*Encoder) Float ¶
Float adds a float64 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Float32 ¶
Float32 adds a float32 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Float32Key ¶
Float32Key adds a float32 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Float32KeyNullEmpty ¶
Float32KeyNullEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) Float32KeyOmitEmpty ¶
Float32KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) Float32NullEmpty ¶
Float32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Float32OmitEmpty ¶
Float32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Float64 ¶
Float64 adds a float64 to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Float64Key ¶
Float64Key adds a float64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Float64KeyNullEmpty ¶
Float64KeyNullEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Float64KeyOmitEmpty ¶
Float64KeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) Float64NullEmpty ¶
Float64NullEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Float64OmitEmpty ¶
Float64OmitEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) FloatKey ¶
FloatKey adds a float64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) FloatKeyNullEmpty ¶
FloatKeyNullEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) FloatKeyOmitEmpty ¶
FloatKeyOmitEmpty adds a float64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key
func (*Encoder) FloatNullEmpty ¶
FloatNullEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) FloatOmitEmpty ¶
FloatOmitEmpty adds a float64 to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int ¶
Int adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Int16 ¶
Int16 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Int16Key ¶
Int16Key adds an int16 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Int16KeyNullEmpty ¶
Int16KeyNullEmpty adds an int16 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int16KeyOmitEmpty ¶
Int16KeyOmitEmpty adds an int16 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int16NullEmpty ¶
Int16NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int16OmitEmpty ¶
Int16OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int32 ¶
Int32 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Int32Key ¶
Int32Key adds an int32 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Int32KeyNullEmpty ¶
Int32KeyNullEmpty adds an int32 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int32KeyOmitEmpty ¶
Int32KeyOmitEmpty adds an int32 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int32NullEmpty ¶
Int32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int32OmitEmpty ¶
Int32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int64 ¶
Int64 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Int64Key ¶
Int64Key adds an int64 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Int64KeyNullEmpty ¶
Int64KeyNullEmpty adds an int64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int64KeyOmitEmpty ¶
Int64KeyOmitEmpty adds an int64 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int64NullEmpty ¶
Int64NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int64OmitEmpty ¶
Int64OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int8 ¶
Int8 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Int8Key ¶
Int8Key adds an int8 to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Int8KeyNullEmpty ¶
Int8KeyNullEmpty adds an int8 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int8KeyOmitEmpty ¶
Int8KeyOmitEmpty adds an int8 to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Int8NullEmpty ¶
Int8NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Int8OmitEmpty ¶
Int8OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) IntKey ¶
IntKey adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) IntKeyNullEmpty ¶
IntKeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) IntKeyOmitEmpty ¶
IntKeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) IntNullEmpty ¶
IntNullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) IntOmitEmpty ¶
IntOmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Null ¶
func (enc *Encoder) Null()
Null adds a `null` to be encoded. Must be used while encoding an array.`
func (*Encoder) NullKey ¶
NullKey adds a `null` to be encoded. Must be used while encoding an array.`
func (*Encoder) Object ¶
func (enc *Encoder) Object(v MarshalerJSONObject)
Object adds an object to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) ObjectKey ¶
func (enc *Encoder) ObjectKey(key string, v MarshalerJSONObject)
ObjectKey adds a struct to be encoded, must be used inside an object as it will encode a key value must implement MarshalerJSONObject
func (*Encoder) ObjectKeyNullEmpty ¶
func (enc *Encoder) ObjectKeyNullEmpty(key string, v MarshalerJSONObject)
ObjectKeyNullEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) ObjectKeyOmitEmpty ¶
func (enc *Encoder) ObjectKeyOmitEmpty(key string, v MarshalerJSONObject)
ObjectKeyOmitEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) ObjectKeyWithKeys ¶
func (enc *Encoder) ObjectKeyWithKeys(key string, value MarshalerJSONObject, keys []string)
ObjectKeyWithKeys adds a struct to be encoded, must be used inside an object as it will encode a key. Value must implement MarshalerJSONObject. It will only encode the keys in keys.
func (*Encoder) ObjectNullEmpty ¶
func (enc *Encoder) ObjectNullEmpty(v MarshalerJSONObject)
ObjectNullEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) ObjectOmitEmpty ¶
func (enc *Encoder) ObjectOmitEmpty(v MarshalerJSONObject)
ObjectOmitEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject
func (*Encoder) ObjectWithKeys ¶
func (enc *Encoder) ObjectWithKeys(v MarshalerJSONObject, keys []string)
ObjectWithKeys adds an object to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject. It will only encode the keys in keys.
func (*Encoder) SQLNullBool ¶
SQLNullBool adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullBoolKey ¶
SQLNullBoolKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullBoolKeyNullEmpty ¶
SQLNullBoolKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullBoolKeyOmitEmpty ¶
SQLNullBoolKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullBoolNullEmpty ¶
SQLNullBoolNullEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullBoolOmitEmpty ¶
SQLNullBoolOmitEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64 ¶
func (enc *Encoder) SQLNullFloat64(v *sql.NullFloat64)
SQLNullFloat64 adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64Key ¶
func (enc *Encoder) SQLNullFloat64Key(key string, v *sql.NullFloat64)
SQLNullFloat64Key adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64KeyNullEmpty ¶
func (enc *Encoder) SQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64)
SQLNullFloat64KeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64KeyOmitEmpty ¶
func (enc *Encoder) SQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64)
SQLNullFloat64KeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64NullEmpty ¶
func (enc *Encoder) SQLNullFloat64NullEmpty(v *sql.NullFloat64)
SQLNullFloat64NullEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullFloat64OmitEmpty ¶
func (enc *Encoder) SQLNullFloat64OmitEmpty(v *sql.NullFloat64)
SQLNullFloat64OmitEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64 ¶
SQLNullInt64 adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64Key ¶
SQLNullInt64Key adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64KeyNullEmpty ¶
SQLNullInt64KeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64KeyOmitEmpty ¶
SQLNullInt64KeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64NullEmpty ¶
SQLNullInt64NullEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullInt64OmitEmpty ¶
SQLNullInt64OmitEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullString ¶
func (enc *Encoder) SQLNullString(v *sql.NullString)
SQLNullString adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullStringKey ¶
func (enc *Encoder) SQLNullStringKey(key string, v *sql.NullString)
SQLNullStringKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullStringKeyNullEmpty ¶
func (enc *Encoder) SQLNullStringKeyNullEmpty(key string, v *sql.NullString)
SQLNullStringKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullStringKeyOmitEmpty ¶
func (enc *Encoder) SQLNullStringKeyOmitEmpty(key string, v *sql.NullString)
SQLNullStringKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) SQLNullStringNullEmpty ¶
func (enc *Encoder) SQLNullStringNullEmpty(v *sql.NullString)
SQLNullStringNullEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SQLNullStringOmitEmpty ¶
func (enc *Encoder) SQLNullStringOmitEmpty(v *sql.NullString)
SQLNullStringOmitEmpty adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) SliceBoolKey ¶
SliceBoolKey marshals the given []bool s
func (*Encoder) SliceFloat64 ¶
SliceFloat64 marshals the given []float64 s
func (*Encoder) SliceFloat64Key ¶
SliceFloat64Key marshals the given []float64 s
func (*Encoder) SliceIntKey ¶
SliceIntKey marshals the given []int s
func (*Encoder) SliceString ¶
SliceString marshals the given []string s
func (*Encoder) SliceStringKey ¶
SliceStringKey marshals the given []string s
func (*Encoder) String ¶
String adds a string to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) StringKey ¶
StringKey adds a string to be encoded, must be used inside an object as it will encode a key
func (*Encoder) StringKeyNullEmpty ¶
StringKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) StringKeyOmitEmpty ¶
StringKeyOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key
func (*Encoder) StringNullEmpty ¶
StringNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) StringOmitEmpty ¶
StringOmitEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Time ¶
Time adds an *time.Time to be encoded with the given format, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) TimeKey ¶
TimeKey adds an *time.Time to be encoded with the given format, must be used inside an object as it will encode a key
func (*Encoder) Uint16 ¶
Uint16 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Uint16Key ¶
Uint16Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Uint16KeyNullEmpty ¶
Uint16KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint16KeyOmitEmpty ¶
Uint16KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint16NullEmpty ¶
Uint16NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint16OmitEmpty ¶
Uint16OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint32 ¶
Uint32 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Uint32Key ¶
Uint32Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Uint32KeyNullEmpty ¶
Uint32KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint32KeyOmitEmpty ¶
Uint32KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint32NullEmpty ¶
Uint32NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint32OmitEmpty ¶
Uint32OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint64 ¶
Uint64 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Uint64Key ¶
Uint64Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Uint64KeyNullEmpty ¶
Uint64KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint64KeyOmitEmpty ¶
Uint64KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint64NullEmpty ¶
Uint64NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint64OmitEmpty ¶
Uint64OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint8 ¶
Uint8 adds an int to be encoded, must be used inside a slice or array encoding (does not encode a key)
func (*Encoder) Uint8Key ¶
Uint8Key adds an int to be encoded, must be used inside an object as it will encode a key
func (*Encoder) Uint8KeyNullEmpty ¶
Uint8KeyNullEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint8KeyOmitEmpty ¶
Uint8KeyOmitEmpty adds an int to be encoded and skips it if its value is 0. Must be used inside an object as it will encode a key.
func (*Encoder) Uint8NullEmpty ¶
Uint8NullEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
func (*Encoder) Uint8OmitEmpty ¶
Uint8OmitEmpty adds an int to be encoded and skips it if its value is 0, must be used inside a slice or array encoding (does not encode a key).
type InvalidJSONError ¶
type InvalidJSONError string
InvalidJSONError is a type representing an error returned when Decoding encounters invalid JSON.
func (InvalidJSONError) Error ¶
func (err InvalidJSONError) Error() string
type InvalidMarshalError ¶
type InvalidMarshalError string
InvalidMarshalError is a type representing an error returned when Encoding did not find the proper way to encode
func (InvalidMarshalError) Error ¶
func (err InvalidMarshalError) Error() string
type InvalidUnmarshalError ¶
type InvalidUnmarshalError string
InvalidUnmarshalError is a type representing an error returned when Decoding cannot unmarshal JSON to the receiver type for various reasons.
func (InvalidUnmarshalError) Error ¶
func (err InvalidUnmarshalError) Error() string
type InvalidUsagePooledDecoderError ¶
type InvalidUsagePooledDecoderError string
InvalidUsagePooledDecoderError is a type representing an error returned when decoding is called on a still pooled Decoder
func (InvalidUsagePooledDecoderError) Error ¶
func (err InvalidUsagePooledDecoderError) Error() string
type InvalidUsagePooledEncoderError ¶
type InvalidUsagePooledEncoderError string
InvalidUsagePooledEncoderError is a type representing an error returned when decoding is called on a still pooled Encoder
func (InvalidUsagePooledEncoderError) Error ¶
func (err InvalidUsagePooledEncoderError) Error() string
type MarshalerJSONArray ¶
MarshalerJSONArray is the interface to implement for a slice or an array to be encoded
type MarshalerJSONObject ¶
MarshalerJSONObject is the interface to implement for struct to be encoded
type MarshalerStream ¶
type MarshalerStream interface {
MarshalStream(enc *StreamEncoder)
}
MarshalerStream is the interface to implement to continuously encode of stream of data.
type NoReaderError ¶
type NoReaderError string
NoReaderError is a type representing an error returned when decoding requires a reader and none was given
func (NoReaderError) Error ¶
func (err NoReaderError) Error() string
type StreamDecoder ¶
type StreamDecoder struct { *Decoder // contains filtered or unexported fields }
A StreamDecoder reads and decodes JSON values from an input stream.
It implements conext.Context and provide a channel to notify interruption.
func (*StreamDecoder) Deadline ¶
func (dec *StreamDecoder) Deadline() (time.Time, bool)
Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.
func (*StreamDecoder) DecodeStream ¶
func (dec *StreamDecoder) DecodeStream(c UnmarshalerStream) error
DecodeStream reads the next line delimited JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by c.
c must implement UnmarshalerStream. Ideally c is a channel. See example for implementation.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*StreamDecoder) Done ¶
func (dec *StreamDecoder) Done() <-chan struct{}
Done returns a channel that's closed when work is done. It implements context.Context
func (*StreamDecoder) Err ¶
func (dec *StreamDecoder) Err() error
Err returns nil if Done is not yet closed. If Done is closed, Err returns a non-nil error explaining why. It implements context.Context
func (*StreamDecoder) Release ¶
func (dec *StreamDecoder) Release()
Release sends back a Decoder to the pool. If a decoder is used after calling Release a panic will be raised with an InvalidUsagePooledDecoderError error.
func (*StreamDecoder) SetDeadline ¶
func (dec *StreamDecoder) SetDeadline(t time.Time)
SetDeadline sets the deadline
func (*StreamDecoder) Value ¶
func (dec *StreamDecoder) Value(key interface{}) interface{}
Value implements context.Context
type StreamEncoder ¶
type StreamEncoder struct { *Encoder // contains filtered or unexported fields }
A StreamEncoder reads and encodes values to JSON from an input stream.
It implements conext.Context and provide a channel to notify interruption.
func (*StreamEncoder) AddArray ¶
func (s *StreamEncoder) AddArray(v MarshalerJSONArray)
AddArray adds an implementation of MarshalerJSONArray to be encoded.
func (*StreamEncoder) AddFloat ¶
func (s *StreamEncoder) AddFloat(value float64)
AddFloat adds a float64 to be encoded.
func (*StreamEncoder) AddFloat64 ¶
func (s *StreamEncoder) AddFloat64(value float64)
AddFloat64 adds a float64 to be encoded.
func (*StreamEncoder) AddInt ¶
func (s *StreamEncoder) AddInt(value int)
AddInt adds an int to be encoded.
func (*StreamEncoder) AddObject ¶
func (s *StreamEncoder) AddObject(v MarshalerJSONObject)
AddObject adds an object to be encoded. value must implement MarshalerJSONObject.
func (*StreamEncoder) AddString ¶
func (s *StreamEncoder) AddString(v string)
AddString adds a string to be encoded.
func (*StreamEncoder) Cancel ¶
func (s *StreamEncoder) Cancel(err error)
Cancel cancels the consumers of the stream, interrupting the stream encoding.
After calling cancel, Done() will return a closed channel.
func (*StreamEncoder) CommaDelimited ¶
func (s *StreamEncoder) CommaDelimited() *StreamEncoder
CommaDelimited sets the delimiter to a comma.
It will add a new line after each JSON marshaled by the MarshalerStream
func (*StreamEncoder) Deadline ¶
func (s *StreamEncoder) Deadline() (time.Time, bool)
Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.
func (*StreamEncoder) Done ¶
func (s *StreamEncoder) Done() <-chan struct{}
Done returns a channel that's closed when work is done. It implements context.Context
func (*StreamEncoder) EncodeStream ¶
func (s *StreamEncoder) EncodeStream(m MarshalerStream)
EncodeStream spins up a defined number of non blocking consumers of the MarshalerStream m.
m must implement MarshalerStream. Ideally m is a channel. See example for implementation.
See the documentation for Marshal for details about the conversion of Go value to JSON.
func (*StreamEncoder) Err ¶
func (s *StreamEncoder) Err() error
Err returns nil if Done is not yet closed. If Done is closed, Err returns a non-nil error explaining why. It implements context.Context
func (*StreamEncoder) LineDelimited ¶
func (s *StreamEncoder) LineDelimited() *StreamEncoder
LineDelimited sets the delimiter to a new line character.
It will add a new line after each JSON marshaled by the MarshalerStream
func (*StreamEncoder) NConsumer ¶
func (s *StreamEncoder) NConsumer(n int) *StreamEncoder
NConsumer sets the number of non blocking go routine to consume the stream.
func (*StreamEncoder) Release ¶
func (s *StreamEncoder) Release()
Release sends back a Decoder to the pool. If a decoder is used after calling Release a panic will be raised with an InvalidUsagePooledDecoderError error.
func (*StreamEncoder) SetDeadline ¶
func (s *StreamEncoder) SetDeadline(t time.Time)
SetDeadline sets the deadline
func (*StreamEncoder) Value ¶
func (s *StreamEncoder) Value(key interface{}) interface{}
Value implements context.Context
type UnmarshalerJSONArray ¶
UnmarshalerJSONArray is the interface to implement to decode a JSON Array.
type UnmarshalerJSONObject ¶
UnmarshalerJSONObject is the interface to implement to decode a JSON Object.
type UnmarshalerStream ¶
type UnmarshalerStream interface {
UnmarshalStream(*StreamDecoder) error
}
UnmarshalerStream is the interface to implement for a slice, an array or a slice to decode a line delimited JSON to.
Source Files ¶
- decode.go
- decode_array.go
- decode_bool.go
- decode_embedded_json.go
- decode_interface.go
- decode_number.go
- decode_number_float.go
- decode_number_int.go
- decode_number_uint.go
- decode_object.go
- decode_pool.go
- decode_slice.go
- decode_sqlnull.go
- decode_stream.go
- decode_stream_pool.go
- decode_string.go
- decode_string_unicode.go
- decode_time.go
- decode_unsafe.go
- encode.go
- encode_array.go
- encode_bool.go
- encode_builder.go
- encode_embedded_json.go
- encode_interface.go
- encode_null.go
- encode_number.go
- encode_number_float.go
- encode_number_int.go
- encode_number_uint.go
- encode_object.go
- encode_pool.go
- encode_slice.go
- encode_sqlnull.go
- encode_stream.go
- encode_stream_pool.go
- encode_string.go
- encode_time.go
- errors.go
- gojay.go