Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed long deserialization problem for longs of ~13digit length #27

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,8 @@ private long _decodeVLong() throws IOException
v |= ((ch & 0x7F) << 14);
ch = buf[_inputPtr++];
if (ch >= 0) {
return v | (ch << 21);
long l2 = (v | (ch << 21));
return (l2 << 28) | l;
}
v |= ((ch & 0x7F) << 21);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fasterxml.jackson.dataformat.protobuf;

public class BigNumPair {
public static final String protobuf_str =
"message BigNumPair {\n"
+ " required int64 long1 = 1;\n"
+ " required int64 long2 = 2;\n"
+ "}\n";

public long long1;
public long long2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fasterxml.jackson.dataformat.protobuf;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
import org.junit.Test;

import java.io.IOException;

/**
* Created by miz on 8/10/16.
*/
public class SerDeserLongTest {
@Test
public void testWeirdLongSerDeser() throws IOException {
ObjectMapper mapper = new ObjectMapper(new ProtobufFactory());
ProtobufSchema schema = ProtobufSchemaLoader.std.parse(BigNumPair.protobuf_str);

BigNumPair bnp = new BigNumPair();
bnp.long1 = 72057594037927935L;
bnp.long2 = 0;

byte[] encoded = mapper.writer(schema).writeValueAsBytes(bnp);

BigNumPair parsed = mapper.readerFor(BigNumPair.class).with(schema).readValue(encoded);

assert parsed.long1 == bnp.long1;
assert parsed.long2 == bnp.long2;
}
}