MCPcopy Index your code
hub / github.com/google/gvisor / encodeMap

Method encodeMap

pkg/state/encode.go:443–463  ·  view source on GitHub ↗

encodeMap encodes a map.

(obj reflect.Value, dest *wire.Object)

Source from the content-addressed store, hash-verified

441
442// encodeMap encodes a map.
443func (es *encodeState) encodeMap(obj reflect.Value, dest *wire.Object) {
444 if obj.IsNil() {
445 // Because there is a difference between a nil map and an empty
446 // map, we need to not decode in the case of a truly nil map.
447 *dest = wire.Nil{}
448 return
449 }
450 l := obj.Len()
451 m := &wire.Map{
452 Keys: make([]wire.Object, l),
453 Values: make([]wire.Object, l),
454 }
455 *dest = m
456 for i, k := range obj.MapKeys() {
457 v := obj.MapIndex(k)
458 // Map keys must be encoded using the full value because the
459 // type will be omitted after the first key.
460 es.encodeObject(k, encodeAsValue, &m.Keys[i])
461 es.encodeObject(v, encodeAsValue, &m.Values[i])
462 }
463}
464
465// objectEncoder is for encoding structs.
466type objectEncoder struct {

Callers 1

encodeObjectMethod · 0.95

Calls 2

encodeObjectMethod · 0.95
LenMethod · 0.65

Tested by

no test coverage detected