Thread: data structure loadng

  1. #1
    Registered User
    Join Date
    Sep 2015
    Location
    Australia
    Posts
    63

    data structure loadng

    Hi all...

    I am trying to find some information regarding loading structures directly from a buffer. I have used structures using the standard methods but never loading it using a buffer with Packet data as in, casting the buffer to the structure....
    I have been looking but there does not seem to be much information regarding this .

    John

  2. #2
    Registered User
    Join Date
    Sep 2015
    Location
    Australia
    Posts
    63
    Part 2...

    the buffer has hex data of 45 00 00 38, the 45 is split into a 4 and 5, but when casting into a structure it reverses....what am I missing... this is an Internet Header...first row of 32 bits..

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,767
    Quote Originally Posted by JohnGM View Post
    what am I missing...
    I don't know what you're missing, but I know what we're missing: some example code so that we can help you.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,127
    > the buffer has hex data of 45 00 00 38, the 45 is split into a 4 and 5
    Picking external data buffers apart usually involves lots of &, |, << and >> operations.

    Eg.
    int one = buffer[0] & 0xf; // gets 5 out of 0x45
    int two = (buffer[0] >> 4) & 0xf; // gets 4 out of 0x45
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    You may also want to read this: https://en.wikipedia.org/wiki/Endianness if the buffer contains multi-byte pieces of data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure help
    By Cdd101 in forum C Programming
    Replies: 35
    Last Post: 12-01-2013, 11:14 AM
  2. Replies: 2
    Last Post: 04-02-2013, 05:19 AM
  3. difference between data object and data structure?
    By c_lady in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2011, 12:30 PM
  4. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  5. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM