(b []byte, p unsafe.Pointer)
| 436 | } |
| 437 | |
| 438 | func (d decoder) decodeDuration(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 439 | if hasNullPrefix(b) { |
| 440 | return b[4:], nil |
| 441 | } |
| 442 | |
| 443 | // in order to inter-operate with the stdlib, we must be able to interpret |
| 444 | // durations passed as integer values. there's some discussion about being |
| 445 | // flexible on how durations are formatted, but for the time being, it's |
| 446 | // been punted to go2 at the earliest: https://github.com/golang/go/issues/4712 |
| 447 | if len(b) > 0 && b[0] != '"' { |
| 448 | v, r, err := d.parseInt(b, durationType) |
| 449 | if err != nil { |
| 450 | return d.inputError(b, int32Type) |
| 451 | } |
| 452 | |
| 453 | if v < math.MinInt64 || v > math.MaxInt64 { |
| 454 | return r, unmarshalOverflow(b[:len(b)-len(r)], int32Type) |
| 455 | } |
| 456 | |
| 457 | *(*time.Duration)(p) = time.Duration(v) |
| 458 | return r, nil |
| 459 | } |
| 460 | |
| 461 | if len(b) < 2 || b[0] != '"' { |
| 462 | return d.inputError(b, durationType) |
| 463 | } |
| 464 | |
| 465 | i := bytes.IndexByte(b[1:], '"') + 1 |
| 466 | if i <= 0 { |
| 467 | return d.inputError(b, durationType) |
| 468 | } |
| 469 | |
| 470 | s := b[1:i] // trim quotes |
| 471 | |
| 472 | v, err := time.ParseDuration(*(*string)(unsafe.Pointer(&s))) |
| 473 | if err != nil { |
| 474 | return d.inputError(b, durationType) |
| 475 | } |
| 476 | |
| 477 | *(*time.Duration)(p) = v |
| 478 | return b[i+1:], nil |
| 479 | } |
| 480 | |
| 481 | func (d decoder) decodeTime(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 482 | if hasNullPrefix(b) { |
nothing calls this directly
no test coverage detected