/**
 * Copyright 2019 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ms_service.proto
syntax = "proto3";

package mindspore.serving.proto;

service MSService {
  rpc Predict(PredictRequest) returns (PredictReply) {}

}

message PredictRequest {
  ServableSpec servable_spec = 1;
  repeated Instance instances = 3;
}

message ErrorMsg{
  int64 error_code = 1; // 0 is valid, otherwise invalid
  bytes error_msg = 2;
}

message PredictReply {
  ServableSpec servable_spec = 1;
  bool status = 2;
  repeated Instance instances = 3;
  // size 0: OK, 1: for all batch, >1: for every batch
  repeated ErrorMsg error_msg = 4;
}

message Instance{
  map<string, Tensor> items = 1;
}

enum DataType {
  MS_UNKNOWN = 0;
  MS_BOOL = 1;
  MS_INT8 = 2;
  MS_UINT8 = 3;
  MS_INT16 = 4;
  MS_UINT16 = 5;
  MS_INT32 = 6;
  MS_UINT32 = 7;
  MS_INT64 = 8;
  MS_UINT64 = 9;
  MS_FLOAT16 = 10;
  MS_FLOAT32 = 11;
  MS_FLOAT64 = 12;
  MS_STRING = 13; // for string model input
  MS_BYTES = 14;  // for images
}

message TensorShape {
  repeated int64 dims = 1;
};

message Tensor {
  // tensor shape info
  TensorShape shape = 1;

  // tensor content data type
  DataType dtype = 2;

  // tensor data
  bytes data = 3;

  // for string type and images, the dtype is MS_BYTES.
  repeated bytes bytes_val = 4;
}

message ServableSpec {
  // servable name
  string name = 1;

  // optional. If unspecified, the latest version servable will be used.
  int64 version_number = 3;

  // Specifies the method name in the servable.
  string method_name = 2;
}

message PingRequest {
  string address = 1;
}

message PingReply {
  string address = 1;
}
message PongRequest {
  string address = 1;
}

message PongReply {
  string address = 1;
}