Assume mostly positive values in protobuf encoding
This is a change to the encoding scheme, but Gerrit Code Review
(our only downstream library consumer that matters) only needs to
store positive values. Positive values encode smaller with the
int32/int64 format than the sint32/sint64 format.
Change-Id: I5bd93592c59b66b8147133ff33f94be51e5490ed
diff --git a/src/main/java/com/google/gwtorm/protobuf/CodecGen.java b/src/main/java/com/google/gwtorm/protobuf/CodecGen.java
index 2aaf841..4aaeef1 100644
--- a/src/main/java/com/google/gwtorm/protobuf/CodecGen.java
+++ b/src/main/java/com/google/gwtorm/protobuf/CodecGen.java
@@ -438,7 +438,7 @@
cgs.preinc();
cgs.push(f.getColumnID());
cgs.pushFieldValue();
- cgs.doinc("computeSInt32Size", Type.INT_TYPE, Type.INT_TYPE);
+ cgs.doinc("computeInt32Size", Type.INT_TYPE, Type.INT_TYPE);
break;
case Type.FLOAT:
@@ -459,7 +459,7 @@
cgs.preinc();
cgs.push(f.getColumnID());
cgs.pushFieldValue();
- cgs.doinc("computeSInt64Size", Type.INT_TYPE, Type.LONG_TYPE);
+ cgs.doinc("computeInt64Size", Type.INT_TYPE, Type.LONG_TYPE);
break;
case Type.ARRAY:
@@ -707,7 +707,7 @@
cgs.pushCodedOutputStream();
cgs.push(f.getColumnID());
cgs.pushFieldValue();
- cgs.write("writeSInt32", Type.INT_TYPE);
+ cgs.write("writeInt32", Type.INT_TYPE);
break;
case Type.FLOAT:
@@ -728,7 +728,7 @@
cgs.pushCodedOutputStream();
cgs.push(f.getColumnID());
cgs.pushFieldValue();
- cgs.write("writeSInt64", Type.LONG_TYPE);
+ cgs.write("writeInt64", Type.LONG_TYPE);
break;
case Type.ARRAY:
@@ -1112,7 +1112,7 @@
case Type.BYTE:
case Type.SHORT:
case Type.INT:
- cgs.call("readSInt32", Type.INT_TYPE);
+ cgs.call("readInt32", Type.INT_TYPE);
break;
case Type.FLOAT:
@@ -1124,7 +1124,7 @@
break;
case Type.LONG:
- cgs.call("readSInt64", Type.LONG_TYPE);
+ cgs.call("readInt64", Type.LONG_TYPE);
break;
default:
diff --git a/src/main/java/com/google/gwtorm/schema/java/ProtoFileGenerator.java b/src/main/java/com/google/gwtorm/schema/java/ProtoFileGenerator.java
index 2852337..3f2a82a 100644
--- a/src/main/java/com/google/gwtorm/schema/java/ProtoFileGenerator.java
+++ b/src/main/java/com/google/gwtorm/schema/java/ProtoFileGenerator.java
@@ -180,13 +180,13 @@
case Type.BYTE:
case Type.SHORT:
case Type.INT:
- return "sint32";
+ return "int32";
case Type.FLOAT:
return "float";
case Type.DOUBLE:
return "double";
case Type.LONG:
- return "sint64";
+ return "int64";
case Type.ARRAY:
case Type.OBJECT: {
if (clazz == byte[].class) {
diff --git a/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java b/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
index 7c9ce10..f4cb241 100644
--- a/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
+++ b/src/test/java/com/google/gwtorm/protobuf/ProtobufEncoderTest.java
@@ -40,7 +40,7 @@
// name.name
0x0a, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, //
// age
- 0x10, (byte) 0x96, 0x01, //
+ 0x10, (byte) 75, //
// registered (true)
0x18, 0x01 //
//