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!
javascript protocol-buffers
This question has an open bounty worth +100
reputation from demonofthemist ending in 7 days.
This question has not received enough attention.
add a comment |
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!
javascript protocol-buffers
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, likemessage.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
add a comment |
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!
javascript protocol-buffers
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
javascript protocol-buffers
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, likemessage.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
add a comment |
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, likemessage.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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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