Berkeley DB tuple with unknown datatype
- by Ronnie
I'm working with a Berkeley database (in Java). I need to read a tuple where the sequence is a string, either an int or long, then another string. How can I determine if the tuple holds an int or a long? Depending on what the tuple holds, I'll do one of the following:
String s1 = input.readString();
int num1 = input.readInt();
String s2= input.readString();
or
String s1 = input.readString();
long num1 = input.readLong();
String s2= input.readString();
The int is 4 bytes and the long is 8 bytes. If the tuple holds an int and I read it in as a long, I get an invalid value as it converts the 4 byte int + 4 bytes of the following string into a long.