Berkeley DB tuple with unknown datatype
Posted
by
Ronnie
on Stack Overflow
See other posts from Stack Overflow
or by Ronnie
Published on 2011-02-25T05:04:15Z
Indexed on
2011/02/25
7:25 UTC
Read the original article
Hit count: 186
java
|berkeley-db
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.
© Stack Overflow or respective owner