473,399 Members | 2,278 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,399 software developers and data experts.

how to populate struct with bytes array

5
Hello, i have created the struct:
Expand|Select|Wrap|Line Numbers
  1.         #region PacketStructures
  2.  
  3.         struct MainPacket
  4.         {            
  5.             HeaderData headerData;
  6.             public byte moduleType;
  7.             public byte deltaTime;
  8.             public byte mode;
  9.             ZonesDescriptions [] zonesDescriptions;        
  10.         }
  11.  
  12.         struct HeaderData
  13.         {            
  14.             public byte header1;
  15.             public byte header2;
  16.             public byte lenght;
  17.             public byte requestId1;
  18.             public byte requestId2;
  19.             public byte command1;
  20.             public byte command2;
  21.             public byte moduleIndex;
  22.             public byte moduleId;
  23.             public byte action;
  24.             public byte padding;           
  25.         }       
  26.  
  27.         struct ZonesDescriptions
  28.         {
  29.             public byte tempIndxManageIndx;
  30.             public byte defaultTemp1;
  31.             public byte defaultTemp2;
  32.             DaysIntervals [] weekConfig;
  33.         }
  34.  
  35.         struct DaysIntervals
  36.         {
  37.             public byte interval1;
  38.             public byte interval2;
  39.             public byte interval3;
  40.             public byte interval4;      
  41.         }
  42.  
  43.         #endregion
  44.  
and i have reading socket, get bytes array with data from my device through network socket, can i in some way recieved bytes array to assign to my struct? There is only way which i can do to create my struct object and then assigning separate fields by analyzing every byte in array, becouse bytes array lenght is 140 it's complicated and not elegant :)

thanks
Mar 29 '07 #1
0 1093

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

Similar topics

36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
8
by: Mike | last post by:
The following struct, DataStruct, is only part of a larger one that contains additional fields and arrays. I need the explicit layout because this struct is really a union, where some of the...
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
15
by: Ken Allen | last post by:
I have some code from C/C++ that I am attempting to port to C#. I have come across an interesting problem that is quite common in complex C/C++ code: the us of UNION in structure definitions to...
6
by: erdem | last post by:
hi all, i guess this question had been asked many times but i couldnt find a way how can we generate a struct with managed code with fixed size i mean struct easy {
4
by: Abubakar | last post by:
Hi, I am writing a server in C# and client in C++ (pure, not managed). The communication goes on through sockets. In C# I am using NetworkStream to send text data (by converting it to byte array)...
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
3
by: dreiko466 | last post by:
(sorry about my english...) I am a newbie in C (3 month expierience) I have wrote a simple test programm in VS2005, what i do wrong?Please... In this programm i create a double linked list.Then ...
3
by: vikas talwar | last post by:
Hi All, Can you please explain me how the 'C' compiler allocate memory to 'struct'. Please go thu the example below and pls suggest me the solution for my problem. Here is my structure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.