commit 4a6baa0c2059e7ca2eae79ec7a0389fc7660f243
parent e9693678193be200f8e2edd3a5730cb86127c072
Author: francoispqt <francois@parquet.ninja>
Date: Sun, 28 Oct 2018 15:16:05 +0800
update documentation on add values and DecodeObjectFunc and DecodeArrayFunc
Diffstat:
12 files changed, 106 insertions(+), 96 deletions(-)
diff --git a/decode.go b/decode.go
@@ -255,7 +255,7 @@ type Decoder struct {
keysDone int
}
-// Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.
+// 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.
func (dec *Decoder) Decode(v interface{}) error {
diff --git a/decode_array.go b/decode_array.go
@@ -203,17 +203,17 @@ func (f DecodeArrayFunc) IsNil() bool {
// Add Values functions
-// AddArray decodes the next key to a UnmarshalerJSONArray.
+// AddArray decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (dec *Decoder) AddArray(v UnmarshalerJSONArray) error {
return dec.Array(v)
}
-// AddArrayNull decodes the next key to a UnmarshalerJSONArray.
+// AddArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (dec *Decoder) AddArrayNull(v UnmarshalerJSONArray) error {
return dec.ArrayNull(v)
}
-// Array decodes the next key to a UnmarshalerJSONArray.
+// Array decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func (dec *Decoder) Array(v UnmarshalerJSONArray) error {
newCursor, err := dec.decodeArray(v)
if err != nil {
@@ -224,7 +224,7 @@ func (dec *Decoder) Array(v UnmarshalerJSONArray) error {
return nil
}
-// ArrayNull decodes the next key to a UnmarshalerJSONArray.
+// 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.
diff --git a/decode_bool.go b/decode_bool.go
@@ -201,14 +201,14 @@ func (dec *Decoder) assertFalse() error {
// Add Values functions
-// AddBool decodes the next key to a *bool.
+// 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 (dec *Decoder) AddBool(v *bool) error {
return dec.Bool(v)
}
-// AddBoolNull decodes the next key to a *bool.
+// 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.
@@ -216,7 +216,7 @@ func (dec *Decoder) AddBoolNull(v **bool) error {
return dec.BoolNull(v)
}
-// Bool decodes the next key to a *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 (dec *Decoder) Bool(v *bool) error {
@@ -228,7 +228,7 @@ func (dec *Decoder) Bool(v *bool) error {
return nil
}
-// BoolNull decodes the next key to a *bool.
+// 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 (dec *Decoder) BoolNull(v **bool) error {
diff --git a/decode_interface.go b/decode_interface.go
@@ -4,7 +4,7 @@ package gojay
// the future it would be great to implement one here inside this repo
import "encoding/json"
-// DecodeInterface reads the next JSON-encoded value from its input and stores it in the value pointed to by i.
+// 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 (dec *Decoder) DecodeInterface(i *interface{}) error {
@@ -114,12 +114,12 @@ func (dec *Decoder) getObject() (start int, end int, err error) {
// Add Values functions
-// AddInterface decodes the next key to a interface{}.
+// AddInterface decodes the JSON value within an object or an array to a interface{}.
func (dec *Decoder) AddInterface(v *interface{}) error {
return dec.Interface(v)
}
-// Interface decodes the next key to an interface{}.
+// Interface decodes the JSON value within an object or an array to an interface{}.
func (dec *Decoder) Interface(value *interface{}) error {
err := dec.decodeInterface(value)
if err != nil {
diff --git a/decode_number_float.go b/decode_number_float.go
@@ -1,6 +1,6 @@
package gojay
-// DecodeFloat64 reads the next JSON-encoded value from its input and stores it in the float64 pointed to by v.
+// 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 (dec *Decoder) DecodeFloat64(v *float64) error {
@@ -208,7 +208,7 @@ func (dec *Decoder) getFloat() (float64, error) {
return float64(dec.atoi64(start, end)), nil
}
-// DecodeFloat32 reads the next JSON-encoded value from its input and stores it in the float32 pointed to by v.
+// 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 (dec *Decoder) DecodeFloat32(v *float32) error {
@@ -420,58 +420,58 @@ func (dec *Decoder) getFloat32() (float32, error) {
// Add Values functions
-// AddFloat decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloat(v *float64) error {
return dec.Float64(v)
}
-// AddFloatNull decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloatNull(v **float64) error {
return dec.Float64Null(v)
}
-// AddFloat64 decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloat64(v *float64) error {
return dec.Float64(v)
}
-// AddFloat64Null decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloat64Null(v **float64) error {
return dec.Float64Null(v)
}
-// AddFloat32 decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloat32(v *float32) error {
return dec.Float32(v)
}
-// AddFloat32Null decodes the next key to a *float64.
+// 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 (dec *Decoder) AddFloat32Null(v **float32) error {
return dec.Float32Null(v)
}
-// Float decodes the next key to a *float64.
+// 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 (dec *Decoder) Float(v *float64) error {
return dec.Float64(v)
}
-// FloatNull decodes the next key to a *float64.
+// 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 (dec *Decoder) FloatNull(v **float64) error {
return dec.Float64Null(v)
}
-// Float64 decodes the next key to a *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 (dec *Decoder) Float64(v *float64) error {
err := dec.decodeFloat64(v)
@@ -482,7 +482,7 @@ func (dec *Decoder) Float64(v *float64) error {
return nil
}
-// Float64Null decodes the next key to a *float64.
+// 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 (dec *Decoder) Float64Null(v **float64) error {
err := dec.decodeFloat64Null(v)
@@ -493,7 +493,7 @@ func (dec *Decoder) Float64Null(v **float64) error {
return nil
}
-// Float32 decodes the next key to a *float64.
+// 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 (dec *Decoder) Float32(v *float32) error {
err := dec.decodeFloat32(v)
@@ -504,7 +504,7 @@ func (dec *Decoder) Float32(v *float32) error {
return nil
}
-// Float32Null decodes the next key to a *float64.
+// 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 (dec *Decoder) Float32Null(v **float32) error {
err := dec.decodeFloat32Null(v)
diff --git a/decode_number_int.go b/decode_number_int.go
@@ -5,7 +5,7 @@ import (
"math"
)
-// DecodeInt reads the next JSON-encoded value from its input and stores it in the int pointed to by v.
+// 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 (dec *Decoder) DecodeInt(v *int) error {
@@ -112,7 +112,7 @@ func (dec *Decoder) decodeIntNull(v **int) error {
return dec.raiseInvalidJSONErr(dec.cursor)
}
-// DecodeInt16 reads the next JSON-encoded value from its input and stores it in the int16 pointed to by v.
+// 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 (dec *Decoder) DecodeInt16(v *int16) error {
@@ -344,7 +344,7 @@ func (dec *Decoder) getInt16WithExp(init int16) (int16, error) {
return 0, dec.raiseInvalidJSONErr(dec.cursor)
}
-// DecodeInt8 reads the next JSON-encoded value from its input and stores it in the int8 pointed to by v.
+// 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 (dec *Decoder) DecodeInt8(v *int8) error {
@@ -575,7 +575,7 @@ func (dec *Decoder) getInt8WithExp(init int8) (int8, error) {
return 0, dec.raiseInvalidJSONErr(dec.cursor)
}
-// DecodeInt32 reads the next JSON-encoded value from its input and stores it in the int32 pointed to by v.
+// 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 (dec *Decoder) DecodeInt32(v *int32) error {
@@ -805,7 +805,7 @@ func (dec *Decoder) getInt32WithExp(init int32) (int32, error) {
return 0, dec.raiseInvalidJSONErr(dec.cursor)
}
-// DecodeInt64 reads the next JSON-encoded value from its input and stores it in the int64 pointed to by v.
+// 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 (dec *Decoder) DecodeInt64(v *int64) error {
@@ -1161,72 +1161,72 @@ func (dec *Decoder) atoi8(start, end int) int8 {
// Add Values functions
-// AddInt decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt(v *int) error {
return dec.Int(v)
}
-// AddIntNull decodes the next key to an *int.
+// 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 (dec *Decoder) AddIntNull(v **int) error {
return dec.IntNull(v)
}
-// AddInt8 decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt8(v *int8) error {
return dec.Int8(v)
}
-// AddInt8Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt8Null(v **int8) error {
return dec.Int8Null(v)
}
-// AddInt16 decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt16(v *int16) error {
return dec.Int16(v)
}
-// AddInt16Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt16Null(v **int16) error {
return dec.Int16Null(v)
}
-// AddInt32 decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt32(v *int32) error {
return dec.Int32(v)
}
-// AddInt32Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt32Null(v **int32) error {
return dec.Int32Null(v)
}
-// AddInt64 decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt64(v *int64) error {
return dec.Int64(v)
}
-// AddInt64Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddInt64Null(v **int64) error {
return dec.Int64Null(v)
}
-// Int decodes the next key to an *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 (dec *Decoder) Int(v *int) error {
err := dec.decodeInt(v)
@@ -1237,7 +1237,7 @@ func (dec *Decoder) Int(v *int) error {
return nil
}
-// IntNull decodes the next key to an *int.
+// 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 (dec *Decoder) IntNull(v **int) error {
err := dec.decodeIntNull(v)
@@ -1248,7 +1248,7 @@ func (dec *Decoder) IntNull(v **int) error {
return nil
}
-// Int8 decodes the next key to an *int.
+// 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 (dec *Decoder) Int8(v *int8) error {
err := dec.decodeInt8(v)
@@ -1259,7 +1259,7 @@ func (dec *Decoder) Int8(v *int8) error {
return nil
}
-// Int8Null decodes the next key to an *int.
+// 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 (dec *Decoder) Int8Null(v **int8) error {
err := dec.decodeInt8Null(v)
@@ -1270,7 +1270,7 @@ func (dec *Decoder) Int8Null(v **int8) error {
return nil
}
-// Int16 decodes the next key to an *int.
+// 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 (dec *Decoder) Int16(v *int16) error {
err := dec.decodeInt16(v)
@@ -1281,7 +1281,7 @@ func (dec *Decoder) Int16(v *int16) error {
return nil
}
-// Int16Null decodes the next key to an *int.
+// 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 (dec *Decoder) Int16Null(v **int16) error {
err := dec.decodeInt16Null(v)
@@ -1292,7 +1292,7 @@ func (dec *Decoder) Int16Null(v **int16) error {
return nil
}
-// Int32 decodes the next key to an *int.
+// 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 (dec *Decoder) Int32(v *int32) error {
err := dec.decodeInt32(v)
@@ -1303,7 +1303,7 @@ func (dec *Decoder) Int32(v *int32) error {
return nil
}
-// Int32Null decodes the next key to an *int.
+// 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 (dec *Decoder) Int32Null(v **int32) error {
err := dec.decodeInt32Null(v)
@@ -1314,7 +1314,7 @@ func (dec *Decoder) Int32Null(v **int32) error {
return nil
}
-// Int64 decodes the next key to an *int.
+// 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 (dec *Decoder) Int64(v *int64) error {
err := dec.decodeInt64(v)
@@ -1325,7 +1325,7 @@ func (dec *Decoder) Int64(v *int64) error {
return nil
}
-// Int64Null decodes the next key to an *int.
+// 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 (dec *Decoder) Int64Null(v **int64) error {
err := dec.decodeInt64Null(v)
diff --git a/decode_number_uint.go b/decode_number_uint.go
@@ -4,7 +4,7 @@ import (
"math"
)
-// DecodeUint8 reads the next JSON-encoded value from its input and stores it in the uint8 pointed to by v.
+// 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 (dec *Decoder) DecodeUint8(v *uint8) error {
@@ -116,7 +116,7 @@ func (dec *Decoder) getUint8() (uint8, error) {
return dec.atoui8(start, end), nil
}
-// DecodeUint16 reads the next JSON-encoded value from its input and stores it in the uint16 pointed to by v.
+// 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 (dec *Decoder) DecodeUint16(v *uint16) error {
@@ -228,7 +228,7 @@ func (dec *Decoder) getUint16() (uint16, error) {
return dec.atoui16(start, end), nil
}
-// DecodeUint32 reads the next JSON-encoded value from its input and stores it in the uint32 pointed to by v.
+// 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 (dec *Decoder) DecodeUint32(v *uint32) error {
@@ -340,7 +340,7 @@ func (dec *Decoder) getUint32() (uint32, error) {
return dec.atoui32(start, end), nil
}
-// DecodeUint64 reads the next JSON-encoded value from its input and stores it in the uint64 pointed to by v.
+// 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 (dec *Decoder) DecodeUint64(v *uint64) error {
@@ -574,59 +574,59 @@ func (dec *Decoder) atoui8(start, end int) uint8 {
// Add Values functions
-// AddUint8 decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint8(v *uint8) error {
return dec.Uint8(v)
}
-// AddUint8Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint8Null(v **uint8) error {
return dec.Uint8Null(v)
}
-// AddUint16 decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint16(v *uint16) error {
return dec.Uint16(v)
}
-// AddUint16Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint16Null(v **uint16) error {
return dec.Uint16Null(v)
}
-// AddUint32 decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint32(v *uint32) error {
return dec.Uint32(v)
}
-// AddUint32Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint32Null(v **uint32) error {
return dec.Uint32Null(v)
}
-// AddUint64 decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint64(v *uint64) error {
return dec.Uint64(v)
}
-// AddUint64Null decodes the next key to an *int.
+// 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 (dec *Decoder) AddUint64Null(v **uint64) error {
return dec.Uint64Null(v)
}
-// Uint8 decodes the next key to an *int.
+// Uint8 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 (dec *Decoder) Uint8(v *uint8) error {
err := dec.decodeUint8(v)
@@ -637,7 +637,7 @@ func (dec *Decoder) Uint8(v *uint8) error {
return nil
}
-// Uint8Null decodes the next key to an *int.
+// Uint8Null 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 (dec *Decoder) Uint8Null(v **uint8) error {
err := dec.decodeUint8Null(v)
@@ -648,7 +648,7 @@ func (dec *Decoder) Uint8Null(v **uint8) error {
return nil
}
-// Uint16 decodes the next key to an *int.
+// 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 (dec *Decoder) Uint16(v *uint16) error {
err := dec.decodeUint16(v)
@@ -659,7 +659,7 @@ func (dec *Decoder) Uint16(v *uint16) error {
return nil
}
-// Uint16Null decodes the next key to an *int.
+// 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 (dec *Decoder) Uint16Null(v **uint16) error {
err := dec.decodeUint16Null(v)
@@ -670,7 +670,7 @@ func (dec *Decoder) Uint16Null(v **uint16) error {
return nil
}
-// Uint32 decodes the next key to an *int.
+// 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 (dec *Decoder) Uint32(v *uint32) error {
err := dec.decodeUint32(v)
@@ -681,7 +681,7 @@ func (dec *Decoder) Uint32(v *uint32) error {
return nil
}
-// Uint32Null decodes the next key to an *int.
+// 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 (dec *Decoder) Uint32Null(v **uint32) error {
err := dec.decodeUint32Null(v)
@@ -692,7 +692,7 @@ func (dec *Decoder) Uint32Null(v **uint32) error {
return nil
}
-// Uint64 decodes the next key to an *int.
+// 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 (dec *Decoder) Uint64(v *uint64) error {
err := dec.decodeUint64(v)
@@ -703,7 +703,7 @@ func (dec *Decoder) Uint64(v *uint64) error {
return nil
}
-// Uint64Null decodes the next key to an *int.
+// 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.
func (dec *Decoder) Uint64Null(v **uint64) error {
err := dec.decodeUint64Null(v)
diff --git a/decode_object.go b/decode_object.go
@@ -5,7 +5,7 @@ import (
"unsafe"
)
-// DecodeObject reads the next JSON-encoded value from its input and stores it in the value pointed to by v.
+// 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.
//
@@ -341,13 +341,23 @@ func (dec *Decoder) skipData() error {
return dec.raiseInvalidJSONErr(dec.cursor)
}
-// DecodeObjectFunc is a custom func type implementing UnmarshalerJSONObject.
-// Use it to cast a func(*Decoder) to Unmarshal an object.
+// DecodeObjectFunc is a func type implementing UnmarshalerJSONObject.
+// Use it to cast a `func(*Decoder, k string) error` to Unmarshal an object on the fly.
//
-// str := ""
+// user := struct{
+// name string
+// email string
+// }{}
// dec := gojay.NewDecoder(io.Reader)
+//
// dec.DecodeObject(gojay.DecodeObjectFunc(func(dec *gojay.Decoder, k string) error {
-// return dec.AddString(&str)
+// switch k {
+// case "name":
+// return dec.String(&user.name)
+// case "email":
+// return dec.String(&user.email)
+// }
+// return nil
// }))
type DecodeObjectFunc func(*Decoder, string) error
@@ -363,17 +373,17 @@ func (f DecodeObjectFunc) NKeys() int {
// Add Values functions
-// AddObject decodes the next key to a UnmarshalerJSONObject.
+// AddObject decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (dec *Decoder) AddObject(v UnmarshalerJSONObject) error {
return dec.Object(v)
}
-// AddObjectNull decodes the next key to a UnmarshalerJSONObject.
+// AddObjectNull decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (dec *Decoder) AddObjectNull(v interface{}) error {
return dec.ObjectNull(v)
}
-// Object decodes the next key to a UnmarshalerJSONObject.
+// Object decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func (dec *Decoder) Object(value UnmarshalerJSONObject) error {
initialKeysDone := dec.keysDone
initialChild := dec.child
@@ -391,7 +401,7 @@ func (dec *Decoder) Object(value UnmarshalerJSONObject) error {
return nil
}
-// ObjectNull decodes the next key to a UnmarshalerJSONObject.
+// 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.
diff --git a/decode_sqlnull.go b/decode_sqlnull.go
@@ -76,12 +76,12 @@ func (dec *Decoder) decodeSQLNullBool(v *sql.NullBool) error {
// Add Values functions
-// AddSQLNullString decodes the next key to qn *sql.NullString
+// AddSQLNullString decodes the JSON value within an object or an array to qn *sql.NullString
func (dec *Decoder) AddSQLNullString(v *sql.NullString) error {
return dec.SQLNullString(v)
}
-// SQLNullString decodes the next key to an *sql.NullString
+// SQLNullString decodes the JSON value within an object or an array to an *sql.NullString
func (dec *Decoder) SQLNullString(v *sql.NullString) error {
var b *string
if err := dec.StringNull(&b); err != nil {
@@ -96,12 +96,12 @@ func (dec *Decoder) SQLNullString(v *sql.NullString) error {
return nil
}
-// AddSQLNullInt64 decodes the next key to qn *sql.NullInt64
+// AddSQLNullInt64 decodes the JSON value within an object or an array to qn *sql.NullInt64
func (dec *Decoder) AddSQLNullInt64(v *sql.NullInt64) error {
return dec.SQLNullInt64(v)
}
-// SQLNullInt64 decodes the next key to an *sql.NullInt64
+// SQLNullInt64 decodes the JSON value within an object or an array to an *sql.NullInt64
func (dec *Decoder) SQLNullInt64(v *sql.NullInt64) error {
var b *int64
if err := dec.Int64Null(&b); err != nil {
@@ -116,12 +116,12 @@ func (dec *Decoder) SQLNullInt64(v *sql.NullInt64) error {
return nil
}
-// AddSQLNullFloat64 decodes the next key to qn *sql.NullFloat64
+// AddSQLNullFloat64 decodes the JSON value within an object or an array to qn *sql.NullFloat64
func (dec *Decoder) AddSQLNullFloat64(v *sql.NullFloat64) error {
return dec.SQLNullFloat64(v)
}
-// SQLNullFloat64 decodes the next key to an *sql.NullFloat64
+// SQLNullFloat64 decodes the JSON value within an object or an array to an *sql.NullFloat64
func (dec *Decoder) SQLNullFloat64(v *sql.NullFloat64) error {
var b *float64
if err := dec.Float64Null(&b); err != nil {
@@ -136,12 +136,12 @@ func (dec *Decoder) SQLNullFloat64(v *sql.NullFloat64) error {
return nil
}
-// AddSQLNullBool decodes the next key to an *sql.NullBool
+// AddSQLNullBool decodes the JSON value within an object or an array to an *sql.NullBool
func (dec *Decoder) AddSQLNullBool(v *sql.NullBool) error {
return dec.SQLNullBool(v)
}
-// SQLNullBool decodes the next key to an *sql.NullBool
+// SQLNullBool decodes the JSON value within an object or an array to an *sql.NullBool
func (dec *Decoder) SQLNullBool(v *sql.NullBool) error {
var b *bool
if err := dec.BoolNull(&b); err != nil {
diff --git a/decode_stream.go b/decode_stream.go
@@ -26,7 +26,7 @@ type StreamDecoder struct {
deadline *time.Time
}
-// DecodeStream reads the next line delimited JSON-encoded value from its input and stores it in the value pointed to by c.
+// 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.
//
diff --git a/decode_string.go b/decode_string.go
@@ -4,7 +4,7 @@ import (
"unsafe"
)
-// DecodeString reads the next JSON-encoded value from its input and stores it in the string pointed to by v.
+// 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 (dec *Decoder) DecodeString(v *string) error {
@@ -216,20 +216,20 @@ func (dec *Decoder) skipString() error {
// Add Values functions
-// AddString decodes the next key to a *string.
+// 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 (dec *Decoder) AddString(v *string) error {
return dec.String(v)
}
-// AddStringNull decodes the next key to a *string.
+// 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 (dec *Decoder) AddStringNull(v **string) error {
return dec.StringNull(v)
}
-// String decodes the next key to a *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 (dec *Decoder) String(v *string) error {
err := dec.decodeString(v)
@@ -240,7 +240,7 @@ func (dec *Decoder) String(v *string) error {
return nil
}
-// StringNull decodes the next key to a **string.
+// 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 (dec *Decoder) StringNull(v **string) error {
diff --git a/decode_time.go b/decode_time.go
@@ -37,12 +37,12 @@ func (dec *Decoder) decodeTime(v *time.Time, format string) error {
// Add Values functions
-// AddTime decodes the next key to a *time.Time with the given format
+// AddTime decodes the JSON value within an object or an array to a *time.Time with the given format
func (dec *Decoder) AddTime(v *time.Time, format string) error {
return dec.Time(v, format)
}
-// Time decodes the next key to a *time.Time with the given format
+// Time decodes the JSON value within an object or an array to a *time.Time with the given format
func (dec *Decoder) Time(v *time.Time, format string) error {
err := dec.decodeTime(v, format)
if err != nil {