|
-
April 2nd, 2009, 08:56 PM
#1
byte mapped records - best approach?
I need to return a set of values that will be used in a mainframe application. I am using C#. I have a set of record definitions like this:
Header record:
TranCode - 2 bytes - ASCII 00
Filler - 1 byte ASCII SPACE (0x20)
TranName - 26 bytes - ASCII value - Left justified - Pad with ASCII 0x20
DataRecord:
DataTypeVal - 2 bytes - ASCII 00 thru 28
DataValue - 18 bytes - ASCII numeric values
RecordDelimiter - 4 bytes - ASCII "END."
Well, you get the idea. There will also be a trailing record to finish things up and the data records can be more than one. Ultimately this will be written to a file that is transmitted to the mainframe and then digested there.
Just to clarify, all of the data will be static except for data record elements (and their supporting records). The goal is to produce a sealed class library that the consumer can instantiate, then iterate through some DB records and calling an ADD method and finally an Execute method. The class library would then build the record data, write it to a file, zip it and then send it to the destination via secure FTP.
I need a reccomended approach to representing this data structure that is byte position specific in C#.
Framework is .NET 2
Thanks in advance!
-
April 3rd, 2009, 01:56 PM
#2
Re: byte mapped records - best approach?
Is this the wrong area to post this question?
-
April 3rd, 2009, 02:45 PM
#3
Re: byte mapped records - best approach?
Before the C# pros answer your question, please let me make some comments and make some assuptions to see if I understand your question the way you meant it.
You say that "this will be written to a file that is transmitted to the mainframe", so you want to write some data to a binary file that has a header section/record, a data section including one or mode data records, and an end section (trailing record).
If my understanding is correct, then I think one approach would be to define 3 data structures: one for the header, one for a data unit, and one for the trailer; then, create an array of data units. When you instantiate a particular data structure, populate it first with the default values you indicated. There are many articles on the Web on writing/reading binary files in C# (for example: http://www.java2s.com/Code/CSharp/Fi...riterClass.htm).
Last edited by tr00don; April 3rd, 2009 at 02:55 PM.
-
April 4th, 2009, 04:50 AM
#4
Re: byte mapped records - best approach?
What you probably want to do is separate the encoding/decoding from your actual datastructure. You can have a class internally which represents your data as:
TranName - 26 bytes - ASCII value - byte[] (or string?)
DataTypeVal - 2 bytes - ushort/short
DataValue - 18 bytes - byte[] (or string?)
Then your decoder will take care of validating and parsing the header/footer for you and the encoder will take care of adding a valid header/footer to the data before writing it to the database/file.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|