开发者

Reading custom binary data formats in C# .NET

开发者 https://www.devze.com 2023-01-12 17:02 出处:网络
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/writ

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开发者_如何学C the task at hand.

Any help much appreciated.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号