| 86 | } |
| 87 | |
| 88 | func decodeFloat(src *bufio.Reader) (float64, int) { |
| 89 | pb := readByte(src) |
| 90 | major := pb & maskOutAdditionalType |
| 91 | minor := pb & maskOutMajorType |
| 92 | if major != majorTypeSimpleAndFloat { |
| 93 | panic(fmt.Errorf("Incorrect Major type is: %d in decodeFloat", major)) |
| 94 | } |
| 95 | |
| 96 | switch minor { |
| 97 | case additionalTypeFloat16: |
| 98 | panic(fmt.Errorf("float16 is not supported in decodeFloat")) |
| 99 | |
| 100 | case additionalTypeFloat32: |
| 101 | pb := readNBytes(src, 4) |
| 102 | switch string(pb) { |
| 103 | case float32Nan: |
| 104 | return math.NaN(), isFloat32 |
| 105 | case float32PosInfinity: |
| 106 | return math.Inf(0), isFloat32 |
| 107 | case float32NegInfinity: |
| 108 | return math.Inf(-1), isFloat32 |
| 109 | } |
| 110 | n := uint32(0) |
| 111 | for i := 0; i < 4; i++ { |
| 112 | n = n * 256 |
| 113 | n += uint32(pb[i]) |
| 114 | } |
| 115 | val := math.Float32frombits(n) |
| 116 | return float64(val), isFloat32 |
| 117 | case additionalTypeFloat64: |
| 118 | pb := readNBytes(src, 8) |
| 119 | switch string(pb) { |
| 120 | case float64Nan: |
| 121 | return math.NaN(), isFloat64 |
| 122 | case float64PosInfinity: |
| 123 | return math.Inf(0), isFloat64 |
| 124 | case float64NegInfinity: |
| 125 | return math.Inf(-1), isFloat64 |
| 126 | } |
| 127 | n := uint64(0) |
| 128 | for i := 0; i < 8; i++ { |
| 129 | n = n * 256 |
| 130 | n += uint64(pb[i]) |
| 131 | } |
| 132 | val := math.Float64frombits(n) |
| 133 | return val, isFloat64 |
| 134 | } |
| 135 | panic(fmt.Errorf("Invalid Additional Type: %d in decodeFloat", minor)) |
| 136 | } |
| 137 | |
| 138 | func decodeStringComplex(dst []byte, s string, pos uint) []byte { |
| 139 | i := int(pos) |