MCPcopy Create free account
hub / github.com/google/go-cloud / encodeMap

Function encodeMap

docstore/driver/codec.go:229–247  ·  view source on GitHub ↗

Encode a map.

(v reflect.Value, enc Encoder)

Source from the content-addressed store, hash-verified

227
228// Encode a map.
229func encodeMap(v reflect.Value, enc Encoder) error {
230 if v.IsNil() {
231 enc.EncodeNil()
232 return nil
233 }
234 keys := v.MapKeys()
235 enc2 := enc.EncodeMap(len(keys))
236 for _, k := range keys {
237 sk, err := stringifyMapKey(k)
238 if err != nil {
239 return err
240 }
241 if err := encode(v.MapIndex(k), enc2); err != nil {
242 return err
243 }
244 enc2.MapKey(sk)
245 }
246 return nil
247}
248
249// k is the key of a map. Encode it as a string.
250// Only strings, integers (signed or unsigned), and types that implement

Callers 2

EncodeMethod · 0.85
encodeFunction · 0.85

Calls 5

stringifyMapKeyFunction · 0.85
encodeFunction · 0.85
EncodeNilMethod · 0.65
EncodeMapMethod · 0.65
MapKeyMethod · 0.65

Tested by

no test coverage detected