package gojay
import "strconv"
func (enc *Encoder ) EncodeFloat (n float64 ) error {
if enc .isPooled == 1 {
panic (InvalidUsagePooledEncoderError ("Invalid usage of pooled encoder" ))
}
_, _ = enc .encodeFloat (n )
_ , err := enc .Write ()
if err != nil {
return err
}
return nil
}
func (enc *Encoder ) encodeFloat (n float64 ) ([]byte , error ) {
enc .buf = strconv .AppendFloat (enc .buf , n , 'f' , -1 , 64 )
return enc .buf , nil
}
func (enc *Encoder ) EncodeFloat32 (n float32 ) error {
if enc .isPooled == 1 {
panic (InvalidUsagePooledEncoderError ("Invalid usage of pooled encoder" ))
}
_, _ = enc .encodeFloat32 (n )
_ , err := enc .Write ()
if err != nil {
return err
}
return nil
}
func (enc *Encoder ) encodeFloat32 (n float32 ) ([]byte , error ) {
enc .buf = strconv .AppendFloat (enc .buf , float64 (n ), 'f' , -1 , 32 )
return enc .buf , nil
}
func (enc *Encoder ) AddFloat (v float64 ) {
enc .Float64 (v )
}
func (enc *Encoder ) AddFloatOmitEmpty (v float64 ) {
enc .Float64OmitEmpty (v )
}
func (enc *Encoder ) AddFloatNullEmpty (v float64 ) {
enc .Float64NullEmpty (v )
}
func (enc *Encoder ) Float (v float64 ) {
enc .Float64 (v )
}
func (enc *Encoder ) FloatOmitEmpty (v float64 ) {
enc .Float64OmitEmpty (v )
}
func (enc *Encoder ) FloatNullEmpty (v float64 ) {
enc .Float64NullEmpty (v )
}
func (enc *Encoder ) AddFloatKey (key string , v float64 ) {
enc .Float64Key (key , v )
}
func (enc *Encoder ) AddFloatKeyOmitEmpty (key string , v float64 ) {
enc .Float64KeyOmitEmpty (key , v )
}
func (enc *Encoder ) AddFloatKeyNullEmpty (key string , v float64 ) {
enc .Float64KeyNullEmpty (key , v )
}
func (enc *Encoder ) FloatKey (key string , v float64 ) {
enc .Float64Key (key , v )
}
func (enc *Encoder ) FloatKeyOmitEmpty (key string , v float64 ) {
enc .Float64KeyOmitEmpty (key , v )
}
func (enc *Encoder ) FloatKeyNullEmpty (key string , v float64 ) {
enc .Float64KeyNullEmpty (key , v )
}
func (enc *Encoder ) AddFloat64 (v float64 ) {
enc .Float (v )
}
func (enc *Encoder ) AddFloat64OmitEmpty (v float64 ) {
enc .FloatOmitEmpty (v )
}
func (enc *Encoder ) Float64 (v float64 ) {
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .buf = strconv .AppendFloat (enc .buf , v , 'f' , -1 , 64 )
}
func (enc *Encoder ) Float64OmitEmpty (v float64 ) {
if v == 0 {
return
}
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .buf = strconv .AppendFloat (enc .buf , v , 'f' , -1 , 64 )
}
func (enc *Encoder ) Float64NullEmpty (v float64 ) {
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
if v == 0 {
enc .writeBytes (nullBytes )
return
}
enc .buf = strconv .AppendFloat (enc .buf , v , 'f' , -1 , 64 )
}
func (enc *Encoder ) AddFloat64Key (key string , v float64 ) {
enc .FloatKey (key , v )
}
func (enc *Encoder ) AddFloat64KeyOmitEmpty (key string , v float64 ) {
enc .FloatKeyOmitEmpty (key , v )
}
func (enc *Encoder ) Float64Key (key string , value float64 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .grow (10 )
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
enc .buf = strconv .AppendFloat (enc .buf , value , 'f' , -1 , 64 )
}
func (enc *Encoder ) Float64KeyOmitEmpty (key string , v float64 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
if v == 0 {
return
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
enc .buf = strconv .AppendFloat (enc .buf , v , 'f' , -1 , 64 )
}
func (enc *Encoder ) Float64KeyNullEmpty (key string , v float64 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
if v == 0 {
enc .writeBytes (nullBytes )
return
}
enc .buf = strconv .AppendFloat (enc .buf , v , 'f' , -1 , 64 )
}
func (enc *Encoder ) AddFloat32 (v float32 ) {
enc .Float32 (v )
}
func (enc *Encoder ) AddFloat32OmitEmpty (v float32 ) {
enc .Float32OmitEmpty (v )
}
func (enc *Encoder ) AddFloat32NullEmpty (v float32 ) {
enc .Float32NullEmpty (v )
}
func (enc *Encoder ) Float32 (v float32 ) {
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
func (enc *Encoder ) Float32OmitEmpty (v float32 ) {
if v == 0 {
return
}
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
func (enc *Encoder ) Float32NullEmpty (v float32 ) {
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
if v == 0 {
enc .writeBytes (nullBytes )
return
}
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
func (enc *Encoder ) AddFloat32Key (key string , v float32 ) {
enc .Float32Key (key , v )
}
func (enc *Encoder ) AddFloat32KeyOmitEmpty (key string , v float32 ) {
enc .Float32KeyOmitEmpty (key , v )
}
func (enc *Encoder ) AddFloat32KeyNullEmpty (key string , v float32 ) {
enc .Float32KeyNullEmpty (key , v )
}
func (enc *Encoder ) Float32Key (key string , v float32 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeByte ('"' )
enc .writeByte (':' )
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
func (enc *Encoder ) Float32KeyOmitEmpty (key string , v float32 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
if v == 0 {
return
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
func (enc *Encoder ) Float32KeyNullEmpty (key string , v float32 ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
if v == 0 {
enc .writeBytes (nullBytes )
return
}
enc .buf = strconv .AppendFloat (enc .buf , float64 (v ), 'f' , -1 , 32 )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .