I am relatively new to C# and .Net in general, but have been programming in
many other languages for more years than I want to recall.
I have a problem where an existing set of code (actually a Windows kernel
component developed by a company I do some work for) is returning
information to user space in the buffer from an IOCTL call in a 'streaming'
format that mixes variable length strings, 8-, 16-, 32-, and 64-bit integer
values. The code currently adds NULL bytes to force some alignment just to
keep some other code happy, but this can easily be removed if not needed.
The buffer contains some fixed header fields followed by zero or more 'rows'
or records, which are each variable length due to the fact that they contain
variable length strings.
<ReportID>
<ContextID>
<Record Count>
<More?>
NULL
<Record Length>
<String Data>
NULL
NULL
<Integer Value>
<Integer Value>
<Timestamp>
<String Data>
NULL
NULL
NULL
<IntegerValue>
<Record Length
<String Data>
<continued>
<continued>
NULL
<Integer Value>
<Integer Value>
<Timestamp>
<String Data>
<continued>
<continued>
NULL
<Integer Value>
NULL
NULL
NULL
NULL
I basically want to extract this information field by field and then use the
information to populate a DataSet, making the rows of data look like
information retrieved as if from a database query. I asked some people about
this and they indicated that serialization was the proper approach, but I am
not certain if I follow this.
Do I have to create two (2) classes, one for the header information and one
for the row data, and make each serializable?
The problem that I see is that the serialization process adds contextual
information for each data value being written serialized and the deserializa
tion process requires this information to be present in the stream that is
being read. All of the methods used to retrieve fields from the
SerializationInfo structure seem to require that I identify the field
information in some manner, which implies that this may be some sort of XML
object rather than a raw binary stream.
In my case all that I have is raw data! Presuming that all I have is a
buffer address for the beginning of the buffer above, how can I extract the
individual fields and then use them? I am will to create a class to hold the
retrieved values, but I would then need to use a different offset into the
buffer for each instance of these class objects.
-Ken