DecodeFloatAscending returns the remaining byte slice after decoding and the decoded float64 from buf.
(buf []byte)
| 64 | // DecodeFloatAscending returns the remaining byte slice after decoding and the decoded |
| 65 | // float64 from buf. |
| 66 | func DecodeFloatAscending(buf []byte) ([]byte, float64, error) { |
| 67 | if PeekType(buf) != Float { |
| 68 | return buf, 0, errors.Errorf("did not find marker") |
| 69 | } |
| 70 | switch buf[0] { |
| 71 | case floatNaN, floatNaNDesc: |
| 72 | return buf[1:], math.NaN(), nil |
| 73 | case floatNeg: |
| 74 | b, u, err := DecodeUint64Ascending(buf[1:]) |
| 75 | if err != nil { |
| 76 | return b, 0, err |
| 77 | } |
| 78 | u = ^u |
| 79 | return b, math.Float64frombits(u), nil |
| 80 | case floatZero: |
| 81 | return buf[1:], 0, nil |
| 82 | case floatPos: |
| 83 | b, u, err := DecodeUint64Ascending(buf[1:]) |
| 84 | if err != nil { |
| 85 | return b, 0, err |
| 86 | } |
| 87 | return b, math.Float64frombits(u), nil |
| 88 | default: |
| 89 | return nil, 0, errors.Errorf("unknown prefix of the encoded byte slice: %q", buf) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // DecodeFloatDescending decodes floats encoded with EncodeFloatDescending. |
| 94 | func DecodeFloatDescending(buf []byte) ([]byte, float64, error) { |
no test coverage detected
searching dependent graphs…