syntax = "proto2";
package Net.NATS.Streaming.PB;

// How messages are delivered to the STAN cluster
message PubMsg {
  optional string clientID = 1;  // ClientID
  optional string guid     = 2;  // guid
  optional string subject  = 3;  // subject
  optional string reply    = 4;  // optional reply
  optional bytes  data     = 5;  // payload

  optional bytes  sha256  = 10; // optional sha256 of data
}

// Used to ACK to publishers
message PubAck {
  optional string guid  = 1; // guid
  optional string error = 2; // err string, empty/omitted if no error
}

// Msg struct. Sequence is assigned for global ordering by
// the cluster after the publisher has been acknowledged.
message MsgProto {
  optional uint64 sequence    = 1;  // globally ordered sequence number for the subject's channel
  optional string subject     = 2;  // subject
  optional string reply       = 3;  // optional reply
  optional bytes  data        = 4;  // payload
  optional int64  timestamp   = 5;  // received timestamp
  optional bool   redelivered = 6;  // Flag specifying if the message is being redelivered

  optional uint32 CRC32       = 10; // optional IEEE CRC32
}

// Ack will deliver an ack for a delivered msg.
message Ack {
  optional string subject  = 1; // Subject
  optional uint64 sequence = 2; // Sequence to acknowledge
}

// Connection Request
message ConnectRequest {
  optional string clientID       = 1;  // Client name/identifier.
  optional string heartbeatInbox = 2;  // Inbox for server initiated heartbeats.
}

// Response to a client connect
message ConnectResponse {
  optional string pubPrefix        = 1;   // Prefix to use when publishing to this STAN cluster
  optional string subRequests      = 2;   // Subject to use for subscription requests
  optional string unsubRequests    = 3;   // Subject to use for unsubscribe requests
  optional string closeRequests    = 4;   // Subject for closing the stan connection
  optional string error            = 5;   // err string, empty/omitted if no error
  optional string subCloseRequests = 6;   // Subject to use for subscription close requests

  optional string publicKey     = 100; // Possibly used to sign acks, etc.
}

// Enum for start position type.
enum StartPosition {
    NewOnly        = 0;
    LastReceived   = 1;
    TimeDeltaStart = 2;
    SequenceStart  = 3;
    First          = 4;
  }

// Protocol for a client to subscribe
message SubscriptionRequest {
  optional string        clientID       = 1;  // ClientID
  optional string        subject        = 2;  // Formal subject to subscribe to, e.g. foo.bar
  optional string        qGroup         = 3;  // Optional queue group
  optional string        inbox          = 4;  // Inbox subject to deliver messages on
  optional int32         maxInFlight    = 5;  // Maximum inflight messages without an ack allowed
  optional int32         ackWaitInSecs  = 6;  // Timeout for receiving an ack from the client
  optional string        durableName    = 7;  // Optional durable name which survives client restarts
  optional StartPosition startPosition  = 10; // Start position
  optional uint64        startSequence  = 11; // Optional start sequence number
  optional int64         startTimeDelta = 12; // Optional start time
}

// Response for SubscriptionRequest and UnsubscribeRequests
message SubscriptionResponse {
  optional string ackInbox = 2; // ackInbox for sending acks
  optional string error    = 3; // err string, empty/omitted if no error
}

// Protocol for a clients to unsubscribe. Will return a SubscriptionResponse
message UnsubscribeRequest {
  optional string clientID    = 1; // ClientID
  optional string subject     = 2; // subject for the subscription
  optional string inbox       = 3; // Inbox subject to identify subscription
  optional string durableName = 4; // Optional durable name which survives client restarts
}

// Protocol for a client to close a connection
message CloseRequest {
  optional string clientID = 1;  // Client name provided to Connect() requests
}

// Response for CloseRequest
message CloseResponse {
  optional string error = 1; // err string, empty/omitted if no error
}
