数据类型未知的 Berkeley DB 元组
我正在使用伯克利数据库(Java)。我需要读取一个元组,其中序列是一个字符串(int 或 long),然后是另一个字符串。如何确定元组保存的是 int 还是 long?根据元组所包含的内容,我将执行以下操作之一:
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();
int 为 4 字节,long 为 8 字节。如果元组保存一个 int 并且我将其作为 long 读入,则会得到一个无效值,因为它将 4 字节 int + 后面字符串的 4 字节转换为 long。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想在 Berkeley DB 或 Berkeley DB Java 版 论坛,具体取决于您使用的库。此外,您可能需要指定您正在使用哪个 API:键值对、Java 集合或直接持久层。这将有助于更好地了解是否有任何方法可以确定记录结构。
例如,如果您使用键值对 API,则记录中不包含“编码”或“架构”。由调用应用程序知道记录的结构是什么样的。
Java 集合和直接持久层 API 确实对记录的外观有一些概念。您可能会发现 Java 集合教程很有用,以及产品下载中包含的 Java 示例 。
You may want to ask this question on the Berkeley DB or the Berkeley DB Java Edition forum, depending on which library you are using. Also, you may want to specify which API you are using: key-value pair, Java Collections or Direct Persistence Layer. That will help to better understand if there is any way to determine what the record structure looks like.
For example, if you are using the key-value pair API, there is no "encoding" or "schema" included with the record. It's up to the calling application to know what the structure of the record looks like.
The Java Collections and Direct Persistence Layer APIs do have some notion of what the record looks like. You may find the Java Collections Tutorial useful, as well as the Java examples that are included with the product download.