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

Method AddInterface

encode_interface.go:52–89  ·  view source on GitHub ↗

AddInterface adds an interface{} to be encoded, must be used inside a slice or array encoding (does not encode a key)

(value interface{})

Source from the content-addressed store, hash-verified

50
51// AddInterface adds an interface{} to be encoded, must be used inside a slice or array encoding (does not encode a key)
52func (enc *Encoder) AddInterface(value interface{}) {
53 switch vt := value.(type) {
54 case string:
55 enc.AddString(vt)
56 case bool:
57 enc.AddBool(vt)
58 case MarshalerJSONArray:
59 enc.AddArray(vt)
60 case MarshalerJSONObject:
61 enc.AddObject(vt)
62 case int:
63 enc.AddInt(vt)
64 case int64:
65 enc.AddInt(int(vt))
66 case int32:
67 enc.AddInt(int(vt))
68 case int8:
69 enc.AddInt(int(vt))
70 case uint64:
71 enc.AddUint64(vt)
72 case uint32:
73 enc.AddInt(int(vt))
74 case uint16:
75 enc.AddInt(int(vt))
76 case uint8:
77 enc.AddInt(int(vt))
78 case float64:
79 enc.AddFloat(vt)
80 case float32:
81 enc.AddFloat32(vt)
82 default:
83 if vt != nil {
84 enc.err = InvalidMarshalError(fmt.Sprintf(invalidMarshalErrorMsg, vt))
85 return
86 }
87 return
88 }
89}
90
91// AddInterfaceKey adds an interface{} to be encoded, must be used inside an object as it will encode a key
92func (enc *Encoder) AddInterfaceKey(key string, value interface{}) {

Callers 5

TestEncoderArrErrorsFunction · 0.95
MarshalJSONArrayMethod · 0.45
UnmarshalJSONObjectMethod · 0.45
UnmarshalJSONObjectMethod · 0.45
MarshalStreamMethod · 0.45

Calls 9

AddStringMethod · 0.95
AddBoolMethod · 0.95
AddArrayMethod · 0.95
AddObjectMethod · 0.95
AddIntMethod · 0.95
AddUint64Method · 0.95
AddFloatMethod · 0.95
AddFloat32Method · 0.95
InvalidMarshalErrorTypeAlias · 0.85

Tested by 5

TestEncoderArrErrorsFunction · 0.76
MarshalJSONArrayMethod · 0.36
UnmarshalJSONObjectMethod · 0.36
UnmarshalJSONObjectMethod · 0.36
MarshalStreamMethod · 0.36