[protobuf] Serializing in c and deSerializing in python

2014-08-29 Thread Mani Abedini
Hi all,

I have a problem serializing a message in C and deserializing it in python.

The problem is that when I serialize a message in C, some of the values are 
0 (zero) or negative (e.g. -150).
Thus I can not send the serialize message as char* to python.
Because, ctype of python expect string as null terminated.
Even if I send it as array of int, then I dont know how to reconstruct the 
original string in python. 
Apparently str() does not let me assign each element directly aslo, chr() 
does not let me convert negative values to character. 

Any comment ? 

Thanks in advance for your help.
Mani

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Serializing in C then deserializing in python

2014-08-29 Thread Mani Abedini
Hi

I have a bit of issue for serializing in C and deserializing it in python,

I defined a message to carry data, serialize it into array in C, then send 
it over to python (via ctype).

I noticed that since the serialized array may contains 0 (zero) values, It 
is better of to send as array of int to python,
otherwise truncated message would be transferred ( python expects strings 
are NULL terminated ). In this case
when I receive an array of int values in python, I don't know how to 
reconstruct a string from those values and feed it to ParseFromString()
because ParseFromString() does not accept array_of_int, because it does not 
have len(). I can not build a string in python especially some of the 
values are negative and python does not let me convert negative value to 
char.

Any comment ?

Codes:


message siftOut{
message keypoint {
required float x = 1;
repeated float descr= 2 [packed=true];
}
repeated keypoint keypoints= 1;
} ; 
 
When I filled a message such as:

siftOut vFrmDescr;
siftOut_keypoint *frmDescr = vFrmDescr.add_keypoints();
int l ;
frmDescr-set_x ( (float) k - x );
for (l = 0 ; l  128 ; ++l) {
frmDescr-add_descr (   (512.0 * descr [l]) ) ;
}

Then   
  
char * charOut = new char[vFrmDescr.ByteSize()];

vFrmDescr.SerializeToArray( charOut , vFrmDescr.ByteSize()); 

and send it to python

in python
   LIB = cdll[_loc]
LIB.protoBufFunc.argtypes =[c_char_p , c_int32 ]
LIB.protoBufFunc.restype  = POINTER(c_int32)
stDescriptors = LIB.protoBufFunc(  A sample dataa in string 
format  , 50 );

 Now how can I use parsefromString() in python to read  stDescriptors  ?

Appreciate your help in advance.

Regards
Mani

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.