(buf []byte, in any)
| 659 | } |
| 660 | |
| 661 | func appendBinaryJSON(buf []byte, in any) (JSONTypeCode, []byte, error) { |
| 662 | var typeCode byte |
| 663 | var err error |
| 664 | switch x := in.(type) { |
| 665 | case nil: |
| 666 | typeCode = JSONTypeCodeLiteral |
| 667 | buf = append(buf, JSONLiteralNil) |
| 668 | case bool: |
| 669 | typeCode = JSONTypeCodeLiteral |
| 670 | if x { |
| 671 | buf = append(buf, JSONLiteralTrue) |
| 672 | } else { |
| 673 | buf = append(buf, JSONLiteralFalse) |
| 674 | } |
| 675 | case int64: |
| 676 | typeCode = JSONTypeCodeInt64 |
| 677 | buf = appendBinaryUint64(buf, uint64(x)) |
| 678 | case uint64: |
| 679 | typeCode = JSONTypeCodeUint64 |
| 680 | buf = appendBinaryUint64(buf, x) |
| 681 | case float64: |
| 682 | typeCode = JSONTypeCodeFloat64 |
| 683 | buf = appendBinaryFloat64(buf, x) |
| 684 | case json.Number: |
| 685 | typeCode, buf, err = appendBinaryNumber(buf, x) |
| 686 | if err != nil { |
| 687 | return typeCode, nil, errors.Trace(err) |
| 688 | } |
| 689 | case string: |
| 690 | typeCode = JSONTypeCodeString |
| 691 | buf = appendBinaryString(buf, x) |
| 692 | case BinaryJSON: |
| 693 | typeCode = x.TypeCode |
| 694 | buf = append(buf, x.Value...) |
| 695 | case []any: |
| 696 | typeCode = JSONTypeCodeArray |
| 697 | buf, err = appendBinaryArray(buf, x) |
| 698 | if err != nil { |
| 699 | return typeCode, nil, errors.Trace(err) |
| 700 | } |
| 701 | case map[string]any: |
| 702 | typeCode = JSONTypeCodeObject |
| 703 | buf, err = appendBinaryObject(buf, x) |
| 704 | if err != nil { |
| 705 | return typeCode, nil, errors.Trace(err) |
| 706 | } |
| 707 | case Opaque: |
| 708 | typeCode = JSONTypeCodeOpaque |
| 709 | buf = appendBinaryOpaque(buf, x) |
| 710 | case Time: |
| 711 | typeCode = JSONTypeCodeDate |
| 712 | if x.Type() == mysql.TypeDatetime { |
| 713 | typeCode = JSONTypeCodeDatetime |
| 714 | } else if x.Type() == mysql.TypeTimestamp { |
| 715 | typeCode = JSONTypeCodeTimestamp |
| 716 | } |
| 717 | buf = appendBinaryUint64(buf, uint64(x.CoreTime())) |
| 718 | case Duration: |
no test coverage detected