package gojay
import "strconv"
func (enc *Encoder ) EncodeBool (v bool ) error {
if enc .isPooled == 1 {
panic (InvalidUsagePooledEncoderError ("Invalid usage of pooled encoder" ))
}
_, _ = enc .encodeBool (v )
_ , err := enc .Write ()
if err != nil {
enc .err = err
return err
}
return nil
}
func (enc *Encoder ) encodeBool (v bool ) ([]byte , error ) {
enc .grow (5 )
if v {
enc .writeString ("true" )
} else {
enc .writeString ("false" )
}
return enc .buf , enc .err
}
func (enc *Encoder ) AddBool (v bool ) {
enc .Bool (v )
}
func (enc *Encoder ) AddBoolOmitEmpty (v bool ) {
enc .BoolOmitEmpty (v )
}
func (enc *Encoder ) AddBoolNullEmpty (v bool ) {
enc .BoolNullEmpty (v )
}
func (enc *Encoder ) AddBoolKey (key string , v bool ) {
enc .BoolKey (key , v )
}
func (enc *Encoder ) AddBoolKeyOmitEmpty (key string , v bool ) {
enc .BoolKeyOmitEmpty (key , v )
}
func (enc *Encoder ) AddBoolKeyNullEmpty (key string , v bool ) {
enc .BoolKeyNullEmpty (key , v )
}
func (enc *Encoder ) Bool (v bool ) {
enc .grow (5 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
if v {
enc .writeString ("true" )
} else {
enc .writeString ("false" )
}
}
func (enc *Encoder ) BoolOmitEmpty (v bool ) {
if v == false {
return
}
enc .grow (5 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .writeString ("true" )
}
func (enc *Encoder ) BoolNullEmpty (v bool ) {
enc .grow (5 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
if v == false {
enc .writeBytes (nullBytes )
return
}
enc .writeString ("true" )
}
func (enc *Encoder ) BoolKey (key string , value bool ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (5 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
enc .buf = strconv .AppendBool (enc .buf , value )
}
func (enc *Encoder ) BoolKeyOmitEmpty (key string , v bool ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
if v == false {
return
}
enc .grow (5 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
enc .buf = strconv .AppendBool (enc .buf , v )
}
func (enc *Encoder ) BoolKeyNullEmpty (key string , v bool ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (5 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .writeStringEscape (key )
enc .writeBytes (objKey )
if v == false {
enc .writeBytes (nullBytes )
return
}
enc .buf = strconv .AppendBool (enc .buf , v )
}
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 .