Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseNumber ¶
ParseNumber reads the given []byte for a valid JSON number. If it is valid, it returns the number of bytes. Parsing logic follows the definition in https://tools.ietf.org/html/rfc7159#section-6, and is based off encoding/json.isValidNumber function.
func TokenEquals ¶
TokenEquals returns true if given Tokens are equal, else false.
Types ¶
type NewEncoderFun ¶
var NewEncoder NewEncoderFun
type Token ¶
type Token struct { // Token Kind. Kind Kind // Pos provides the position of the token in the original input. Pos int // Raw bytes of the serialized token. // This is a subslice into the original input. Raw []byte // Boo is parsed boolean value. Boo bool // Str is parsed string value. Str string }
Token provides a parsed token kind and value.
Values are provided by the difference accessor methods. The accessor methods Name, Bool, and ParsedString will panic if called on the wrong kind. There are different accessor methods for the Number kind for converting to the appropriate Go numeric type and those methods have the ok return value.
func (Token) Float ¶
Float returns the floating-point number if token kind is Number.
The floating-point precision is specified by the bitSize parameter: 32 for float32 or 64 for float64. If bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value. It will return false if the number exceeds the floating point limits for given bitSize.
func (Token) Int ¶
Int returns the signed integer number if token is Number.
The given bitSize specifies the integer type that the result must fit into. It returns false if the number is not an integer value or if the result exceeds the limits for given bitSize.
func (Token) ParsedString ¶
ParsedString returns the string value for a JSON string token or the read value in string if token is not a string.