use bytes::Bytes;
use fdb::error::FdbResult;
use fdb::range::Range;
use fdb::subspace::Subspace;
use fdb::Key;
use std::convert::{TryFrom, TryInto};
use crate::cursor::pb;
use crate::cursor::{KeyValueContinuationInternal, KeyValueCursorBuilder};
use crate::range::KeyRange;
pub fn key_value_cursor_builder_build_range(
maybe_subspace: &Option<Subspace>,
key_range: KeyRange,
continuation: Option<Bytes>,
reverse: bool,
) -> FdbResult<Range> {
let maybe_continuation_internal = match continuation {
Some(b) => Some(KeyValueContinuationInternal::try_from(b)?),
None => None,
};
KeyValueCursorBuilder::build_range(
maybe_subspace,
key_range,
maybe_continuation_internal,
reverse,
)
}
pub fn key_value_continuation_v1_key_marker_bytes(key: Key) -> FdbResult<Bytes> {
KeyValueContinuationInternal::V1(pb::KeyValueContinuationInternalV1 {
key_value_continuation: pb::ProtoKeyValueContinuationEnumV1::KeyMarker(
pb::ProtoKeyMarkerV1 {
key_marker: Bytes::from(key),
},
),
})
.try_into()
}
pub fn key_value_continuation_v1_begin_marker_bytes() -> FdbResult<Bytes> {
KeyValueContinuationInternal::V1(pb::KeyValueContinuationInternalV1 {
key_value_continuation: pb::ProtoKeyValueContinuationEnumV1::BeginMarker(
pb::ProtoBeginMarkerV1 {},
),
})
.try_into()
}
pub fn key_value_continuation_v1_end_marker_bytes() -> FdbResult<Bytes> {
KeyValueContinuationInternal::V1(pb::KeyValueContinuationInternalV1 {
key_value_continuation: pb::ProtoKeyValueContinuationEnumV1::EndMarker(
pb::ProtoEndMarkerV1 {},
),
})
.try_into()
}