Fixed: [Issue 122] unint64 fields with value 0xffffffffffffffff not
supported
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
index c435cfd..ba29fdc 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
@@ -41,7 +41,8 @@
return asList(new Object[][] {
{ "0x1", 1L },
{ "0xA", 10L },
- { "0xFF", 255L }
+ { "0xFF", 255L },
+ { "0xffffffffffffffff", -1L }
});
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
index a142e70..12f6261 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
@@ -14,6 +14,8 @@
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
import org.eclipse.xtext.nodemodel.INode;
+import java.math.BigInteger;
+
/**
* Converts hexadecimal numbers to {@code long}s.
*
@@ -31,13 +33,20 @@
*/
public Long toValue(String string, INode node) throws ValueConverterException {
if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
+ if (!string.startsWith("0x") && !string.startsWith("0X")) throw parsingError(string, node);
+ String withoutZeroX = string.substring(2, string.length());
try {
- return Long.decode(string);
+ BigInteger value = new BigInteger(withoutZeroX, 16);
+ return value.longValue();
} catch (NumberFormatException e) {
throw parsingError(string, node, e);
}
}
+ private ValueConverterException parsingError(String string, INode node) {
+ return parsingError(string, node, null);
+ }
+
private ValueConverterException parsingError(String string, INode node, Exception cause) {
return new ValueConverterException("Couldn't convert '" + string + "' to long.", node, cause);
}