grpc-gateway
grpc-gateway copied to clipboard
Add Bytes and Enum handlers to `proto2ConvertFuncs`
Due to backward compatibility issue, I am forced to use proto2. I am not sure if my clients can keep on using proto2 and I can move to proto3. Also it is recommended to keep using proto2 as proto3 doesn't have many new features.
So, if I am supposed to use proto2 only, is there a workaround for it given bytes_type and enums are not supported?
Any workaround for this that I can do without changing from proto2 to proto3?
Base64 encode the data in a string type maybe?
rpc EntityUpdate(EntityUpdateArg) returns (EntityUpdateRet) { option (google.api.http) = { put: "/v1/tentity/{uuid}" body: "*" }; }
Given the above and given uuid in bytes, how am i supposed to achieve that?
You'd have to encode it in the client anyway, you can't send raw bytes in a URL. If it's a uuid though, maybe just send the string representation of the uuid?
Agreed but in EntityUpdateArg, uuid is in bytes. How the type conversion is done here? Apologies I am not much aware of that. Will it be something like - put: "/v1/entity/string{uuid}" ?
If it's a path parameter, it has to be URL-encoded or base64-encoded and stored in a string. If it's in the body of the message, I guess you may still want to base64 encode it.
Few things to clarify here - If its a path param, I create a string entry in EntityUpdateArg say uuid_str and use that in path param? If thats the case, then for body of the message, where is this encoding supposed to happen? Given the fact that everything needs to be handled on server end and atleast existing rpc clients are not expected to change.
Also I am only supposed to add fields in proto as interface.pb.gw.go is generated. So any such operation of encoding etc has to be part of proto definition.
If you add it as a path param you don't need to add it to the body of the message. If existing clients are already sending the UUID in the path, what format is it using, since it can't be bytes?
My existing clients are rpc clients only. On top of existing proto, I wanted to expose REST interface for new clients. But given I have to use field from existing proto (unless a new string type field is added), the generation of interface.pb.gw.go fails from existing interface.proto
Ah I see. In that case, maybe just make the uuid a parameter in the body instead? So you can reuse the same types. If that doesn't work, you will need to add a uuid_str and manually handle it in the service.
Does that mean that conversion from bytes_type is supported in body and not for path params as far as proto2 is concerned? If thats the case, is there any plan to make that enhancement in near future?
I frankly don't know, I'm afraid. Try it :man_shrugging:.