(b []byte, p unsafe.Pointer)
| 400 | } |
| 401 | |
| 402 | func (d decoder) decodeBytes(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 403 | if hasNullPrefix(b) { |
| 404 | *(*[]byte)(p) = nil |
| 405 | return b[4:], nil |
| 406 | } |
| 407 | |
| 408 | if len(b) < 2 { |
| 409 | return d.inputError(b, bytesType) |
| 410 | } |
| 411 | |
| 412 | if b[0] != '"' { |
| 413 | // Go 1.7- behavior: bytes slices may be decoded from array of integers. |
| 414 | if len(b) > 0 && b[0] == '[' { |
| 415 | return d.decodeSlice(b, p, 1, bytesType, decoder.decodeUint8) |
| 416 | } |
| 417 | return d.inputError(b, bytesType) |
| 418 | } |
| 419 | |
| 420 | // The input string contains escaped sequences, we need to parse it before |
| 421 | // decoding it to match the encoding/json package behvaior. |
| 422 | src, r, _, err := d.parseStringUnquote(b, nil) |
| 423 | if err != nil { |
| 424 | return d.inputError(b, bytesType) |
| 425 | } |
| 426 | |
| 427 | dst := make([]byte, base64.StdEncoding.DecodedLen(len(src))) |
| 428 | |
| 429 | n, err := base64.StdEncoding.Decode(dst, src) |
| 430 | if err != nil { |
| 431 | return r, err |
| 432 | } |
| 433 | |
| 434 | *(*[]byte)(p) = dst[:n] |
| 435 | return r, nil |
| 436 | } |
| 437 | |
| 438 | func (d decoder) decodeDuration(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 439 | if hasNullPrefix(b) { |
no test coverage detected