Skip to content

Commit

Permalink
Part 4 of #443: ProtobufParser (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 7, 2024
1 parent 084628e commit da95300
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.core.util.TextBuffer;
import com.fasterxml.jackson.core.util.VersionUtil;

import com.fasterxml.jackson.dataformat.protobuf.schema.*;

public class ProtobufParser extends ParserMinimalBase
Expand Down Expand Up @@ -1565,12 +1566,12 @@ public NumberType getNumberType() throws IOException
_checkNumericValue(NR_UNKNOWN); // will also check event type
}
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
if ((_numTypesValid & NR_INT) != 0) {
return NumberType.INT;
}
if ((_numTypesValid & NR_LONG) != 0) {
return NumberType.LONG;
}
if ((_numTypesValid & NR_INT) != 0) {
return NumberType.INT;
}
return NumberType.BIG_INTEGER;
}

Expand All @@ -1589,6 +1590,23 @@ public NumberType getNumberType() throws IOException
return NumberType.FLOAT;
}

@Override // since 2.17
public NumberTypeFP getNumberTypeFP() throws IOException
{
if (_currToken == JsonToken.VALUE_NUMBER_FLOAT) {
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
return NumberTypeFP.BIG_DECIMAL;
}
if ((_numTypesValid & NR_DOUBLE) != 0) {
return NumberTypeFP.DOUBLE64;
}
if ((_numTypesValid & NR_FLOAT) != 0) {
return NumberTypeFP.FLOAT32;
}
}
return NumberTypeFP.UNKNOWN;
}

@Override
public int getIntValue() throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.fasterxml.jackson.core.JsonToken;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.core.JsonParser.NumberTypeFP;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
Expand Down Expand Up @@ -58,7 +60,7 @@ public NamedStrings(String n, String... v) {
/**********************************************************
*/

final ObjectMapper MAPPER = newObjectMapper();
private final ObjectMapper MAPPER = newObjectMapper();

public void testReadPointInt() throws Exception
{
Expand All @@ -85,6 +87,8 @@ public void testReadPointInt() throws Exception
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("x", p.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(NumberType.INT, p.getNumberType());
assertEquals(NumberTypeFP.UNKNOWN, p.getNumberTypeFP());
assertEquals(input.x, p.getIntValue());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("y", p.currentName());
Expand Down Expand Up @@ -118,6 +122,8 @@ public void testReadPointLong() throws Exception
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("x", p.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(NumberType.LONG, p.getNumberType());
assertEquals(NumberTypeFP.UNKNOWN, p.getNumberTypeFP());
assertEquals(input.x, p.getIntValue());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("y", p.currentName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.core.JsonParser.NumberTypeFP;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
Expand Down Expand Up @@ -333,6 +334,7 @@ private void _verifyDoubleArray(byte[] doc, ProtobufSchema schema,
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(NumberType.DOUBLE, p.getNumberType());
assertEquals(NumberTypeFP.DOUBLE64, p.getNumberTypeFP());
assertEquals(Double.valueOf(inputValues[0]), p.getNumberValue());
assertFalse(p.isNaN());
assertEquals(new BigDecimal(inputValues[0]), p.getDecimalValue());
Expand Down Expand Up @@ -395,6 +397,7 @@ private void _verifyFloatArray(byte[] doc, ProtobufSchema schema,
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(NumberType.FLOAT, p.getNumberType());
assertEquals(NumberTypeFP.FLOAT32, p.getNumberTypeFP());
assertEquals(Float.valueOf(inputValues[0]), p.getNumberValue());
assertFalse(p.isNaN());

Expand Down

0 comments on commit da95300

Please sign in to comment.