By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

how to populate struct with bytes array

P: 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
Share this question for a faster answer!
Share on Google+

Post your reply

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