How to use zeromq to send a string with variable length?

  Kiến thức lập trình

I am new to zeromq and I want to use zeromq to send a self-defined struct. The struct is filled inside a C language project, and I use this struct to collect some log info from the C project. Then I send this struct to the log store.

struct msg {
  char * item1;
  unsigned int amount1;
  char * name1;
  unsigned int cost1;

  ...
};

There are about 10 strings with variable length, and I don’t know how to send this struct to zeromq. One method is separate this struct to 10 parts, each part i can get the string and length, then use zmq_msg_send 10 times. But I wonder whether there is a more elegant way to do this.

Thanks!

I tried to search Google and the official document. No examples solve my question.

New contributor

Chengyuan Zhang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT