AddInterface adds an interface{} to be encoded, must be used inside a slice or array encoding (does not encode a key)
(value interface{})
| 50 | |
| 51 | // AddInterface adds an interface{} to be encoded, must be used inside a slice or array encoding (does not encode a key) |
| 52 | func (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 |
| 92 | func (enc *Encoder) AddInterfaceKey(key string, value interface{}) { |