how to store list of varying types



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





.



Relevant Pages

  • how to store list of varying types
    ... 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. ... and contains a vector of dataElements. ...
    (microsoft.public.vc.language)
  • Re: how to store list of varying types
    ... packet into individual chunks of varying sizes, based on the Opcode tag of ... the packet. ... Why would you ever use a char* to store a string? ... representation I would just store bytes and cache a concrete object ...
    (microsoft.public.vc.language)
  • Re: how to store list of varying types
    ... I always tell people "design the data structure FIRST" Once that is done, ... packet into individual chunks of varying sizes, based on the Opcode tag of ... the packet. ... Think about the fundamental object you need and build from that ...
    (microsoft.public.vc.mfc)
  • Re: how to store list of varying types
    ... packet into individual chunks of varying sizes, based on the Opcode tag of ... the packet. ... Think about the fundamental object you need and build from that for the simplest start. ...
    (microsoft.public.vc.mfc)
  • Re: how to store list of varying types
    ... You need to say more about the packet. ... virtual void SomeMethod() PURE; ... and contains a vector of dataElements. ... instead of CString, or, since the packets are probably defined as 8-bit packets, CStringA. ...
    (microsoft.public.vc.mfc)