Skip to content

Commit c51a13f

Browse files
committed
Fixed long deserialization problem for longs of ~13digit length
1 parent c9fc4cd commit c51a13f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,8 @@ private long _decodeVLong() throws IOException
23262326
v |= ((ch & 0x7F) << 14);
23272327
ch = buf[_inputPtr++];
23282328
if (ch >= 0) {
2329-
return v | (ch << 21);
2329+
long l2 = (v | (ch << 21));
2330+
return (l2 << 28) | l;
23302331
}
23312332
v |= ((ch & 0x7F) << 21);
23322333

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.fasterxml.jackson.dataformat.protobuf;
2+
3+
public class BigNumPair {
4+
public static final String protobuf_str =
5+
"message BigNumPair {\n"
6+
+ " required int64 long1 = 1;\n"
7+
+ " required int64 long2 = 2;\n"
8+
+ "}\n";
9+
10+
public long long1;
11+
public long long2;
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fasterxml.jackson.dataformat.protobuf;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
5+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
6+
import org.junit.Test;
7+
8+
import java.io.IOException;
9+
10+
/**
11+
* Created by miz on 8/10/16.
12+
*/
13+
public class SerDeserLongTest {
14+
@Test
15+
public void testWeirdLongSerDeser() throws IOException {
16+
ObjectMapper mapper = new ObjectMapper(new ProtobufFactory());
17+
ProtobufSchema schema = ProtobufSchemaLoader.std.parse(BigNumPair.protobuf_str);
18+
19+
BigNumPair bnp = new BigNumPair();
20+
bnp.long1 = 72057594037927935L;
21+
bnp.long2 = 0;
22+
23+
byte[] encoded = mapper.writer(schema).writeValueAsBytes(bnp);
24+
25+
BigNumPair parsed = mapper.readerFor(BigNumPair.class).with(schema).readValue(encoded);
26+
27+
assert parsed.long1 == bnp.long1;
28+
assert parsed.long2 == bnp.long2;
29+
}
30+
}

0 commit comments

Comments
 (0)