rustorb_giop/
service_context.rs1use rustorb_cdr::{ByteOrder, CdrDecode, CdrEncode, CdrVersion, Decoder, Encoder};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ServiceContext {
6 pub context_id: u32,
8 pub context_data: Vec<u8>,
10}
11
12impl CdrEncode for ServiceContext {
13 fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
14 enc.write_u32(self.context_id);
15 enc.write_octet_seq(&self.context_data)
16 }
17}
18
19impl CdrDecode for ServiceContext {
20 fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
21 Ok(ServiceContext {
22 context_id: dec.read_u32()?,
23 context_data: dec.read_octet_seq()?.to_vec(),
24 })
25 }
26}
27
28pub mod service_id {
30 pub const TRANSACTION_SERVICE: u32 = 0;
32 pub const CODE_SETS: u32 = 1;
34 pub const CHAIN_BYPASS_CHECK: u32 = 2;
36 pub const CHAIN_BYPASS_INFO: u32 = 3;
38 pub const LOGICAL_THREAD_ID: u32 = 4;
40 pub const BI_DIR_IIOP: u32 = 5;
42 pub const SENDING_CONTEXT_RUN_TIME: u32 = 6;
44 pub const INVOCATION_POLICIES: u32 = 7;
46 pub const FORWARDED_IDENTITY: u32 = 8;
48 pub const UNKNOWN_EXCEPTION_INFO: u32 = 9;
50 pub const RT_CORBA_PRIORITY: u32 = 10;
52 pub const RT_CORBA_PRIORITY_RANGE: u32 = 11;
54 pub const FT_GROUP_VERSION: u32 = 12;
56 pub const FT_REQUEST: u32 = 13;
58 pub const EXCEPTION_DETAIL_MESSAGE: u32 = 14;
60 pub const SECURITY_ATTRIBUTE_SERVICE: u32 = 15;
62 pub const ACTIVITY_SERVICE: u32 = 16;
64}
65
66pub mod code_set {
68 pub const ISO_8859_1: u32 = 0x0001_0001;
70 pub const UCS_2_LEVEL_1: u32 = 0x0001_0100;
72 pub const UTF_16: u32 = 0x0001_0109;
74 pub const UTF_8: u32 = 0x0501_0001;
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
81pub struct CodeSetContext {
82 pub char_data: u32,
84 pub wchar_data: u32,
86}
87
88impl CodeSetContext {
89 pub fn to_service_context(&self, order: ByteOrder) -> ServiceContext {
91 let mut enc = Encoder::encapsulation(order, CdrVersion::Giop1_2);
92 enc.write_u32(self.char_data);
93 enc.write_u32(self.wchar_data);
94 ServiceContext {
95 context_id: service_id::CODE_SETS,
96 context_data: enc.into_bytes(),
97 }
98 }
99
100 pub fn from_service_context(context: &ServiceContext) -> rustorb_cdr::Result<CodeSetContext> {
102 let mut dec = Decoder::encapsulation(&context.context_data, CdrVersion::Giop1_2)?;
103 Ok(CodeSetContext {
104 char_data: dec.read_u32()?,
105 wchar_data: dec.read_u32()?,
106 })
107 }
108
109 pub fn find(contexts: &[ServiceContext]) -> Option<rustorb_cdr::Result<CodeSetContext>> {
111 contexts
112 .iter()
113 .find(|c| c.context_id == service_id::CODE_SETS)
114 .map(CodeSetContext::from_service_context)
115 }
116}