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

Method AddInterfaceKey

encode_interface.go:92–131  ·  view source on GitHub ↗

AddInterfaceKey adds an interface{} to be encoded, must be used inside an object as it will encode a key

(key string, value interface{})

Source from the content-addressed store, hash-verified

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{}) {
93 switch vt := value.(type) {
94 case string:
95 enc.AddStringKey(key, vt)
96 case bool:
97 enc.AddBoolKey(key, vt)
98 case MarshalerJSONArray:
99 enc.AddArrayKey(key, vt)
100 case MarshalerJSONObject:
101 enc.AddObjectKey(key, vt)
102 case int:
103 enc.AddIntKey(key, vt)
104 case int64:
105 enc.AddIntKey(key, int(vt))
106 case int32:
107 enc.AddIntKey(key, int(vt))
108 case int16:
109 enc.AddIntKey(key, int(vt))
110 case int8:
111 enc.AddIntKey(key, int(vt))
112 case uint64:
113 enc.AddIntKey(key, int(vt))
114 case uint32:
115 enc.AddIntKey(key, int(vt))
116 case uint16:
117 enc.AddIntKey(key, int(vt))
118 case uint8:
119 enc.AddIntKey(key, int(vt))
120 case float64:
121 enc.AddFloatKey(key, vt)
122 case float32:
123 enc.AddFloat32Key(key, vt)
124 default:
125 if vt != nil {
126 enc.err = InvalidMarshalError(fmt.Sprintf(invalidMarshalErrorMsg, vt))
127 return
128 }
129 return
130 }
131}
132
133// AddInterfaceKeyOmitEmpty adds an interface{} to be encoded, must be used inside an object as it will encode a key
134func (enc *Encoder) AddInterfaceKeyOmitEmpty(key string, v interface{}) {

Callers 4

MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80
MarshalJSONObjectMethod · 0.80

Calls 8

AddStringKeyMethod · 0.95
AddBoolKeyMethod · 0.95
AddArrayKeyMethod · 0.95
AddObjectKeyMethod · 0.95
AddIntKeyMethod · 0.95
AddFloatKeyMethod · 0.95
AddFloat32KeyMethod · 0.95
InvalidMarshalErrorTypeAlias · 0.85

Tested by 4

MarshalJSONObjectMethod · 0.64
MarshalJSONObjectMethod · 0.64
MarshalJSONObjectMethod · 0.64
MarshalJSONObjectMethod · 0.64