summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/francoispqt/gojay/encode_embedded_json.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-08-10 00:29:54 +0200
committerGitHub <noreply@github.com>2020-08-10 00:29:54 +0200
commit4e50fd864921c556988c919269448efdb90fa961 (patch)
treea3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/francoispqt/gojay/encode_embedded_json.go
parentdfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff)
downloadmatterbridge-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_embedded_json.go')
-rw-r--r--vendor/github.com/francoispqt/gojay/encode_embedded_json.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/github.com/francoispqt/gojay/encode_embedded_json.go b/vendor/github.com/francoispqt/gojay/encode_embedded_json.go
new file mode 100644
index 00000000..4c99a057
--- /dev/null
+++ b/vendor/github.com/francoispqt/gojay/encode_embedded_json.go
@@ -0,0 +1,93 @@
+package gojay
+
+// EncodeEmbeddedJSON encodes an embedded JSON.
+// is basically sets the internal buf as the value pointed by v and calls the io.Writer.Write()
+func (enc *Encoder) EncodeEmbeddedJSON(v *EmbeddedJSON) error {
+ if enc.isPooled == 1 {
+ panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
+ }
+ enc.buf = *v
+ _, err := enc.Write()
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (enc *Encoder) encodeEmbeddedJSON(v *EmbeddedJSON) ([]byte, error) {
+ enc.writeBytes(*v)
+ return enc.buf, nil
+}
+
+// AddEmbeddedJSON adds an EmbeddedJSON to be encoded.
+//
+// It basically blindly writes the bytes to the final buffer. Therefore,
+// it expects the JSON to be of proper format.
+func (enc *Encoder) AddEmbeddedJSON(v *EmbeddedJSON) {
+ enc.grow(len(*v) + 4)
+ r := enc.getPreviousRune()
+ if r != '[' {
+ enc.writeByte(',')
+ }
+ enc.writeBytes(*v)
+}
+
+// AddEmbeddedJSONOmitEmpty adds an EmbeddedJSON to be encoded or skips it if nil pointer or empty.
+//
+// It basically blindly writes the bytes to the final buffer. Therefore,
+// it expects the JSON to be of proper format.
+func (enc *Encoder) AddEmbeddedJSONOmitEmpty(v *EmbeddedJSON) {
+ if v == nil || len(*v) == 0 {
+ return
+ }
+ r := enc.getPreviousRune()
+ if r != '[' {
+ enc.writeByte(',')
+ }
+ enc.writeBytes(*v)
+}
+
+// AddEmbeddedJSONKey adds an EmbeddedJSON and a key to be encoded.
+//
+// It basically blindly writes the bytes to the final buffer. Therefore,
+// it expects the JSON to be of proper format.
+func (enc *Encoder) AddEmbeddedJSONKey(key string, v *EmbeddedJSON) {
+ if enc.hasKeys {
+ if !enc.keyExists(key) {
+ return
+ }
+ }
+ enc.grow(len(key) + len(*v) + 5)
+ r := enc.getPreviousRune()
+ if r != '{' {
+ enc.writeByte(',')
+ }
+ enc.writeByte('"')
+ enc.writeStringEscape(key)
+ enc.writeBytes(objKey)
+ enc.writeBytes(*v)
+}
+
+// AddEmbeddedJSONKeyOmitEmpty adds an EmbeddedJSON and a key to be encoded or skips it if nil pointer or empty.
+//
+// It basically blindly writes the bytes to the final buffer. Therefore,
+// it expects the JSON to be of proper format.
+func (enc *Encoder) AddEmbeddedJSONKeyOmitEmpty(key string, v *EmbeddedJSON) {
+ if enc.hasKeys {
+ if !enc.keyExists(key) {
+ return
+ }
+ }
+ if v == nil || len(*v) == 0 {
+ return
+ }
+ enc.grow(len(key) + len(*v) + 5)
+ r := enc.getPreviousRune()
+ if r != '{' {
+ enc.writeByte(',')
+ }
+ enc.writeByte('"')
+ enc.writeStringEscape(key)
+ enc.writeBytes(objKey)
+ enc.writeBytes(*v)
+}