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