Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto3 repeated field cause error Illegal wire type for field Message.Field #476

Closed
ryanhex53 opened this issue Oct 14, 2016 · 5 comments
Closed

Comments

@ryanhex53
Copy link

syntax = "proto3";

package com.jiaojiaoapp.protobuftest;

message ProtobufTest {
    float num = 1;
    bytes payload = 2;
    repeated int32 scores = 3;
}
var builder = ProtoBuf.loadProtoFile(path.join(__dirname, "protobuftest.proto")),
    Message = builder.build("com.jiaojiaoapp.protobuftest");
    var message = new Message.ProtobufTest({
        num: 1,
        payload: new Buffer('helloworld')
    });
    message.scores.push(1);
    message.scores.push(2);

this will cause error

[Error: Illegal wire type for field Message.Field .com.jiaojiaoapp.protobuftest.ProtobufTest.scores: 2 (0 expected)]

@ryanhex53
Copy link
Author

resolved after add [packed=true], no more errors.

syntax = "proto3";

package com.jiaojiaoapp.protobuftest;

message ProtobufTest {
    float num = 1;
    bytes payload = 2;
    repeated int32 scores = 3 [packed=true];
}

but i think should treat it as packed by default as the google docs says:

In proto3, repeated fields of scalar numeric types use packed encoding by default.

@tanis2000
Copy link

Yes, according to Google docs, when using syntax = "proto3" the default behavior should be to consider repeated fields as [packed=true]
Any chance of this being corrected?

@jdimond
Copy link

jdimond commented Nov 2, 2016

Related: #390

@codeka
Copy link

codeka commented Nov 12, 2016

I think this is a dupe of #432.

@dcodeIO
Copy link
Member

dcodeIO commented Nov 28, 2016

Closing this for now.

protobuf.js 6.0.0

Feel free to send a pull request if this is still a requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants