MCPcopy Create free account
hub / github.com/francoispqt/gojay / ArrayKey

Method ArrayKey

encode_array.go:118–146  ·  view source on GitHub ↗

ArrayKey adds an array or slice to be encoded, must be used inside an object as it will encode a key value must implement Marshaler

(key string, v MarshalerJSONArray)

Source from the content-addressed store, hash-verified

116// ArrayKey adds an array or slice to be encoded, must be used inside an object as it will encode a key
117// value must implement Marshaler
118func (enc *Encoder) ArrayKey(key string, v MarshalerJSONArray) {
119 if enc.hasKeys {
120 if !enc.keyExists(key) {
121 return
122 }
123 }
124 if v.IsNil() {
125 enc.grow(2 + len(key))
126 r := enc.getPreviousRune()
127 if r != '{' {
128 enc.writeByte(',')
129 }
130 enc.writeByte('"')
131 enc.writeStringEscape(key)
132 enc.writeBytes(objKeyArr)
133 enc.writeByte(']')
134 return
135 }
136 enc.grow(5 + len(key))
137 r := enc.getPreviousRune()
138 if r != '{' {
139 enc.writeByte(',')
140 }
141 enc.writeByte('"')
142 enc.writeStringEscape(key)
143 enc.writeBytes(objKeyArr)
144 v.MarshalJSONArray(enc)
145 enc.writeByte(']')
146}
147
148// ArrayKeyOmitEmpty adds an array or slice to be encoded and skips if it is nil.
149// Must be called inside an object as it will encode a key.

Callers 12

SliceStringKeyMethod · 0.95
SliceIntKeyMethod · 0.95
SliceFloat64KeyMethod · 0.95
SliceBoolKeyMethod · 0.95
AddArrayKeyMethod · 0.95
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80

Calls 8

keyExistsMethod · 0.95
growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
writeStringEscapeMethod · 0.95
writeBytesMethod · 0.95
IsNilMethod · 0.65
MarshalJSONArrayMethod · 0.65

Tested by 1

MarshalJSONObjectMethod · 0.64