hdbconnect_impl/protocol/parts/
transactionflags.rs1use crate::protocol::parts::option_part::{OptionId, OptionPart};
2
3pub(crate) type TransactionFlags = OptionPart<TaFlagId>;
12
13#[derive(Clone, Debug, Eq, PartialEq, Hash)]
14pub(crate) enum TaFlagId {
15 RolledBack, Committed, NewIsolationlevel, DdlCommitmodeChanged, WriteTaStarted, NoWriteTaStarted, SessionclosingTaError, ReadOnlyMode, __Unexpected__(u8),
24}
25impl OptionId<TaFlagId> for TaFlagId {
26 fn to_u8(&self) -> u8 {
27 match *self {
28 Self::RolledBack => 0,
29 Self::Committed => 1,
30 Self::NewIsolationlevel => 2,
31 Self::DdlCommitmodeChanged => 3,
32 Self::WriteTaStarted => 4,
33 Self::NoWriteTaStarted => 5,
34 Self::SessionclosingTaError => 6,
35 Self::ReadOnlyMode => 7,
36 Self::__Unexpected__(val) => val,
37 }
38 }
39
40 fn from_u8(val: u8) -> Self {
41 match val {
42 0 => Self::RolledBack,
43 1 => Self::Committed,
44 2 => Self::NewIsolationlevel,
45 3 => Self::DdlCommitmodeChanged,
46 4 => Self::WriteTaStarted,
47 5 => Self::NoWriteTaStarted,
48 6 => Self::SessionclosingTaError,
49 7 => Self::ReadOnlyMode,
50 val => {
51 warn!("Unsupported value for TaFlagId received: {val}");
52 Self::__Unexpected__(val)
53 }
54 }
55 }
56
57 fn part_type(&self) -> &'static str {
58 "TransactionFlags"
59 }
60}
61
62impl TransactionFlags {
63 pub fn is_committed(&self) -> bool {
64 self.get(&TaFlagId::Committed)
65 .map(|bv| bv.get_bool().unwrap_or(false))
66 .unwrap_or(false)
67 }
68}