// Copyright 2021 Google LLC
//
// 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.

syntax = "proto3";

package cast.web;

option optimize_for = LITE_RUNTIME;

message Message {
  oneof message_type {
    MessageRequest request = 1;
    MessageResponse response = 2;
    MessagePortStatus status = 3;
  }

  MessageChannelDescriptor channel = 4;
}

message MessageChannelDescriptor {
  uint32 channel_id = 1;
}

message MessageRequest {
  string data = 1;
  repeated MessagePortDescriptor ports = 2;
}

message MessageResponse {
  bool result = 1;
}

// MessagePortDescriptor is used to transfer ownership of a port across the
// MessageChannel. After port transfer, Messages may be sent to and from the
// port by using same |channel|, which must be unique to each entangled
// port pair. Pairs from Cast Core start with |channel_id| of 0x80000000 and
// increment by one for each pair; pairs generated by a runtime should start
// at 0x0 and increment by one to avoid collisions.
message MessagePortDescriptor {
  MessageChannelDescriptor channel = 1;
  MessagePortStatus peer_status = 2;
  uint32 sequence_number = 3;
}

message MessagePortStatus {
  enum Status {
    OK = 0;
    ERROR = 1;
    STARTED = 2;
  }

  Status status = 1;
}
