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

The enum type under proto3 will report an error. #29

Open
freshcn opened this issue Jul 26, 2020 · 7 comments
Open

The enum type under proto3 will report an error. #29

freshcn opened this issue Jul 26, 2020 · 7 comments
Labels
question Further information is requested

Comments

@freshcn
Copy link

freshcn commented Jul 26, 2020

The enum type under proto3 will report an error.

Error: Error while parsing the JSON representation of the protobuf message:
Expected 'number', but got 'string'
@spluxx
Copy link
Owner

spluxx commented Jul 27, 2020

Hmm that's strange. To best of my knowledge, enum values in protobuf are serialized as numbers rather than strings. Could you provide me a snippet of the .proto file and how you're constructing your message?

@spluxx spluxx added the question Further information is requested label Jul 27, 2020
@freshcn
Copy link
Author

freshcn commented Jul 27, 2020

I have two .proto file

backend/server/status/get.proto

syntax = "proto3";
package backend.server.status;

option go_package = "backend/app/pb/server/status";

import "backend/public/responseHead.proto";
import "backend/public/platform.proto";

message GetResponse {
    backend.public.ResponseHead head = 1;
    backend.public.Platform platform = 2;
}

backend/public/platform.proto

syntax = "proto3";
package backend.public;

option go_package = "backend/app/pb/public";

enum Platform {
    PLATFORM_EMAIL = 0;
    PLATFORM_WXMINI = 1;
    PLATFORM_WXH5 = 2;
    PLATFORM_MOBILE = 3;
}

An error occurred on the platform in GetResponse

@spluxx
Copy link
Owner

spluxx commented Jul 30, 2020

Hmm that's strange. I'll double check to see what's going on. Thank you!

@codingforeternity
Copy link

@spluxx any updates on this ? I am facing the same issue.

@ahmad-pepperstone
Copy link

Same here

@umarfarooq-del
Copy link

@spluxx any updates on this ? I am facing the same issue.

got the solution?

@benjaminwilsonvirbela
Copy link

I'm running into this issue too (v0.4.0 on Windows 10). Even an enum with a single option will cause issues:

syntax = "proto3";
package enumtest;

message MyObject {
  enum MessageType {
    MY_MESSAGE_TYPE = 0;
  }
  MessageType message_type = 1;
}

Here I encoded { messageType: 0 }:

image

I noticed if messageType is out of range, it will use the enum default (here MY_MESSAGE_TYPE) with no error. Here I encoded { messageType: 15 }:

image

Going to look into this a bit later, but at least the data can be verified in the readout window below the error message for now.

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

No branches or pull requests

6 participants