Encode a map.
(v reflect.Value, enc Encoder)
| 227 | |
| 228 | // Encode a map. |
| 229 | func encodeMap(v reflect.Value, enc Encoder) error { |
| 230 | if v.IsNil() { |
| 231 | enc.EncodeNil() |
| 232 | return nil |
| 233 | } |
| 234 | keys := v.MapKeys() |
| 235 | enc2 := enc.EncodeMap(len(keys)) |
| 236 | for _, k := range keys { |
| 237 | sk, err := stringifyMapKey(k) |
| 238 | if err != nil { |
| 239 | return err |
| 240 | } |
| 241 | if err := encode(v.MapIndex(k), enc2); err != nil { |
| 242 | return err |
| 243 | } |
| 244 | enc2.MapKey(sk) |
| 245 | } |
| 246 | return nil |
| 247 | } |
| 248 | |
| 249 | // k is the key of a map. Encode it as a string. |
| 250 | // Only strings, integers (signed or unsigned), and types that implement |