How to set enum value in google-protobufjs











up vote
2
down vote

favorite












Hi have a proto file as follows:



enum Type
{
A = 0;
B = 1;
C = 2;
}

message Message
{
User to = 1;
User from = 2;
Type type = 3;
}


I use protoc compiler to convert it to javascript utility classes. Using this generated javascript file I set up Message object in my application as follows:



const message = new Main.Message()
message.setTo(this.user1) // saved user
message.setFrom(this.user3) // saved user
message.setType(0) // trying to set type to A

const buffer = message.serializeBinary()
socket.send(buffer)


The issue I am facing is in message object both to and from fields get updated properly, but type remains null! I am unable to figure out a solution for this.



Is this because in Message proto, expected type is as Enum? But it javascript it is not possible. How to set expected enum values while creating protobuf for dispatch?



Note:




I've noticed that, this issue happens only when I try to set zero
value to Enum type!











share|improve this question

















This question has an open bounty worth +100
reputation from demonofthemist ending in 7 days.


This question has not received enough attention.
















  • Which protobuf version (proto2, proto3)?
    – jannis
    3 hours ago












  • @jannis this is proto3
    – demonofthemist
    3 hours ago






  • 1




    Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
    – Martin Adámek
    3 hours ago










  • @MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
    – demonofthemist
    2 hours ago















up vote
2
down vote

favorite












Hi have a proto file as follows:



enum Type
{
A = 0;
B = 1;
C = 2;
}

message Message
{
User to = 1;
User from = 2;
Type type = 3;
}


I use protoc compiler to convert it to javascript utility classes. Using this generated javascript file I set up Message object in my application as follows:



const message = new Main.Message()
message.setTo(this.user1) // saved user
message.setFrom(this.user3) // saved user
message.setType(0) // trying to set type to A

const buffer = message.serializeBinary()
socket.send(buffer)


The issue I am facing is in message object both to and from fields get updated properly, but type remains null! I am unable to figure out a solution for this.



Is this because in Message proto, expected type is as Enum? But it javascript it is not possible. How to set expected enum values while creating protobuf for dispatch?



Note:




I've noticed that, this issue happens only when I try to set zero
value to Enum type!











share|improve this question

















This question has an open bounty worth +100
reputation from demonofthemist ending in 7 days.


This question has not received enough attention.
















  • Which protobuf version (proto2, proto3)?
    – jannis
    3 hours ago












  • @jannis this is proto3
    – demonofthemist
    3 hours ago






  • 1




    Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
    – Martin Adámek
    3 hours ago










  • @MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
    – demonofthemist
    2 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Hi have a proto file as follows:



enum Type
{
A = 0;
B = 1;
C = 2;
}

message Message
{
User to = 1;
User from = 2;
Type type = 3;
}


I use protoc compiler to convert it to javascript utility classes. Using this generated javascript file I set up Message object in my application as follows:



const message = new Main.Message()
message.setTo(this.user1) // saved user
message.setFrom(this.user3) // saved user
message.setType(0) // trying to set type to A

const buffer = message.serializeBinary()
socket.send(buffer)


The issue I am facing is in message object both to and from fields get updated properly, but type remains null! I am unable to figure out a solution for this.



Is this because in Message proto, expected type is as Enum? But it javascript it is not possible. How to set expected enum values while creating protobuf for dispatch?



Note:




I've noticed that, this issue happens only when I try to set zero
value to Enum type!











share|improve this question















Hi have a proto file as follows:



enum Type
{
A = 0;
B = 1;
C = 2;
}

message Message
{
User to = 1;
User from = 2;
Type type = 3;
}


I use protoc compiler to convert it to javascript utility classes. Using this generated javascript file I set up Message object in my application as follows:



const message = new Main.Message()
message.setTo(this.user1) // saved user
message.setFrom(this.user3) // saved user
message.setType(0) // trying to set type to A

const buffer = message.serializeBinary()
socket.send(buffer)


The issue I am facing is in message object both to and from fields get updated properly, but type remains null! I am unable to figure out a solution for this.



Is this because in Message proto, expected type is as Enum? But it javascript it is not possible. How to set expected enum values while creating protobuf for dispatch?



Note:




I've noticed that, this issue happens only when I try to set zero
value to Enum type!








javascript protocol-buffers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago

























asked Nov 15 at 7:17









demonofthemist

2,67731231




2,67731231






This question has an open bounty worth +100
reputation from demonofthemist ending in 7 days.


This question has not received enough attention.








This question has an open bounty worth +100
reputation from demonofthemist ending in 7 days.


This question has not received enough attention.














  • Which protobuf version (proto2, proto3)?
    – jannis
    3 hours ago












  • @jannis this is proto3
    – demonofthemist
    3 hours ago






  • 1




    Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
    – Martin Adámek
    3 hours ago










  • @MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
    – demonofthemist
    2 hours ago


















  • Which protobuf version (proto2, proto3)?
    – jannis
    3 hours ago












  • @jannis this is proto3
    – demonofthemist
    3 hours ago






  • 1




    Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
    – Martin Adámek
    3 hours ago










  • @MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
    – demonofthemist
    2 hours ago
















Which protobuf version (proto2, proto3)?
– jannis
3 hours ago






Which protobuf version (proto2, proto3)?
– jannis
3 hours ago














@jannis this is proto3
– demonofthemist
3 hours ago




@jannis this is proto3
– demonofthemist
3 hours ago




1




1




Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
– Martin Adámek
3 hours ago




Just a guess (never used protobuf), but can't you use the enum itself, like message.setType(Main.Type.A)?
– Martin Adámek
3 hours ago












@MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
– demonofthemist
2 hours ago




@MartinAdámek It doesn't matter! Effectively you are passing same value in both ways, i.e. a number.
– demonofthemist
2 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314212%2fhow-to-set-enum-value-in-google-protobufjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314212%2fhow-to-set-enum-value-in-google-protobufjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Volksrepublik China

How to test boost logger output in unit testing?

How do you send bulk inserts with no ids to elasticsearch