/**
 * Copyright (C) 2014-2018 Lightbend Inc. <https://www.lightbend.com>
 */
package akka.cluster.ddata;

option java_package = "akka.cluster.ddata.protobuf.msg";
option optimize_for = SPEED;

message Get {
  required OtherMessage key = 1;
  required sint32 consistency = 2;
  required uint32 timeout = 3;
  optional OtherMessage request = 4;   
}

message GetSuccess {
  required OtherMessage key = 1;
  required OtherMessage data = 2;
  optional OtherMessage request = 4;
}

message NotFound {
  required OtherMessage key = 1;
  optional OtherMessage request = 2;
}

message GetFailure {
  required OtherMessage key = 1;
  optional OtherMessage request = 2;
}

message Subscribe {
  required OtherMessage key = 1;
  required string ref = 2;
}

message Unsubscribe {
  required OtherMessage key = 1;
  required string ref = 2;
}

message Changed {
  required OtherMessage key = 1;
  required OtherMessage data = 2;
}

message Write {
  required string key = 1;
  required DataEnvelope envelope = 2;
}

// message WriteAck, via Empty

message Empty {
}

message Read {
  required string key = 1;
}

message ReadResult {
  optional DataEnvelope envelope = 1;
}

message DataEnvelope {
  message PruningEntry {
    required UniqueAddress removedAddress = 1;
    required UniqueAddress ownerAddress = 2;
    required bool performed = 3;
    repeated Address seen = 4;
    optional sint64 obsoleteTime = 5;
  } 
  
  required OtherMessage data = 1;
  repeated PruningEntry pruning = 2;
  optional VersionVector deltaVersions = 3;
}

message Status {
  message Entry {
    required string key = 1;
    required bytes digest = 2;
  }
  
  required uint32 chunk = 1;
  required uint32 totChunks = 2;
  repeated Entry entries = 3;
}

message Gossip {
  message Entry {
    required string key = 1;
    required DataEnvelope envelope = 2;
  }
  
  required bool sendBack = 1;
  repeated Entry entries = 2;
}

message DeltaPropagation {
  message Entry {
    required string key = 1;
    required DataEnvelope envelope = 2;
    required int64 fromSeqNr = 3;
    optional int64 toSeqNr = 4; // if not set then same as fromSequenceNr
  }
  
  required UniqueAddress fromNode = 1;
  repeated Entry entries = 2;
  optional bool reply = 3; // no reply if not set 
}

message UniqueAddress {
  required Address address = 1;
  required sfixed32 uid = 2;
  // 64 bit uids but with backward wire compatibility
  optional sfixed32 uid2 = 3;
}

message Address {
  required string hostname = 1;
  required uint32 port = 2;
}

message VersionVector {
  message Entry {
    required UniqueAddress node = 1;
    required int64 version = 2;
  }
  repeated Entry entries = 1;
}

message OtherMessage {
  required bytes enclosedMessage = 1;
  required int32 serializerId = 2;
  optional bytes messageManifest = 4;
}

message StringGSet {
  repeated string elements = 1;
}

message DurableDataEnvelope {
  required OtherMessage data = 1;
  repeated DataEnvelope.PruningEntry pruning = 2;
}
