1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;

/// Expose [`KeyValueCursorBuilder::build_range`] method.
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,
    )
}

/// Expose [`pb::ProtoKeyValueContinuationEnumV1::KeyMarker`].
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()
}

/// Expose [`pb::ProtoKeyValueContinuationEnumV1::BeginMarker`].
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()
}

/// Expose [`pb::ProtoKeyValueContinuationEnumV1::EndMarker`].
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()
}