rustorb_giop/
component.rs1use rustorb_cdr::{ByteOrder, CdrDecode, CdrEncode, Decoder, Encoder, Encoding};
2
3use crate::Result;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct TaggedComponent {
9 pub tag: u32,
11 pub component_data: Vec<u8>,
13}
14
15impl CdrEncode for TaggedComponent {
16 fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
17 enc.write_u32(self.tag);
18 enc.write_octet_seq(&self.component_data)
19 }
20}
21
22impl CdrDecode for TaggedComponent {
23 fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
24 Ok(TaggedComponent {
25 tag: dec.read_u32()?,
26 component_data: dec.read_octet_seq()?.to_vec(),
27 })
28 }
29}
30
31impl TaggedComponent {
32 pub fn encapsulated<F>(tag: u32, order: ByteOrder, f: F) -> Result<TaggedComponent>
34 where
35 F: FnOnce(&mut Encoder) -> rustorb_cdr::Result<()>,
36 {
37 let mut enc = Encoder::encapsulation(order, Encoding::Giop1_2);
38 f(&mut enc)?;
39 Ok(TaggedComponent {
40 tag,
41 component_data: enc.into_bytes(),
42 })
43 }
44
45 pub fn decoder(&self) -> Result<Decoder<'_>> {
47 Ok(Decoder::encapsulation(
48 &self.component_data,
49 Encoding::Giop1_2,
50 )?)
51 }
52}
53
54pub mod component_tag {
56 pub const ORB_TYPE: u32 = 0;
58 pub const CODE_SETS: u32 = 1;
60 pub const POLICIES: u32 = 2;
62 pub const ALTERNATE_IIOP_ADDRESS: u32 = 3;
64 pub const COMPLETE_OBJECT_KEY: u32 = 5;
66 pub const ENDPOINT_ID_POSITION: u32 = 6;
68 pub const LOCATION_POLICY: u32 = 12;
70 pub const ASSOCIATION_OPTIONS: u32 = 13;
72 pub const SEC_NAME: u32 = 14;
74 pub const SSL_SEC_TRANS: u32 = 20;
76 pub const JAVA_CODEBASE: u32 = 25;
78 pub const CSI_SEC_MECH_LIST: u32 = 33;
80 pub const NULL_TAG: u32 = 34;
82 pub const TLS_SEC_TRANS: u32 = 36;
84 pub const OMNIORB_BIDIR: u32 = 0x4154_5401;
86 pub const OMNIORB_UNIX_TRANS: u32 = 0x4154_5402;
88 pub const OMNIORB_PERSISTENT_ID: u32 = 0x4154_5403;
90 pub const OMNIORB_RESTRICTED_CONNECTION: u32 = 0x4154_5404;
92 pub const OMNIORB_HTTP_TRANS: u32 = 0x4154_5405;
94}
95
96pub mod orb_type {
98 pub const OMNIORB: u32 = 0x4154_5400;
100}
101
102#[derive(Debug, Clone, PartialEq, Eq, Default)]
105pub struct CodeSetComponent {
106 pub native_code_set: u32,
108 pub conversion_code_sets: Vec<u32>,
110}
111
112impl CdrEncode for CodeSetComponent {
113 fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
114 enc.write_u32(self.native_code_set);
115 self.conversion_code_sets.encode(enc)
116 }
117}
118
119impl CdrDecode for CodeSetComponent {
120 fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
121 Ok(CodeSetComponent {
122 native_code_set: dec.read_u32()?,
123 conversion_code_sets: Vec::decode(dec)?,
124 })
125 }
126}
127
128#[derive(Debug, Clone, PartialEq, Eq, Default)]
131pub struct CodeSetComponentInfo {
132 pub for_char_data: CodeSetComponent,
134 pub for_wchar_data: CodeSetComponent,
136}
137
138impl CodeSetComponentInfo {
139 pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
141 TaggedComponent::encapsulated(component_tag::CODE_SETS, order, |enc| {
142 self.for_char_data.encode(enc)?;
143 self.for_wchar_data.encode(enc)
144 })
145 }
146
147 pub fn from_component(component: &TaggedComponent) -> Result<CodeSetComponentInfo> {
149 let mut dec = component.decoder()?;
150 Ok(CodeSetComponentInfo {
151 for_char_data: CodeSetComponent::decode(&mut dec)?,
152 for_wchar_data: CodeSetComponent::decode(&mut dec)?,
153 })
154 }
155}
156
157#[derive(Debug, Clone, PartialEq, Eq)]
160pub struct AlternateIiopAddress {
161 pub host: String,
163 pub port: u16,
165}
166
167impl AlternateIiopAddress {
168 pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
171 TaggedComponent::encapsulated(component_tag::ALTERNATE_IIOP_ADDRESS, order, |enc| {
172 enc.write_string(&self.host)?;
173 enc.write_u16(self.port);
174 Ok(())
175 })
176 }
177
178 pub fn from_component(component: &TaggedComponent) -> Result<AlternateIiopAddress> {
180 let mut dec = component.decoder()?;
181 Ok(AlternateIiopAddress {
182 host: dec.read_string()?,
183 port: dec.read_u16()?,
184 })
185 }
186}
187
188pub mod association_options {
191 pub const NO_PROTECTION: u16 = 1;
193 pub const INTEGRITY: u16 = 2;
195 pub const CONFIDENTIALITY: u16 = 4;
197 pub const DETECT_REPLAY: u16 = 8;
199 pub const DETECT_MISORDERING: u16 = 16;
201 pub const ESTABLISH_TRUST_IN_TARGET: u16 = 32;
203 pub const ESTABLISH_TRUST_IN_CLIENT: u16 = 64;
205}
206
207#[derive(Debug, Clone, Copy, PartialEq, Eq)]
211pub struct SslSecTrans {
212 pub target_supports: u16,
214 pub target_requires: u16,
216 pub port: u16,
218}
219
220impl SslSecTrans {
221 pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
223 TaggedComponent::encapsulated(component_tag::SSL_SEC_TRANS, order, |enc| {
224 enc.write_u16(self.target_supports);
225 enc.write_u16(self.target_requires);
226 enc.write_u16(self.port);
227 Ok(())
228 })
229 }
230
231 pub fn from_component(component: &TaggedComponent) -> Result<SslSecTrans> {
233 let mut dec = component.decoder()?;
234 Ok(SslSecTrans {
235 target_supports: dec.read_u16()?,
236 target_requires: dec.read_u16()?,
237 port: dec.read_u16()?,
238 })
239 }
240}
241
242pub fn orb_type_component(orb_type: u32, order: ByteOrder) -> Result<TaggedComponent> {
244 TaggedComponent::encapsulated(component_tag::ORB_TYPE, order, |enc| {
245 enc.write_u32(orb_type);
246 Ok(())
247 })
248}