473,385 Members | 1,732 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,385 software developers and data experts.

pack heterogeneous data types

Hello,

How do i pack different data types into a struct or an array. Examples
would be helpful.

Say i need to pack an unsigned char( 0xFF) and an long( 0xAAAAAAAA)
into a single array? The reason i need to do this is send a packet over
a network.

Thanks,
-AB

Jul 19 '05 #1
2 1437
as*********@gmail.com wrote:
Hello,

How do i pack different data types into a struct or an array. Examples
would be helpful.

Say i need to pack an unsigned char( 0xFF) and an long( 0xAAAAAAAA)
into a single array? The reason i need to do this is send a packet over
a network.


Look at the struct module, struct.pack sounds like what you need.
Jul 19 '05 #2
as*********@gmail.com wrote:
Hello,

How do i pack different data types into a struct or an array. Examples
would be helpful.

Say i need to pack an unsigned char( 0xFF) and an long( 0xAAAAAAAA)
into a single array? The reason i need to do this is send a packet over
a network.


You've been reposting this on a frequent base all the time for 2 weeks
now - and everytime you've been told (by me and others) to use the
module struct. So - how about actually trying so and come back if you
hit the wall with that for whatever reason instead of unsuccsessfully
shoehorning arrays int something you think they're supposed to be?
Which, BTW, they aren't in _any_ language, as the are homogenous by
nature and only pointer-tricks in C can get you around that.

Diez
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Johannes | last post by:
Hi, I tried to pack eight integer values and one string into one binary string, which I would like to store in a mysql db. I encountered two problems doing this: 1) $this->packed =...
1
by: kj | last post by:
The main rationale I have seen for namespace support in XML is to enable the peaceful coexistence of XML fragments from various sources within the same ("heterogeneous") XML document without their...
4
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
8
by: Markus Dehmann | last post by:
I defined a base class in order to put heterogeneous values into a standard container: All values that I store in the container are derived from my base class. Now when I iterate over the...
12
by: robertbrown1971 | last post by:
My company is working on a bond derivative portfolio analysis tool and we're facing a problem that I did not see adequately addressed any where in literature. I really did RTFM. I'm very...
5
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: ...
2
by: Arash Partow | last post by:
Hi all, I've got a question related to emulating aspects of polymorphism with CRTP. Below is a typical polymorphic class hierarchy with a definition of a "somewhat" heterogeneous container of...
10
by: giddy | last post by:
hi , I' know what the StructLayoutAttribute does. I've seen it being used. But what does the Pack field do!? This is what MSDN says: Controls the alignment of data fields of a class or...
5
by: Gordon Airporte | last post by:
This is one of those nice, permissive Python features but I was wondering how often people actually use lists holding several different types of objects. It looks like whenever I need to group...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.