CreateBinaryJSONWithCheck creates a BinaryJSON from interface with error check.
(in any)
| 646 | |
| 647 | // CreateBinaryJSONWithCheck creates a BinaryJSON from interface with error check. |
| 648 | func CreateBinaryJSONWithCheck(in any) (BinaryJSON, error) { |
| 649 | typeCode, buf, err := appendBinaryJSON(nil, in) |
| 650 | if err != nil { |
| 651 | return BinaryJSON{}, err |
| 652 | } |
| 653 | bj := BinaryJSON{TypeCode: typeCode, Value: buf} |
| 654 | // GetElemDepth always returns +1. |
| 655 | if bj.GetElemDepth()-1 > maxJSONDepth { |
| 656 | return BinaryJSON{}, ErrJSONDocumentTooDeep |
| 657 | } |
| 658 | return bj, nil |
| 659 | } |
| 660 | |
| 661 | func appendBinaryJSON(buf []byte, in any) (JSONTypeCode, []byte, error) { |
| 662 | var typeCode byte |
no test coverage detected