syntax = "proto3";

package wasm.rpc;

message Type {
  oneof type {
    TypePrimitive primitive = 1;
    TypeList list = 2;
    TypeTuple tuple = 3;
    TypeRecord record = 5;
    TypeFlags flags = 6;
    TypeEnum enum = 7;
    TypeOption option = 8;
    TypeResult result = 9;
    TypeVariant variant = 10;
    TypeHandle handle = 11;
  }
}

message TypePrimitive {
  PrimitiveType primitive = 1;
}

message TypeList {
  Type elem = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeTuple {
  repeated Type elems = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeRecord {
  repeated NameTypePair fields = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeFlags {
  repeated string names = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeEnum {
  repeated string names = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeOption {
  Type elem = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeResult {
  optional Type ok = 1;
  optional Type err = 2;
  optional string name = 3;
  optional string owner = 4;
}

message TypeVariant {
  repeated NameOptionTypePair cases = 1;
  optional string name = 2;
  optional string owner = 3;
}

message TypeHandle {
  uint64 resource_id = 1;
  ResourceMode mode = 2;
  optional string name = 3;
  optional string owner = 4;
}

message NameTypePair {
  string name = 1;
  Type typ = 2;
}

message NameOptionTypePair {
  string name = 1;
  optional Type typ = 2;
}

enum PrimitiveType {
  BOOL = 0;
  S8 = 1;
  U8 = 2;
  S16 = 3;
  U16 = 4;
  S32 = 5;
  U32 = 6;
  S64 = 7;
  U64 = 8;
  F32 = 9;
  F64 = 10;
  CHR = 11;
  STR = 12;
}

enum ResourceMode {
  BORROWED = 0;
  OWNED = 1;
}