Skip to main content

couchbase_core/memdx/
ext_frame_code.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
20#[non_exhaustive]
21pub enum ExtReqFrameCode {
22    Barrier,
23    Durability,
24    StreamID,
25    OtelContext,
26    OnBehalfOf,
27    PreserveTTL,
28    ExtraPerm,
29
30    Unknown(u16),
31}
32
33impl From<ExtReqFrameCode> for u16 {
34    fn from(value: ExtReqFrameCode) -> u16 {
35        match value {
36            ExtReqFrameCode::Barrier => 0x00,
37            ExtReqFrameCode::Durability => 0x01,
38            ExtReqFrameCode::StreamID => 0x02,
39            ExtReqFrameCode::OtelContext => 0x03,
40            ExtReqFrameCode::OnBehalfOf => 0x04,
41            ExtReqFrameCode::PreserveTTL => 0x05,
42            ExtReqFrameCode::ExtraPerm => 0x06,
43
44            ExtReqFrameCode::Unknown(code) => code,
45        }
46    }
47}
48
49#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
50#[non_exhaustive]
51pub enum ExtResFrameCode {
52    ServerDuration,
53    ReadUnits,
54    WriteUnits,
55    ThrottleDuration,
56
57    Unknown(u16),
58}
59
60impl From<ExtResFrameCode> for u16 {
61    fn from(value: ExtResFrameCode) -> u16 {
62        match value {
63            ExtResFrameCode::ServerDuration => 0x00,
64            ExtResFrameCode::ReadUnits => 0x01,
65            ExtResFrameCode::WriteUnits => 0x02,
66            ExtResFrameCode::ThrottleDuration => 0x03,
67
68            ExtResFrameCode::Unknown(code) => code,
69        }
70    }
71}
72
73impl From<u16> for ExtResFrameCode {
74    fn from(value: u16) -> Self {
75        match value {
76            0x00 => ExtResFrameCode::ServerDuration,
77            0x01 => ExtResFrameCode::ReadUnits,
78            0x02 => ExtResFrameCode::WriteUnits,
79            0x03 => ExtResFrameCode::ThrottleDuration,
80            _ => ExtResFrameCode::Unknown(value),
81        }
82    }
83}