/**
 * Common messages used in other protocol files.
 * @author Rafał Słota
 * @copyright (C) 2016 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in
 * 'LICENSE.txt'
 */
 
syntax = "proto2";
package one.clproto;

message DBSyncRequest {
    oneof message_body {
        TreeBroadcast       tree_broadcast  = 1;
        ChangesRequest      changes_request = 2;
        BatchUpdate         batch_update    = 3;
    }
}

message TreeBroadcast {
    required int32 depth                    = 1;
    required bytes l_edge                   = 2;
    required bytes r_edge                   = 3;
    required bytes space_id                 = 4;
    required bytes request_id               = 5;
    repeated bytes excluded_providers       = 6;
    oneof message_body {
        BatchUpdate     batch_update        = 7;
        StatusRequest   status_request      = 8;
        StatusReport    status_report       = 9;
    }
}


message BatchUpdate {
    required bytes space_id             = 1;
    required bytes since_seq            = 2;
    required bytes until_seq            = 3;
    required bytes changes_encoded      = 4;
}

message StatusReport {
    required bytes space_id     = 1;
    required bytes seq_num      = 2;
}

message StatusRequest {
}

message ChangesRequest {
    required bytes since_seq    = 1;
    required bytes until_seq    = 2;
}

message DBSyncMessage {
    oneof message_body {
        TreeBroadcast2  tree_broadcast  = 1;
        ChangesBatch    changes_batch   = 2;
        ChangesRequest2 changes_request = 3;
    }
}

message TreeBroadcast2 {
    required bytes        src_provider_id  = 1;
    required bytes        low_provider_id  = 2;
    required bytes        high_provider_id = 3;
    required bytes        message_id       = 4;
    required ChangesBatch changes_batch    = 5;
}

message ChangesBatch {
    required bytes  space_id   = 1;
    required uint64 since      = 2;
    required uint64 until      = 3;
    required uint64 timestamp  = 4;
    required bool   compressed = 5;
    required bytes  docs       = 6;
}

message ChangesRequest2 {
    required bytes  space_id          = 1;
    required uint64 since             = 2;
    required uint64 until             = 3;
    repeated bytes  included_mutators = 4;
}
