在 C# .NET 中读取自定义二进制数据格式

发布于 2024-09-16 02:28:50 字数 718 浏览 9 评论 0原文

我正在尝试为 .NET 中的 AutoCAD DWG 文件编写一个简单的阅读器。我实际上不需要访问文件中的所有数据,因此为整个文件格式编写读取器/写入器所涉及的复杂性不是问题。

我已经设法阅读了基础知识,例如版本、所有标题数据、节定位器记录,但在阅读实际节时遇到问题。

该问题似乎源于以下事实:该格式使用存储某些数据类型的自定义方法。我将按照此处的规格进行操作:

http://www.opendesign.com /files/guestdownloads/OpenDesign_Specification_for_.dwg_files.pdf

具体来说,依赖于读取各个位的类型是我正在努力读取的类型。问题的很大一部分似乎是 C# 的 BinaryReader 只允许您一次读取整个字节,而事实上我相信我需要能够读取单个位,而不仅仅是一次读取 8 位或多个位。

可能是我误解了规范以及如何解释它,但是如果有人可以澄清我如何从流中读取各个位,甚至如何读取上述规范中的某些变量类型需要比简单地读取完整字节更复杂的位操作,那就太好了。

我确实意识到有一些商业图书馆可以用于此目的,但所有这些图书馆的价格都太高,无法完成手头的任务。

非常感谢任何帮助。

I'm trying to write a simple reader for AutoCAD's DWG files in .NET. I don't actually need to access all data in the file so the complexity that would otherwise be involved in writing a reader/writer for the whole file format is not an issue.

I've managed to read in the basics, such as the version, all the header data, the section locator records, but am having problems with reading the actual sections.

The problem seems to stem from the fact that the format uses a custom method of storing some data types. I'm going by the specs here:

http://www.opendesign.com/files/guestdownloads/OpenDesign_Specification_for_.dwg_files.pdf

Specifically, the types that depend on reading in of individual bits are the types I'm struggling to read. A large part of the problem seems to be that C#'s BinaryReader only lets you read in whole bytes at a time, when in fact I believe I need the ability to read in individual bits and not simply 8 bits or a multiple of at a time.

It could be that I'm misunderstanding the spec and how to interpret it, but if anyone could clarify how I might go about reading in individual bits from a stream, or even how to read in some of the variables types in the above spec that require more complex manipulation of bits than simply reading in full bytes then that'd be excellent.

I do realise there are commercial libraries out there for this, but the price is simply too high on all of them to be justifiable for the task at hand.

Any help much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

も星光 2024-09-23 02:28:50

您始终可以使用 BitArray 类按位进行操作操纵。因此,您从文件中读取字节并将它们加载到 BitArray 中,然后访问各个位。

You can always use BitArray class to do bit wise manipulation. So you read bytes from file and load them into BitArray and then access individual bits.

柠北森屋 2024-09-23 02:28:50

对于任何这些库的价格,你绝对无法自己开发稳定的东西。到目前为止你花了多少时间?

For the price of any of those libraries you definitely cannot develop something stable yourself. How much time did you spend so far?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文