diff options
author | Wim <wim@42.be> | 2020-08-10 00:29:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 00:29:54 +0200 |
commit | 4e50fd864921c556988c919269448efdb90fa961 (patch) | |
tree | a3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/francoispqt/gojay/encode_bool.go | |
parent | dfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff) | |
download | matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.gz matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.bz2 matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.zip |
Use mattermost v5 module (#1192)
Diffstat (limited to 'vendor/github.com/francoispqt/gojay/encode_bool.go')
-rw-r--r-- | vendor/github.com/francoispqt/gojay/encode_bool.go | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/vendor/github.com/francoispqt/gojay/encode_bool.go b/vendor/github.com/francoispqt/gojay/encode_bool.go new file mode 100644 index 00000000..253e0378 --- /dev/null +++ b/vendor/github.com/francoispqt/gojay/encode_bool.go @@ -0,0 +1,164 @@ +package gojay + +import "strconv" + +// EncodeBool encodes a bool to JSON +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 +} + +// encodeBool encodes a bool to JSON +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 +} + +// AddBool adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +func (enc *Encoder) AddBool(v bool) { + enc.Bool(v) +} + +// AddBoolOmitEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +func (enc *Encoder) AddBoolOmitEmpty(v bool) { + enc.BoolOmitEmpty(v) +} + +// AddBoolNullEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +func (enc *Encoder) AddBoolNullEmpty(v bool) { + enc.BoolNullEmpty(v) +} + +// AddBoolKey adds a bool to be encoded, must be used inside an object as it will encode a key. +func (enc *Encoder) AddBoolKey(key string, v bool) { + enc.BoolKey(key, v) +} + +// 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 (enc *Encoder) AddBoolKeyOmitEmpty(key string, v bool) { + enc.BoolKeyOmitEmpty(key, v) +} + +// 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 (enc *Encoder) AddBoolKeyNullEmpty(key string, v bool) { + enc.BoolKeyNullEmpty(key, v) +} + +// Bool adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +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") + } +} + +// BoolOmitEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +func (enc *Encoder) BoolOmitEmpty(v bool) { + if v == false { + return + } + enc.grow(5) + r := enc.getPreviousRune() + if r != '[' { + enc.writeByte(',') + } + enc.writeString("true") +} + +// BoolNullEmpty adds a bool to be encoded, must be used inside a slice or array encoding (does not encode a key) +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") +} + +// BoolKey adds a bool to be encoded, must be used inside an object as it will encode a key. +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) +} + +// 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 (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) +} + +// 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 (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) +} |