MCPcopy Create free account
hub / github.com/segmentio/encoding / encodeFuncMapAsSetOf

Function encodeFuncMapAsSetOf

thrift/encode.go:210–241  ·  view source on GitHub ↗
(t reflect.Type, seen encodeFuncCache)

Source from the content-addressed store, hash-verified

208}
209
210func encodeFuncMapAsSetOf(t reflect.Type, seen encodeFuncCache) encodeFunc {
211 key := t.Key()
212 typ := TypeOf(key)
213 enc := encodeFuncOf(key, seen)
214
215 return func(w Writer, v reflect.Value, flags flags) error {
216 n := v.Len()
217 if n > math.MaxInt32 {
218 return fmt.Errorf("map length is too large to be represented in thrift: %d > max(int32)", n)
219 }
220
221 err := w.WriteSet(Set{
222 Size: int32(n),
223 Type: typ,
224 })
225 if err != nil {
226 return err
227 }
228 if n == 0 { // empty map
229 return nil
230 }
231
232 iter := v.MapRange()
233 for iter.Next() {
234 if err := enc(w, iter.Key(), flags); err != nil {
235 return err
236 }
237 }
238
239 return nil
240 }
241}
242
243type structEncoder struct {
244 fields []structEncoderField

Callers 1

encodeFuncMapOfFunction · 0.85

Calls 6

encodeFuncOfFunction · 0.85
TypeOfFunction · 0.70
KeyMethod · 0.65
WriteSetMethod · 0.65
LenMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…