how to store list of varying types
- From: "Nick Schultz" <nick.schultz@xxxxxxxx>
- Date: Wed, 18 Jun 2008 14:50:49 -0700
I am writing a program that parses data found in a proprietary protocol
packet into individual chunks of varying sizes, based on the Opcode tag of
the packet. sizes could be from a single byte to an very large null
terminating string. The parser is part of a pipeline that works on the
incoming packets so that an user at the end can do whatever he/she wants to
do with the data (display it, apply operations, etc)
I planned on creating a ProtocolPacket class that represents an entire
packet, and contains a vector of dataElements. dataElement is a class that
contains a pointer to the data, its size(in bytes) and a char* that stores
its field name.
My original implementation called for malloc'ing the necessary space on the
heap, and passing the user a void pointer to the data on the heap along with
a data length. This then allows me to have a vector<dataElement> that point
to dataElements that represent various types. Does C++ ( or anything simpler
and safe) cover this type of functionality? Or is my design philosophy flat
out flawed?
Thanks,
Nick
.
- Follow-Ups:
- Re: how to store list of varying types
- From: Joseph M . Newcomer
- Re: how to store list of varying types
- From: Giovanni Dicanio
- Re: how to store list of varying types
- From: Ajay Kalra
- Re: how to store list of varying types
- Prev by Date: Zoom example
- Next by Date: Re: WM_COPYDATA between two applications
- Previous by thread: Zoom example
- Next by thread: Re: how to store list of varying types
- Index(es):
Relevant Pages
|