Berkeley DB tuple with unknown data type

I am working with a Berkeley database (in Java). I need to read a tuple where the sequence is a string, either int, or long, and then another string. How to determine if a tuple has int or long? Depending on what the tuple has, I will 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 value is 4 bytes, and long is 8 bytes. If the tuple contains an int, and I read it as long, I get an invalid value as it converts 4 bytes of int + 4 bytes of the next line to long.

+3
source share
1 answer

Berkeley DB Berkeley DB Java Edition, . , , API : -, Java . , , .

, API -, "" "". , , .

API- Java Direct Persistence Layer , . Java, Java, .

+1

Source: https://habr.com/ru/post/1794626/


All Articles