grpcgrpc-pythonproto3

How to determine the value type of proto3's oneof field?


syntax = "proto3";

package gRPC_Forecaster;

import "google/protobuf/timestamp.proto";

service Forecaster {
    rpc Forecast (ProductToForecast) returns (ForecastData) {}
}

message ProductToForecast {
    int32 productID = 1;
    google.protobuf.Timestamp startDate = 2;
    int32 forecastDurationInWeeks = 3;
    Model model = 4;
}

message ForecastData {
    repeated int32 data = 1;
    repeated int32 date = 2;
}

message Model {
    oneof model_oneof {
        ARIMA arima = 1;
        SARIMA sarima = 2;
    }
}

message ARIMA{
    int32 p = 1;
    int32 d = 2;
    int32 q = 3;
}

message SARIMA{
    int32 p = 1;
    int32 d = 2;
    int32 q = 3;
    int32 p2 = 4;
    int32 d2 = 5;
    int32 q2 = 6;

}

Above is my proto3 code for my gRPC setup, where I have a python sever and a PHP client.
On the PHP client i set the model object as ARIMA.
How do I check on my python server that the type of the request.model is of type ARIMA?
Also, I want the PHP client to be able to set the model to either ARIMA or SARIMA, is the way I am approaching this correct?


Solution

  • Take a look at potocol buffers' reference for generated code: