When I am using https://cs.chromium.org/chromium/src/url/mojom/origin.mojom, the port domain has data type uint16, which makes sense in C++ since there is unsigned short type.
However, we have the following bindings for Java [1]:
mojom.UINT16.spec: 'short',
mojom.UINT32.spec: 'int',
mojom.UINT64.spec: 'long',
mojom.UINT8.spec: 'byte',
Since Java has no unsigned short/int/long/byte [2], we will receive a signed short in Java, it will overflow to a negative number if the original value is big enough. Java's Short.toUnsignedInt() API is available from API level 26 and above, so that is not an option currently.
Do we want to convert all of them to the next long enough data type except |long|? Otherwise I'll need something like
short port ...
int portInt = port & 0xffff;
to convert it to int. For my usage, I am converting the origin mojom type to android.net.Uri [3], which has port with int data type, so eventually it will be an int.
[1] https://cs.chromium.org/chromium/src/mojo/public/tools/bindings/generators/mojom_java_generator.py?rcl=64f9fa5153f9e73ca45193e54a01fa077e59131f&l=54
[2] https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
[3] https://developer.android.com/reference/android/net/Uri