(t reflect.Type, seen map[reflect.Type]*structType)
| 282 | } |
| 283 | |
| 284 | func constructSliceCodec(t reflect.Type, seen map[reflect.Type]*structType) codec { |
| 285 | e := t.Elem() |
| 286 | s := alignedSize(e) |
| 287 | |
| 288 | if e.Kind() == reflect.Uint8 { |
| 289 | // Go 1.7+ behavior: slices of byte types (and aliases) may override the |
| 290 | // default encoding and decoding behaviors by implementing marshaler and |
| 291 | // unmarshaler interfaces. |
| 292 | p := reflect.PointerTo(e) |
| 293 | c := codec{} |
| 294 | |
| 295 | switch { |
| 296 | case e.Implements(jsonMarshalerType): |
| 297 | c.encode = constructJSONMarshalerEncodeFunc(e, false) |
| 298 | case e.Implements(textMarshalerType): |
| 299 | c.encode = constructTextMarshalerEncodeFunc(e, false) |
| 300 | case p.Implements(jsonMarshalerType): |
| 301 | c.encode = constructJSONMarshalerEncodeFunc(e, true) |
| 302 | case p.Implements(textMarshalerType): |
| 303 | c.encode = constructTextMarshalerEncodeFunc(e, true) |
| 304 | } |
| 305 | |
| 306 | switch { |
| 307 | case e.Implements(jsonUnmarshalerType): |
| 308 | c.decode = constructJSONUnmarshalerDecodeFunc(e, false) |
| 309 | case e.Implements(textUnmarshalerType): |
| 310 | c.decode = constructTextUnmarshalerDecodeFunc(e, false) |
| 311 | case p.Implements(jsonUnmarshalerType): |
| 312 | c.decode = constructJSONUnmarshalerDecodeFunc(e, true) |
| 313 | case p.Implements(textUnmarshalerType): |
| 314 | c.decode = constructTextUnmarshalerDecodeFunc(e, true) |
| 315 | } |
| 316 | |
| 317 | if c.encode != nil { |
| 318 | c.encode = constructSliceEncodeFunc(s, t, c.encode) |
| 319 | } else { |
| 320 | c.encode = encoder.encodeBytes |
| 321 | } |
| 322 | |
| 323 | if c.decode != nil { |
| 324 | c.decode = constructSliceDecodeFunc(s, t, c.decode) |
| 325 | } else { |
| 326 | c.decode = decoder.decodeBytes |
| 327 | } |
| 328 | |
| 329 | return c |
| 330 | } |
| 331 | |
| 332 | c := constructCodec(e, seen, true) |
| 333 | return codec{ |
| 334 | encode: constructSliceEncodeFunc(s, t, c.encode), |
| 335 | decode: constructSliceDecodeFunc(s, t, c.decode), |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | func constructSliceEncodeFunc(size uintptr, t reflect.Type, encode encodeFunc) encodeFunc { |
| 340 | return func(e encoder, b []byte, p unsafe.Pointer) ([]byte, error) { |
no test coverage detected
searching dependent graphs…