chrisdew / protobuf

Protocol Buffers for Node.JS
http://code.google.com/p/protobuf-for-node/
Apache License 2.0
234 stars 71 forks source link

Support for repeated string fields is not working #34

Closed shargors closed 10 years ago

shargors commented 11 years ago

Not sure if the problem is in serialization or de-serialization logic but when I send a message with a repeated string field I get back a single string instead of an array. To be more exact, the repeated string field is set by a string array in the outgoing message but I got back a comma-separated string where each comma-separated part is an element of the original string array.

Here is the proto file: message TT { repeated string str = 1; optional uint32 uu = 2; }

Here is a simple test I did in node (v0.10.4): $ node

var fs = require('fs'); undefined var Schema = require('protobuf').Schema; undefined Schema [Function: Schema] var schema = new Schema(fs.readFileSync('t.desc')) undefined schema {} var tt = schema['TT'] undefined var msg = {str: ['abc', '123'], uu: 23} undefined var buf = tt.serialize(msg) undefined buf <SlowBuffer 0a 07 61 62 63 2c 31 32 33 10 17> tt.parse(buf) { str: 'abc,123', uu: 23 } var m = tt.parse(buf) undefined m.str 'abc,123'

AdamMagaluk commented 11 years ago

It returns an array for me.

Node version: v0.10.12 Protobuf Version: v0.8.6

t.proto

message TT {
repeated string str = 1;
optional uint32 uu = 2;
}

test.js

var fs = require('fs');
var util = require('util');
var assert = require('assert');
var Schema = require('protobuf').Schema;
var schema = new Schema(fs.readFileSync('t.desc'))

var tt = schema['TT']
var msg = {str: ['abc', '123'], uu: 23}
var buf = tt.serialize(msg)

var m = tt.parse(buf)

assert(util.isArray(m.str));
shargors commented 11 years ago

Thank you, Adam.

I will try to upgrade to the latest version of Node and perform the same tests. Give me a few days to do that. I will close the issue then.

Stan

shargors commented 10 years ago

Tested with node v0.10.22 and protobuf v 0.8.7 and it works as expected.