I'm new to gRPC, I'm trying to expose gRPC server in which and rpc does not have known shape before hand.
Requirement is that particular field can have any value present in it.
Ex: file.proto
syntax = "proto3";
import "google/protobuf/struct.proto";
string corr_id = 1;
google.protobuf.Struct message = 2;
When i went through the docs there is no way we can create gRPC server without knowing the fields before hand. For this struct to work, i'm doing the following conversion and making it work.
Actual JSON Object:
{
name: "wer",
age: 28,
hobbies: ["Cricket", "Tea"],
key: {
value1: 89,
value2: "sure next"
}
}
gRPC Server Requires this below conversion:
{
"fields": {
"name": {
"stringValue": "wer"
},
"age": {
"numberValue": 28
},
"hobbies": {
"listValue": {
"fields": [
"Cricket",
"Tea"
]
}
},
"key": {
"structValue": {
"fields": {
"value1": {
"numberValue": 89
},
"value2": {
"stringValue": "sure next"
}
}
}
}
}
}
Is there util available already to do this conversion ? OR is there any other way i can achieve this without the conversion to make gRPC server parse the request ?
Imagine what i have to do for the below json ?
{
name: "Sathish",
age: 28,
address: [
{
is_primary: true,
name: "address1"
},
{
is_primary: false,
name: "address2"
}
],
hobbies: ["Cricket", "Tea"],
movies: {
liked: ["Re"],
unliked: ["Te"]
},
key: {
value1: 89,
value2: "sure next"
}
}
Note: I'm using @grpc/grpc-js package alone for now.