farsounder / protobuf-matlab

Automatically exported from code.google.com/p/protobuf-matlab
Other
26 stars 13 forks source link

Instructions for protobuf-matlab use may be incorrect #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi there,

Goal: After the Makefile.am was edited and the protoc binary was correctly 
built, I attempted to get a protobuf message transmitted correctly over the 
wire. So I followed the example.

1.

Following the example as is in matlab R2011b didn't work. This is because in 
the 
"pb_read_*()" functions, it is expecting a buffer to read values from. If that 
buffer doesn't exist, it will fall into a check that all required fields are 
set. Since the message is just instantiated and no buffer is available, the 
check fails and the object won't be instantiated. It becomes unusable, so 
there's no way to create the actual object this way.

I modified the library code to only perform the check if the length of the 
buffer was > 0. This allowed me to instantiate the object, so that I could 
manipulate it.

2.

The next snag appeared when using pblib_set. Note: I'm by no means a matlab 
expert, I'm actually a first-time user helping someone out. My observations 
here were that the remote process wasn't actually getting the values that I 
thought were being set. Further investigation revealed the following. 

I put a disp( bob ) call before pblib_set calls and after and this demonstrated 
that none of the set calls persisted. The function definition has an "input" 
msg parameter and another "msg" parameter going out. It appears that in this 
version of matlab at least (R2011b), a copy was made of that object and this 
copy was manipulated instead of the "in" object from matlab. 

I think it's helpful if the "out" and "in" parameters into this function refer 
to the same object, but not sure if that can be forced in matlab that way. 
Having additional copies would also raise memory concerns, because every 
attribute being set would copy the entire object by itself.

For the purpose of this demo, I did manage to get this to work by using 
syntaxes like:

bob = pblib_set( bob, 'id', ... );

Greatly appreciate your comments on this issue and whether this should work as 
specified, or whether there are indeed issues with matlab or future versions of 
it after this was released.

I noticed however that whatever value I set on a simple integer, this value was 
not actually transmitted. 

Original issue reported on code.google.com by gtoons...@gmail.com on 13 Oct 2011 at 4:29

GoogleCodeExporter commented 9 years ago
Issue resolved via an update to the example on the home page.

Original comment by evan.lap...@gmail.com on 24 Oct 2011 at 8:19

GoogleCodeExporter commented 9 years ago
Hello. I ran into the same problem mentioned under 1, and the example on the 
homepage still has the line "bob = pb_read_Person();", which does not work. I 
would like to know the correct way of doing it. 

I would greatly appreciate it if you would fix the example code and test it. 
Not trying to insult you by stating the obvious here, but given the scarce 
documentation, it is pretty important that your canonical example actually 
works ;-)

Original comment by deni...@gmail.com on 17 Aug 2012 at 3:25

GoogleCodeExporter commented 9 years ago
Sorry to hear you're having trouble with this. The example code does work for 
me, so in order to help resolve this it would be helpful to know:

1. The version of matlab you're using

2. The contents of the 'bob' variable after the 'bob = pb_read_Person();' call 
(you can determine this by typing 'bob' without a semicolon in the matlab 
command window and pressing enter).

Lastly, any patches or suggestions for improving the documentation would be 
great.

Original comment by evan.lap...@farsounder.com on 17 Aug 2012 at 10:02

GoogleCodeExporter commented 9 years ago
Hi again, thanks for the response!

I am running Matlab version R2012a (7.14.0.739). I successfully compiled your 
person.proto example to the Matlab routines, started Matlab, and added the 
utility routines to the path. What happens next is this:

    >> bob = pb_read_Person();
    Warning: Required field not set while parsing. This is an error. 
    > In pblib_generic_parse_from_string at 111
      In pb_read_Person at 31 
    Warning: Required field not set while parsing. This is an error. 
    > In pblib_generic_parse_from_string at 111
      In pb_read_Person at 31 

This sounds a lot like what happened to the first poster in this thread, who 
explained that the code will check if all required fields are set if you don't 
supply a buffer. I have not looked into the generated code very hard myself, 
but obviously there is a check for the required fields that fails here. 

Is there another, safer way to instantiate an empty Person in this example that 
will not trigger the error, or possibly some workaround that you know of? I 
would be greatly helped. We are using protocol buffers across a number of 
different languages. It would be a big setback if we can't get Matlab to work. 

Original comment by deni...@gmail.com on 20 Aug 2012 at 11:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
...sorry, forgot to paste the contents of the 'bob' variable:

 bob = 

              has_field: [4 java.util.HashMap]
                   name: ''
                     id: 0
                  email: ''
                  phone: [0x0 struct]
         unknown_fields: []
    descriptor_function: @pb_descriptor_Person

Update: It just dawned on me that this is just a warning (the 'This is an 
error.' part of the message got me there;) Needs fixing I suppose, but at least 
I can continue for now, or so it appears. 

Original comment by deni...@gmail.com on 20 Aug 2012 at 12:20