BuildNumeric builds a Numeric type that represents any whole number. It normalizes the representation to ensure 1:1 mapping between the number and its representation.
(val string)
| 433 | // It normalizes the representation to ensure 1:1 mapping between the |
| 434 | // number and its representation. |
| 435 | func BuildNumeric(val string) (n Value, err error) { |
| 436 | if val[0] == '-' || val[0] == '+' { |
| 437 | signed, err := strconv.ParseInt(val, 0, 64) |
| 438 | if err != nil { |
| 439 | return Value{}, err |
| 440 | } |
| 441 | n = Value{Numeric(strconv.AppendInt(nil, signed, 10))} |
| 442 | } else { |
| 443 | unsigned, err := strconv.ParseUint(val, 0, 64) |
| 444 | if err != nil { |
| 445 | return Value{}, err |
| 446 | } |
| 447 | n = Value{Numeric(strconv.AppendUint(nil, unsigned, 10))} |
| 448 | } |
| 449 | return n, nil |
| 450 | } |
| 451 | |
| 452 | func writeBinary(typ ValueType, data []byte) ([]byte, error) { |
| 453 | var scratch [binary.MaxVarintLen64]byte |