简体   繁体   English

寻找一种优雅的方式来存储表数据

[英]Looking for an elegant way to store table data

First post here :) Relatively new to C# coming from C++ originally.这里的第一篇文章:) 最初来自 C++ 的 C# 相对较新。 I'm currently working with table binaries that use the following format:我目前正在使用使用以下格式的表二进制文件:

struct Table
{
Int32 rowCount;
Int32 columnCount;
customString columnNames[columnCount];
Int32 columnTypes[columnCount];
// Followed by the rowdata, where each type is different based on the columnType (0 = Int32, 1 = float, 2/3 = customString, 4 = Int64
};

struct customString
{
Int16 len;
char str[len]; // There is no null terminator
};

Due to the variable sizes of the strings I cannot define a struct for each table and cast.由于字符串的可变大小,我无法为每个表定义结构并进行转换。 All tables have different column names too.所有表也有不同的列名。 I'd like to be able to parse every single table in this format and easily be able to read all struct members.我希望能够以这种格式解析每个表,并且能够轻松读取所有结构成员。 How should I go about this without filling in 240 struct members manually for each table?如果不为每个表手动填充 240 个结构成员,我应该如何处理?

Thanks a lot!非常感谢!

this might not be to helpful but i would take a closer look at the data in the binary file to break down what and how to present/ hold you data.这可能没有帮助,但我会仔细查看二进制文件中的数据,以分解呈现/保存数据的内容和方式。

the table struct could be much easier build with list for your rows and a row can have in turn list for fields and on the field level you can do all the hard work with figure out the type of the data and what else you need to keep track of.表结构可以更容易地使用您的行列表构建,并且一行可以依次包含字段列表,在字段级别,您可以完成所有艰苦的工作,找出数据的类型以及您需要保留的其他内容踪迹。

Again this isnt a soluction ist only an suggestion because what you show us isnt a "final" stage i guess.同样,这不是一个解决方案,只是一个建议,因为我猜你向我们展示的不是“最终”阶段。

regards问候

Markus马库斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM