diff --git a/resources/dbbasis.proto b/resources/dbbasis.proto new file mode 100644 index 0000000..952c882 --- /dev/null +++ b/resources/dbbasis.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package com.xtdb.protos; +import "common.proto"; + +message DbBasisRequest { + OptionInt64 tx_id = 1; + OptionDatetime valid_time = 2; + OptionDatetime tx_time = 3; +} + +message DbBasisResponse { + string xt_id = 1; + string content = 2; +} diff --git a/resources/service.proto b/resources/service.proto index 626f3af..7852e56 100644 --- a/resources/service.proto +++ b/resources/service.proto @@ -5,7 +5,7 @@ package com.xtdb.protos; import "transactions.proto"; import "entity.proto"; import "common.proto"; - +import "dbbasis.proto"; message StatusResponse { string version = 1; @@ -17,15 +17,6 @@ message StatusResponse { OptionString consumer_state = 7; } -message DbBasisRequest { - bool open_snapshot = 1; -} - -message DbBasisResponse { - string valid_time = 1; - int64 tx_id = 2; -} - service GrpcApi { rpc Status(Empty) returns (StatusResponse); rpc SubmitTx(com.xtdb.protos.SubmitRequest) @@ -36,6 +27,6 @@ service GrpcApi { returns (com.xtdb.protos.EntityTxResponse); rpc Entity(com.xtdb.protos.EntityRequest) returns (com.xtdb.protos.EntityResponse); - rpc DbBasis(DbBasisRequest) - returns(DbBasisResponse); + rpc DbBasis(com.xtdb.protos.DbBasisRequest) + returns(com.xtdb.protos.DbBasisResponse); } diff --git a/src/com/xtdb/protos.cljc b/src/com/xtdb/protos.cljc index 767a4b5..fa18873 100644 --- a/src/com/xtdb/protos.cljc +++ b/src/com/xtdb/protos.cljc @@ -206,22 +206,23 @@ ;----------------------------------------------------------------------------- ; DbBasisRequest ;----------------------------------------------------------------------------- -(defrecord DbBasisRequest-record [open-snapshot] +(defrecord DbBasisRequest-record [tx-id valid-time tx-time] pb/Writer (serialize [this os] - (serdes.core/write-Bool 1 {:optimize true} (:open-snapshot this) os)) + (serdes.core/write-embedded 1 (:tx-id this) os) + (serdes.core/write-embedded 2 (:valid-time this) os) + (serdes.core/write-embedded 3 (:tx-time this) os)) pb/TypeReflection (gettype [this] "com.xtdb.protos.DbBasisRequest")) -(s/def :com.xtdb.protos.DbBasisRequest/open-snapshot boolean?) -(s/def ::DbBasisRequest-spec (s/keys :opt-un [:com.xtdb.protos.DbBasisRequest/open-snapshot])) -(def DbBasisRequest-defaults {:open-snapshot false}) +(s/def ::DbBasisRequest-spec (s/keys :opt-un [])) +(def DbBasisRequest-defaults {}) (defn cis->DbBasisRequest "CodedInputStream to DbBasisRequest" [is] - (map->DbBasisRequest-record (tag-map DbBasisRequest-defaults (fn [tag index] (case index 1 [:open-snapshot (serdes.core/cis->Bool is)] [index (serdes.core/cis->undefined tag is)])) is))) + (map->DbBasisRequest-record (tag-map DbBasisRequest-defaults (fn [tag index] (case index 1 [:tx-id (ecis->OptionInt64 is)] 2 [:valid-time (ecis->OptionDatetime is)] 3 [:tx-time (ecis->OptionDatetime is)] [index (serdes.core/cis->undefined tag is)])) is))) (defn ecis->DbBasisRequest "Embedded CodedInputStream to DbBasisRequest" @@ -234,7 +235,11 @@ " [init] {:pre [(if (s/valid? ::DbBasisRequest-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::DbBasisRequest-spec init))))]} - (map->DbBasisRequest-record (merge DbBasisRequest-defaults init))) + (-> (merge DbBasisRequest-defaults init) + (cond-> (some? (get init :tx-id)) (update :tx-id new-OptionInt64)) + (cond-> (some? (get init :valid-time)) (update :valid-time new-OptionDatetime)) + (cond-> (some? (get init :tx-time)) (update :tx-time new-OptionDatetime)) + (map->DbBasisRequest-record))) (defn pb->DbBasisRequest "Protobuf to DbBasisRequest" @@ -573,24 +578,24 @@ ;----------------------------------------------------------------------------- ; DbBasisResponse ;----------------------------------------------------------------------------- -(defrecord DbBasisResponse-record [valid-time tx-id] +(defrecord DbBasisResponse-record [xt-id content] pb/Writer (serialize [this os] - (serdes.core/write-String 1 {:optimize true} (:valid-time this) os) - (serdes.core/write-Int64 2 {:optimize true} (:tx-id this) os)) + (serdes.core/write-String 1 {:optimize true} (:xt-id this) os) + (serdes.core/write-String 2 {:optimize true} (:content this) os)) pb/TypeReflection (gettype [this] "com.xtdb.protos.DbBasisResponse")) -(s/def :com.xtdb.protos.DbBasisResponse/valid-time string?) -(s/def :com.xtdb.protos.DbBasisResponse/tx-id int?) -(s/def ::DbBasisResponse-spec (s/keys :opt-un [:com.xtdb.protos.DbBasisResponse/valid-time :com.xtdb.protos.DbBasisResponse/tx-id])) -(def DbBasisResponse-defaults {:valid-time "" :tx-id 0}) +(s/def :com.xtdb.protos.DbBasisResponse/xt-id string?) +(s/def :com.xtdb.protos.DbBasisResponse/content string?) +(s/def ::DbBasisResponse-spec (s/keys :opt-un [:com.xtdb.protos.DbBasisResponse/xt-id :com.xtdb.protos.DbBasisResponse/content])) +(def DbBasisResponse-defaults {:xt-id "" :content ""}) (defn cis->DbBasisResponse "CodedInputStream to DbBasisResponse" [is] - (map->DbBasisResponse-record (tag-map DbBasisResponse-defaults (fn [tag index] (case index 1 [:valid-time (serdes.core/cis->String is)] 2 [:tx-id (serdes.core/cis->Int64 is)] [index (serdes.core/cis->undefined tag is)])) is))) + (map->DbBasisResponse-record (tag-map DbBasisResponse-defaults (fn [tag index] (case index 1 [:xt-id (serdes.core/cis->String is)] 2 [:content (serdes.core/cis->String is)] [index (serdes.core/cis->undefined tag is)])) is))) (defn ecis->DbBasisResponse "Embedded CodedInputStream to DbBasisResponse"