()
| 1181 | } |
| 1182 | |
| 1183 | func (p *TSimpleJSONProtocol) readNumeric() (Numeric, error) { |
| 1184 | isNull, err := p.readIfNull() |
| 1185 | if isNull || err != nil { |
| 1186 | return NUMERIC_NULL, err |
| 1187 | } |
| 1188 | hasDecimalPoint := false |
| 1189 | nextCanBeSign := true |
| 1190 | hasE := false |
| 1191 | MAX_LEN := 40 |
| 1192 | buf := bytes.NewBuffer(make([]byte, 0, MAX_LEN)) |
| 1193 | continueFor := true |
| 1194 | inQuotes := false |
| 1195 | for continueFor { |
| 1196 | c, err := p.reader.ReadByte() |
| 1197 | if err != nil { |
| 1198 | if errors.Is(err, io.EOF) { |
| 1199 | break |
| 1200 | } |
| 1201 | return NUMERIC_NULL, NewTProtocolException(err) |
| 1202 | } |
| 1203 | switch c { |
| 1204 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 1205 | buf.WriteByte(c) |
| 1206 | nextCanBeSign = false |
| 1207 | case '.': |
| 1208 | if hasDecimalPoint { |
| 1209 | e := fmt.Errorf("Unable to parse number with multiple decimal points '%s.'", buf.String()) |
| 1210 | return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) |
| 1211 | } |
| 1212 | if hasE { |
| 1213 | e := fmt.Errorf("Unable to parse number with decimal points in the exponent '%s.'", buf.String()) |
| 1214 | return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) |
| 1215 | } |
| 1216 | buf.WriteByte(c) |
| 1217 | hasDecimalPoint, nextCanBeSign = true, false |
| 1218 | case 'e', 'E': |
| 1219 | if hasE { |
| 1220 | e := fmt.Errorf("Unable to parse number with multiple exponents '%s%c'", buf.String(), c) |
| 1221 | return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) |
| 1222 | } |
| 1223 | buf.WriteByte(c) |
| 1224 | hasE, nextCanBeSign = true, true |
| 1225 | case '-', '+': |
| 1226 | if !nextCanBeSign { |
| 1227 | e := fmt.Errorf("Negative sign within number") |
| 1228 | return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) |
| 1229 | } |
| 1230 | buf.WriteByte(c) |
| 1231 | nextCanBeSign = false |
| 1232 | case ' ', 0, '\t', '\n', '\r', JSON_RBRACE[0], JSON_RBRACKET[0], JSON_COMMA[0], JSON_COLON[0]: |
| 1233 | p.reader.UnreadByte() |
| 1234 | continueFor = false |
| 1235 | case JSON_NAN[0]: |
| 1236 | if buf.Len() == 0 { |
| 1237 | buffer := make([]byte, len(JSON_NAN)) |
| 1238 | buffer[0] = c |
| 1239 | _, e := p.reader.Read(buffer[1:]) |
| 1240 | if e != nil { |
no test coverage detected