protobuf with 2d array

745 views
Skip to first unread message

suraji...@snehix.com

unread,
May 28, 2021, 3:12:54 PM5/28/21
to grpc.io

Hi All,

Its not a direct grpc query but protobuf with 2D array.

It will be very helpful to get any help.

 

I have a structure as below

 

typedef struct _MsgPixelDataHistory {

        int is_initialized;

        unsigned int user_id;;

        int pen;

        int start;

        int quanta_count[MAX_RETRANS];

        int x[MAX_RETRANS][MAX_PIXELS_PER_QUANTA];

        int y[MAX_RETRANS][MAX_PIXELS_PER_QUANTA];

}MsgPixelDataHistory;

 

And the corresponding protobuf structure

 

message x_his {

        repeated int32 xh=1;

}

 

message y_his {

        repeated int32 yh=1;

}

 

message PixelDataHis {

        int32 start=1;

        bool pen=2;

        repeated x_his x=3;

        repeated y_his y=4;

}

 

Now I have written the write and read function as below, but it doesn’t seems to initialize the array correctly .

What will be the correct way to write and read

Write

 

   PixelDataHis payload ;

        int i,j;

 

        payload.set_start(d->start);

        payload.set_pen(d->pen);

 

        x_his* x_send;

        y_his* y_send;

 

        for(j=0;j<MAX_RETRANS;j++){

                x_send=payload.add_x();

                y_send=payload.add_y();

                for(i=0;i<d->quanta_count[j];i++){

                        x_send->add_xh(d->x[j][i]);

                        y_send->add_yh(d->y[j][i]);

                        x_send->set_xh(i,d->x[j][i]);

                        y_send->set_yh(i,d->y[j][i]);

                }

        }

 

   std::string serializedData = payload.SerializeAsString();

 

Read

   payload.ParseFromString(buffer);

 

        dr->dataType=PX;

        dr->grpcError=0;

        dr->dr.dph.pen=payload.pen();

        dr->dr.dph.start=payload.start();

 

        for(j=0;j<payload.x_size();j++){

                dr->dr.dph.quanta_count[j]=payload.x_size();

                const x_his& xhis = payload.x(i);

                const y_his& yhis = payload.y(i);

                for(i=0;i<xhis.xh_size();i++){

                        dr->dr.dph.x[j][i]=xhis.xh(j);;

                }

                for(i=0;i<yhis.yh_size();i++){

                        dr->dr.dph.y[j][i]=yhis.yh(j);

                }

        }

 

Thanks and Best Regards,

Surajit

+91 9886677508

Reply all
Reply to author
Forward
0 new messages