summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorBrian Duff <bduff@google.com>2015-01-06 19:15:20 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-01-06 19:15:20 +0000
commit41be9083a4cef078c9a2e209ac99d065b5e71ad0 (patch)
treee14406bad1f9eefcb7b90ad1070438b0334bd777 /java
parent4353bbc88f513a3c8863cc5b30e765dd5530faa1 (diff)
parentb7cf53ba3b46eb17180465d3d3bb151fa4d93f3d (diff)
downloadexternal_protobuf-41be9083a4cef078c9a2e209ac99d065b5e71ad0.zip
external_protobuf-41be9083a4cef078c9a2e209ac99d065b5e71ad0.tar.gz
external_protobuf-41be9083a4cef078c9a2e209ac99d065b5e71ad0.tar.bz2
Merge "Fix bug with large extension field numbers."
Diffstat (limited to 'java')
-rw-r--r--java/src/main/java/com/google/protobuf/nano/Extension.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/java/src/main/java/com/google/protobuf/nano/Extension.java b/java/src/main/java/com/google/protobuf/nano/Extension.java
index a851daf..728f0dc 100644
--- a/java/src/main/java/com/google/protobuf/nano/Extension.java
+++ b/java/src/main/java/com/google/protobuf/nano/Extension.java
@@ -74,6 +74,11 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
public static final int TYPE_SINT32 = 17;
public static final int TYPE_SINT64 = 18;
+ // Note: these create...() methods take a long for the tag parameter,
+ // because tags are represented as unsigned longs, and these values exist
+ // in generated code as long values. However, they can fit in 32-bits, so
+ // it's safe to cast them to int without loss of precision.
+
/**
* Creates an {@code Extension} of the given message type and tag number.
* Should be used by the generated code only.
@@ -81,8 +86,8 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
* @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
*/
public static <M extends ExtendableMessageNano<M>, T extends MessageNano>
- Extension<M, T> createMessageTyped(int type, Class<T> clazz, int tag) {
- return new Extension<M, T>(type, clazz, tag, false);
+ Extension<M, T> createMessageTyped(int type, Class<T> clazz, long tag) {
+ return new Extension<M, T>(type, clazz, (int) tag, false);
}
/**
@@ -92,8 +97,8 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
* @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
*/
public static <M extends ExtendableMessageNano<M>, T extends MessageNano>
- Extension<M, T[]> createRepeatedMessageTyped(int type, Class<T[]> clazz, int tag) {
- return new Extension<M, T[]>(type, clazz, tag, true);
+ Extension<M, T[]> createRepeatedMessageTyped(int type, Class<T[]> clazz, long tag) {
+ return new Extension<M, T[]>(type, clazz, (int) tag, true);
}
/**
@@ -104,8 +109,8 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
* @param clazz the boxed Java type of this extension
*/
public static <M extends ExtendableMessageNano<M>, T>
- Extension<M, T> createPrimitiveTyped(int type, Class<T> clazz, int tag) {
- return new PrimitiveExtension<M, T>(type, clazz, tag, false, 0, 0);
+ Extension<M, T> createPrimitiveTyped(int type, Class<T> clazz, long tag) {
+ return new PrimitiveExtension<M, T>(type, clazz, (int) tag, false, 0, 0);
}
/**
@@ -117,8 +122,9 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
*/
public static <M extends ExtendableMessageNano<M>, T>
Extension<M, T> createRepeatedPrimitiveTyped(
- int type, Class<T> clazz, int tag, int nonPackedTag, int packedTag) {
- return new PrimitiveExtension<M, T>(type, clazz, tag, true, nonPackedTag, packedTag);
+ int type, Class<T> clazz, long tag, long nonPackedTag, long packedTag) {
+ return new PrimitiveExtension<M, T>(type, clazz, (int) tag, true,
+ (int) nonPackedTag, (int) packedTag);
}
/**