Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:37:52+00:00 2026-05-11T23:37:52+00:00

I need to send some information on a VxWorks message queue. The information to

  • 0

I need to send some information on a VxWorks message queue. The information to be sent is decided at runtime and may be of different data types. I am using a structure for this –

struct structData
{
  char m_chType;    // variable to indicate the data type - long, float or string
  long m_lData;     // variable to hold long value
  float m_fData;    // variable to hold float value
  string m_strData; // variable to hold string value
};

I am currently sending an array of structData over the message queue.

structData arrStruct[MAX_SIZE];

The problem here is that only one variable in the structure is useful at a time, the other two are useless. The message queue is therefore unneccessarily overloaded.
I can’t use unions because the datatype and the value are required.
I tried using templates, but it doesn’t solve the problem.I can only send an array of structures of one datatype at a time.

template <typename T>
struct structData
{
  char m_chType;
  T m_Data;
}

structData<int> arrStruct[MAX_SIZE];

Is there a standard way to hold such information?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:37:52+00:00Added an answer on May 11, 2026 at 11:37 pm

    There are many ways to handle different datatypes. Besides the union solution you can use a generic struct like :

    typedef struct
    {
        char m_type;
        void* m_data;
    } 
    structData;
    

    This way you know the type and you can cast the void* pointer into the right type.
    This is like the union solution a more C than C++ way of doing things.
    The C++ way would be something using inheritance. You define a base “Data” class an use inheritance to specialize the data. You can use RTTI to check for type if needed.

    But as you stated, you need to send your data over a VxWork queue. I’m no specialist but if those queues are OS realtime queue, all the previous solutions are not good ones. Your problem is that your data have variable length (in particular string) and you need to send them through a queue that probably ask for something like a fixed length datastruct and the actual length of this datastruct.

    In my experience, the right way to handle this is to serialize the data into something like a buffer class/struct. This way you can optimize the size (you only serialize what you need) and you can send your buffer through your queue.

    To serialize you can use something like 1 byte for type then data. To handle variable length data, you can use 1 to n bytes to encode data length, so you can deserialize the data.

    For a string :
    1 byte to code the type (0x01 = string, …)
    2 bytes to code the string length (if you need less than 65536 bytes)
    n data bytes

    So the string “Hello” will be serialized as :

    0x00 0x00 0x07 0x65 0x48 0x6c 0x6c
    

    You need a buffer class and a serializer/deserializer class. Then you do something like :

    serialize data
    send serialized data into queue
    

    and on the other side

    receive data
    deserialize data
    

    I hope it helps and that I have not misunderstood your problem. The serialization part is overkill if the VxWorks queues are not what I think …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 164k
  • Answers 164k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer quoted from: Learning ColdFusion 9: EntityNew() vs. The NEW Operator… May 12, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer Instead of specifiying your listener function, handleAlert(), as a normal… May 12, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer Do it with CSS: label { clear: both; } May 12, 2026 at 12:24 pm

Related Questions

Can anyone tell me the best way to send some xml data from one
I'm writing a small tool in C# which will need to send and receive
I'm about to start a fairly Ajax heavy feature in my company's application. What
I am working on a reliable file transfer program that uses UDP. (for a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.