473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How can I template a BitConverter class for various return types from a byte array

1
OK, please bear with me and forgive my poor explanation on this, but here goes...

I have 20 different frame types of binary data which is just an array of bytes. Each frame is about 2000 bytes long.

Each frame has a mixture of 16 and 32 bit Ints and UInts which need to be extracted and then multiplied by an LSB to produce either a Single, Double, UInt, or Int data output value.

The first 2 bytes define the type of data in the frame so I can tell how and what position to pull the variables out.

Right now I have thousands of subroutines which use BitConverter.ToInt16, .ToInt32, .ToUInt16 and .ToUInt32 passing in the byte array and position in the array. Then I take the BitConverter output and multiply by an LSB and return the correct data type (Double, Int, UInt)

I would like to create a data dictionary which allows me to handle the data by reading the dictionary the software adapts accordingly.

Example :

One parameter I have in block 10 is an Int32 time in milliseconds at array position 0. The software calls a function with the byte array parameter. The function does a call to Bitconverter.ToInt32(byteArray, 0), then the data is multiplied by .001 and the function returns a Double.

I would like to change this to get the information out of a dictionary. Maybe store the offset into the byte array, LSB of the data, TypeOf BitConverter??, and maybe the return type.

I know I could also make about a dozen functions (numbers 1-12) and store this number in the dictionary. Then have a switch statement which would pick the correct function. For instance one uses BitConverter.ToInt32 returns a Double, one that uses BitConverter.ToUInt16 returns a UInt16, one that uses BitConverter.ToUInt16 that returns a Double, etc, etc. This is my fallback idea, but I think there may be more efficient ways.

I am processing about 20,000 parameters per second so I need for this to be fast.
Jul 16 '15 #1
0 1367

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
3
by: simonc | last post by:
Can you define a property as type Byte array of a specific length? I am trying to pass a byte array which is 3200 bytes in length from one form (in which the bytes are read from a file) to...
12
by: Saurabh Kumar | last post by:
I have a byte array, which i need to send to a class, where it will be stored in an arraylist. I use the following property in the class to accept the byte array, but it seems that the array is...
1
by: kmercer46 | last post by:
I have the byte array generated and I also have the web service generated what i need to know is how to pass a byte array to the web service itself any help would be appreciated.
4
by: infogoogle | last post by:
Hello, i'm having problems with the type of a template function: This code: class A {}; class B : A {}; template<class T B* fnull() { return 0; };
2
by: O.B. | last post by:
I have a structure named EntityState with an explicit layout. The following two operations exist within the class to return a byte array representing the current object. Upon executing them each a...
7
by: mehafi | last post by:
hi, I need to write a few integer numbers to file. A method write from FileStream writes an array of bytes. So how to conwert my integers to byte array? I've tried Convert class, but it hasn't...
1
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, Assuming I have a class/struct with only following types float, int, string what is the most efficient way to pack it to a single byte array before I send it out. I tried to use...
2
Airslash
by: Airslash | last post by:
Hello, I'm currently working with byte arrays to hold data transmitted over the network, and i'm looking for a way to copy a section of that byte array and return it from a function result. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.