summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/francoispqt/gojay/decode_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/decode_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/decode_embedded_json.go')
-rw-r--r--vendor/github.com/francoispqt/gojay/decode_embedded_json.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/github.com/francoispqt/gojay/decode_embedded_json.go b/vendor/github.com/francoispqt/gojay/decode_embedded_json.go
new file mode 100644
index 00000000..67fcc2ea
--- /dev/null
+++ b/vendor/github.com/francoispqt/gojay/decode_embedded_json.go
@@ -0,0 +1,85 @@
+package gojay
+
+// EmbeddedJSON is a raw encoded JSON value.
+// It can be used to delay JSON decoding or precompute a JSON encoding.
+type EmbeddedJSON []byte
+
+func (dec *Decoder) decodeEmbeddedJSON(ej *EmbeddedJSON) error {
+ var err error
+ if ej == nil {
+ return InvalidUnmarshalError("Invalid nil pointer given")
+ }
+ var beginOfEmbeddedJSON int
+ for ; dec.cursor < dec.length || dec.read(); dec.cursor++ {
+ switch dec.data[dec.cursor] {
+ case ' ', '\n', '\t', '\r', ',':
+ continue
+ // is null
+ case 'n':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor++
+ err := dec.assertNull()
+ if err != nil {
+ return err
+ }
+ case 't':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor++
+ err := dec.assertTrue()
+ if err != nil {
+ return err
+ }
+ // is false
+ case 'f':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor++
+ err := dec.assertFalse()
+ if err != nil {
+ return err
+ }
+ // is an object
+ case '{':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor = dec.cursor + 1
+ dec.cursor, err = dec.skipObject()
+ // is string
+ case '"':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor = dec.cursor + 1
+ err = dec.skipString() // why no new dec.cursor in result?
+ // is array
+ case '[':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor = dec.cursor + 1
+ dec.cursor, err = dec.skipArray()
+ case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-':
+ beginOfEmbeddedJSON = dec.cursor
+ dec.cursor, err = dec.skipNumber()
+ }
+ break
+ }
+ if err == nil {
+ if dec.cursor-1 >= beginOfEmbeddedJSON {
+ *ej = append(*ej, dec.data[beginOfEmbeddedJSON:dec.cursor]...)
+ }
+ dec.called |= 1
+ }
+ return err
+}
+
+// AddEmbeddedJSON adds an EmbeddedsJSON to the value pointed by v.
+// It can be used to delay JSON decoding or precompute a JSON encoding.
+func (dec *Decoder) AddEmbeddedJSON(v *EmbeddedJSON) error {
+ return dec.EmbeddedJSON(v)
+}
+
+// EmbeddedJSON adds an EmbeddedsJSON to the value pointed by v.
+// It can be used to delay JSON decoding or precompute a JSON encoding.
+func (dec *Decoder) EmbeddedJSON(v *EmbeddedJSON) error {
+ err := dec.decodeEmbeddedJSON(v)
+ if err != nil {
+ return err
+ }
+ dec.called |= 1
+ return nil
+}