summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/rs/zerolog/internal/cbor/string.go
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
committermsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
commit032a7e0c1188d3507b8d9a9571f2446a43cf775b (patch)
tree2bd38c01bc7761a6195e426082ce7191ebc765a1 /vendor/github.com/rs/zerolog/internal/cbor/string.go
parent56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (diff)
downloadmatterbridge-msglm-1.26.0+0.1.0.tar.gz
matterbridge-msglm-1.26.0+0.1.0.tar.bz2
matterbridge-msglm-1.26.0+0.1.0.zip
apply https://github.com/42wim/matterbridge/pull/1864v1.26.0+0.1.0
Diffstat (limited to 'vendor/github.com/rs/zerolog/internal/cbor/string.go')
-rw-r--r--vendor/github.com/rs/zerolog/internal/cbor/string.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/vendor/github.com/rs/zerolog/internal/cbor/string.go b/vendor/github.com/rs/zerolog/internal/cbor/string.go
new file mode 100644
index 00000000..a33890a5
--- /dev/null
+++ b/vendor/github.com/rs/zerolog/internal/cbor/string.go
@@ -0,0 +1,95 @@
+package cbor
+
+import "fmt"
+
+// AppendStrings encodes and adds an array of strings to the dst byte array.
+func (e Encoder) AppendStrings(dst []byte, vals []string) []byte {
+ major := majorTypeArray
+ l := len(vals)
+ if l <= additionalMax {
+ lb := byte(l)
+ dst = append(dst, major|lb)
+ } else {
+ dst = appendCborTypePrefix(dst, major, uint64(l))
+ }
+ for _, v := range vals {
+ dst = e.AppendString(dst, v)
+ }
+ return dst
+}
+
+// AppendString encodes and adds a string to the dst byte array.
+func (Encoder) AppendString(dst []byte, s string) []byte {
+ major := majorTypeUtf8String
+
+ l := len(s)
+ if l <= additionalMax {
+ lb := byte(l)
+ dst = append(dst, major|lb)
+ } else {
+ dst = appendCborTypePrefix(dst, majorTypeUtf8String, uint64(l))
+ }
+ return append(dst, s...)
+}
+
+// AppendStringers encodes and adds an array of Stringer values
+// to the dst byte array.
+func (e Encoder) AppendStringers(dst []byte, vals []fmt.Stringer) []byte {
+ if len(vals) == 0 {
+ return e.AppendArrayEnd(e.AppendArrayStart(dst))
+ }
+ dst = e.AppendArrayStart(dst)
+ dst = e.AppendStringer(dst, vals[0])
+ if len(vals) > 1 {
+ for _, val := range vals[1:] {
+ dst = e.AppendStringer(dst, val)
+ }
+ }
+ return e.AppendArrayEnd(dst)
+}
+
+// AppendStringer encodes and adds the Stringer value to the dst
+// byte array.
+func (e Encoder) AppendStringer(dst []byte, val fmt.Stringer) []byte {
+ if val == nil {
+ return e.AppendNil(dst)
+ }
+ return e.AppendString(dst, val.String())
+}
+
+// AppendBytes encodes and adds an array of bytes to the dst byte array.
+func (Encoder) AppendBytes(dst, s []byte) []byte {
+ major := majorTypeByteString
+
+ l := len(s)
+ if l <= additionalMax {
+ lb := byte(l)
+ dst = append(dst, major|lb)
+ } else {
+ dst = appendCborTypePrefix(dst, major, uint64(l))
+ }
+ return append(dst, s...)
+}
+
+// AppendEmbeddedJSON adds a tag and embeds input JSON as such.
+func AppendEmbeddedJSON(dst, s []byte) []byte {
+ major := majorTypeTags
+ minor := additionalTypeEmbeddedJSON
+
+ // Append the TAG to indicate this is Embedded JSON.
+ dst = append(dst, major|additionalTypeIntUint16)
+ dst = append(dst, byte(minor>>8))
+ dst = append(dst, byte(minor&0xff))
+
+ // Append the JSON Object as Byte String.
+ major = majorTypeByteString
+
+ l := len(s)
+ if l <= additionalMax {
+ lb := byte(l)
+ dst = append(dst, major|lb)
+ } else {
+ dst = appendCborTypePrefix(dst, major, uint64(l))
+ }
+ return append(dst, s...)
+}