Copying from allocated memory to a repetable field.

31 views
Skip to first unread message

Gerardo Melesio

unread,
Jun 13, 2024, 3:17:41 PMJun 13
to Protocol Buffers
I am new to the gRPC implementation in C++ and wantd to see if there is any way of achieving something.

I have a low library in C that is performing some operations with Matrices. It saves the result in a pointer that was allocated dynamically in memory. 

matrixDataA = (double *) malloc(sizeA*sizeof (double ));
//... some code fills MatrixA with data

// then manually copy the data to the protobuf
for(int i = 0; i < sizeA; i++){
                matrixDataA[i] = reply->data_c()[i];
  }

Would there be any way of copying my data in the *double pointer to the reply->data_c(), assuming data_c is a repeated double field?

Gerardo Melesio

unread,
Jun 13, 2024, 3:41:29 PMJun 13
to Protocol Buffers
Bug in the copied code, I'm copying the matrix to protobuf this way:


// then manually copy the data to the protobuf
for(int i = 0; i < sizeA; i++){
                reply->data_c()[i] = matrixDataA[i];
  }

I'm guessing the answer is now because of encoding, but if anyone has an idea I'm happy to hear it out. 
Reply all
Reply to author
Forward
0 new messages