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

Method ObjectWithKeys

encode_object.go:135–164  ·  view source on GitHub ↗

ObjectWithKeys adds an object to be encoded, must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject. It will only encode the keys in keys.

(v MarshalerJSONObject, keys []string)

Source from the content-addressed store, hash-verified

133// ObjectWithKeys adds an object to be encoded, must be used inside a slice or array encoding (does not encode a key)
134// value must implement MarshalerJSONObject. It will only encode the keys in keys.
135func (enc *Encoder) ObjectWithKeys(v MarshalerJSONObject, keys []string) {
136 if v.IsNil() {
137 enc.grow(2)
138 r := enc.getPreviousRune()
139 if r != '{' && r != '[' {
140 enc.writeByte(',')
141 }
142 enc.writeByte('{')
143 enc.writeByte('}')
144 return
145 }
146 enc.grow(4)
147 r := enc.getPreviousRune()
148 if r != '[' {
149 enc.writeByte(',')
150 }
151 enc.writeByte('{')
152
153 var origKeys = enc.keys
154 var origHasKeys = enc.hasKeys
155 enc.hasKeys = true
156 enc.keys = keys
157
158 v.MarshalJSONObject(enc)
159
160 enc.hasKeys = origHasKeys
161 enc.keys = origKeys
162
163 enc.writeByte('}')
164}
165
166// ObjectOmitEmpty adds an object to be encoded or skips it if IsNil returns true.
167// Must be used inside a slice or array encoding (does not encode a key)

Callers 1

TestEncodeObjectWithKeysFunction · 0.95

Calls 5

growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
IsNilMethod · 0.65
MarshalJSONObjectMethod · 0.65

Tested by 1

TestEncodeObjectWithKeysFunction · 0.76