Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
update db-basis proto
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrasp committed Aug 8, 2023
1 parent bccb69e commit 91369cb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
15 changes: 15 additions & 0 deletions resources/dbbasis.proto
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 3 additions & 12 deletions resources/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
}
35 changes: 20 additions & 15 deletions src/com/xtdb/protos.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 91369cb

Please sign in to comment.