rustorb-cdr 0.6.0

CDR (Common Data Representation) encoder and decoder for rustorb
Documentation
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
use rustorb_cdr::{
    ByteOrder, CdrDecode, CdrEncode, Decoder, Encoder, Encoding, Error, LongDouble, Segment,
};

const V12: Encoding = Encoding::Giop1_2;

fn encode<T: CdrEncode + ?Sized>(value: &T, order: ByteOrder) -> Vec<u8> {
    let mut enc = Encoder::new(order, V12);
    value.encode(&mut enc).unwrap();
    enc.into_bytes()
}

fn decode<T: CdrDecode>(bytes: &[u8], order: ByteOrder) -> T {
    let mut dec = Decoder::new(bytes, order, V12);
    let value = T::decode(&mut dec).unwrap();
    assert!(dec.is_empty(), "{} bytes left", dec.remaining());
    value
}

fn roundtrip<T: CdrEncode + CdrDecode + PartialEq + std::fmt::Debug>(value: T) {
    for order in [ByteOrder::Big, ByteOrder::Little] {
        let bytes = encode(&value, order);
        assert_eq!(decode::<T>(&bytes, order), value, "{order:?}");
    }
}

#[test]
fn primitives_big_endian() {
    let mut enc = Encoder::new(ByteOrder::Big, V12);
    enc.write_octet(0xAB);
    enc.write_i16(-2);
    enc.write_u32(0x0102_0304);
    enc.write_bool(true);
    enc.write_u64(0x0102_0304_0506_0708);
    enc.write_f32(1.0);
    enc.write_f64(-2.0);
    assert_eq!(
        enc.as_bytes(),
        [
            0xAB, 0x00, // octet, pad to 2
            0xFF, 0xFE, // short
            0x01, 0x02, 0x03, 0x04, // ulong
            0x01, // boolean
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // pad to 16
            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // ulonglong
            0x3F, 0x80, 0x00, 0x00, // float
            0x00, 0x00, 0x00, 0x00, // pad to 32
            0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // double
        ]
    );

    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Big, V12);
    assert_eq!(dec.read_octet().unwrap(), 0xAB);
    assert_eq!(dec.read_i16().unwrap(), -2);
    assert_eq!(dec.read_u32().unwrap(), 0x0102_0304);
    assert!(dec.read_bool().unwrap());
    assert_eq!(dec.read_u64().unwrap(), 0x0102_0304_0506_0708);
    assert_eq!(dec.read_f32().unwrap(), 1.0);
    assert_eq!(dec.read_f64().unwrap(), -2.0);
    assert!(dec.is_empty());
}

#[test]
fn long_double_is_16_octets_on_an_8_octet_boundary() {
    for (order, bytes) in [
        (
            ByteOrder::Big,
            [
                0x01, 0, 0, 0, 0, 0, 0, 0, // octet, pad to 8
                0xC0, 0x00, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // -3.0
            ],
        ),
        (
            ByteOrder::Little,
            [
                0x01, 0, 0, 0, 0, 0, 0, 0, // octet, pad to 8
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x00, 0xC0, // -3.0
            ],
        ),
    ] {
        let mut enc = Encoder::new(order, V12);
        enc.write_octet(1);
        enc.write_long_double(LongDouble::from_f64(-3.0));
        assert_eq!(enc.as_bytes(), bytes, "{order:?}");
        let mut dec = Decoder::new(&bytes, order, V12);
        assert_eq!(dec.read_octet().unwrap(), 1);
        assert_eq!(dec.read_long_double().unwrap().to_f64(), -3.0);
        assert!(dec.is_empty());
    }
    roundtrip(vec![LongDouble::from_bits(
        0x3fff_8000_0000_0000_0000_0000_0000_0001,
    )]);
}

#[test]
fn primitives_little_endian() {
    let mut enc = Encoder::new(ByteOrder::Little, V12);
    enc.write_u16(0x0102);
    enc.write_i32(-1);
    enc.write_u64(0x0102_0304_0506_0708);
    assert_eq!(
        enc.as_bytes(),
        [
            0x02, 0x01, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
            0x02, 0x01,
        ]
    );
}

#[test]
fn primitive_roundtrips() {
    roundtrip(true);
    roundtrip(0x7Fu8);
    roundtrip(-5i8);
    roundtrip(i16::MIN);
    roundtrip(u16::MAX);
    roundtrip(i32::MIN);
    roundtrip(u32::MAX);
    roundtrip(i64::MIN);
    roundtrip(u64::MAX);
    roundtrip(f32::MIN_POSITIVE);
    roundtrip(std::f64::consts::PI);
}

#[test]
fn alignment_follows_stream_offset() {
    // A body that starts at offset 12 (after a GIOP header) is aligned
    // against the whole message, not against the start of the body.
    let mut enc = Encoder::with_offset(ByteOrder::Big, V12, 12);
    enc.write_octet(1);
    enc.write_u64(2);
    assert_eq!(enc.len(), 1 + 3 + 8);
    assert_eq!(enc.position(), 24);

    let mut dec = Decoder::with_offset(enc.as_bytes(), ByteOrder::Big, V12, 12);
    assert_eq!(dec.read_octet().unwrap(), 1);
    assert_eq!(dec.read_u64().unwrap(), 2);
}

#[test]
fn padding_is_zero_and_skipped_regardless_of_value() {
    let bytes = [0x07, 0xAA, 0xBB, 0xCC, 0x00, 0x00, 0x00, 0x2A];
    let mut dec = Decoder::new(&bytes, ByteOrder::Big, V12);
    assert_eq!(dec.read_octet().unwrap(), 7);
    assert_eq!(dec.read_u32().unwrap(), 42);
}

#[test]
fn invalid_boolean() {
    let mut dec = Decoder::new(&[2], ByteOrder::Big, V12);
    assert_eq!(dec.read_bool(), Err(Error::InvalidBoolean(2)));
}

#[test]
fn truncated_input() {
    let mut dec = Decoder::new(&[0, 0, 1], ByteOrder::Big, V12);
    assert_eq!(
        dec.read_u32(),
        Err(Error::UnexpectedEof {
            needed: 4,
            remaining: 3
        })
    );
    // Padding past the end is also an error.
    let mut dec = Decoder::new(&[0, 0], ByteOrder::Big, V12);
    dec.read_octet().unwrap();
    assert!(dec.read_u32().is_err());
}

#[test]
fn string_encoding() {
    assert_eq!(encode("Hi", ByteOrder::Big), [0, 0, 0, 3, b'H', b'i', 0]);
    assert_eq!(encode("", ByteOrder::Little), [1, 0, 0, 0, 0]);
    roundtrip(String::from("こんにちは"));
    roundtrip(String::new());
}

#[test]
fn string_decoding_errors() {
    let mut dec = Decoder::new(&[0, 0, 0, 2, b'a', b'b'], ByteOrder::Big, V12);
    assert_eq!(dec.read_string(), Err(Error::StringNotTerminated));

    let mut dec = Decoder::new(&[0, 0, 0, 2, 0xFF, 0], ByteOrder::Big, V12);
    assert_eq!(dec.read_string(), Err(Error::InvalidUtf8));
    // The raw bytes are still available for non-UTF-8 code sets.
    let mut dec = Decoder::new(&[0, 0, 0, 2, 0xE9, 0], ByteOrder::Big, V12);
    assert_eq!(dec.read_string_bytes().unwrap(), [0xE9]);

    let mut dec = Decoder::new(&[0, 0, 0, 100, b'a', 0], ByteOrder::Big, V12);
    assert_eq!(
        dec.read_string(),
        Err(Error::LengthTooLarge {
            len: 100,
            remaining: 2
        })
    );

    // Length 0 is tolerated as an empty string.
    let mut dec = Decoder::new(&[0, 0, 0, 0], ByteOrder::Big, V12);
    assert_eq!(dec.read_string().unwrap(), "");
}

#[test]
fn wstring_giop_1_2() {
    // Octet length, then a BOM and UTF-16 in the stream byte order with no
    // terminator, as omniORB writes it.
    let mut enc = Encoder::new(ByteOrder::Little, V12);
    enc.write_wstring("Aé").unwrap();
    assert_eq!(
        enc.as_bytes(),
        [6, 0, 0, 0, 0xFF, 0xFE, 0x41, 0x00, 0xE9, 0x00]
    );
    let mut enc = Encoder::new(ByteOrder::Big, V12);
    enc.write_wstring("Aé").unwrap();
    assert_eq!(
        enc.as_bytes(),
        [0, 0, 0, 6, 0xFE, 0xFF, 0x00, 0x41, 0x00, 0xE9]
    );
    // An empty string has no BOM.
    let mut enc = Encoder::new(ByteOrder::Little, V12);
    enc.write_wstring("").unwrap();
    assert_eq!(enc.as_bytes(), [0, 0, 0, 0]);

    // Without a BOM: big-endian UTF-16, whatever the stream byte order.
    let mut enc = Encoder::new(ByteOrder::Little, V12);
    enc.set_wstring_bom(false);
    enc.write_wstring("Aé").unwrap();
    assert_eq!(enc.as_bytes(), [4, 0, 0, 0, 0x00, 0x41, 0x00, 0xE9]);

    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Little, V12);
    assert_eq!(dec.read_wstring().unwrap(), "Aé");

    // A BOM overrides the default order.
    let le_bom = [6, 0, 0, 0, 0xFF, 0xFE, 0x41, 0x00, 0xE9, 0x00];
    let mut dec = Decoder::new(&le_bom, ByteOrder::Little, V12);
    assert_eq!(dec.read_wstring().unwrap(), "Aé");

    // Peers that write the stream byte order without a BOM.
    let le = [4, 0, 0, 0, 0x41, 0x00, 0xE9, 0x00];
    let mut dec = Decoder::new(&le, ByteOrder::Little, V12);
    dec.set_wstring_default_order(ByteOrder::Little);
    assert_eq!(dec.read_wstring().unwrap(), "Aé");

    // Characters outside the BMP use surrogate pairs.
    for order in [ByteOrder::Big, ByteOrder::Little] {
        let mut enc = Encoder::new(order, V12);
        enc.write_wstring("🦀").unwrap();
        assert_eq!(enc.len(), 4 + 2 + 4);
        let mut dec = Decoder::new(enc.as_bytes(), order, V12);
        assert_eq!(dec.read_wstring().unwrap(), "🦀");
    }

    let odd = [3, 0, 0, 0, 0, 0x41, 0];
    let mut dec = Decoder::new(&odd, ByteOrder::Little, V12);
    assert_eq!(dec.read_wstring(), Err(Error::OddWstringLength(3)));

    let lone_surrogate = [0, 0, 0, 2, 0xD8, 0x00];
    let mut dec = Decoder::new(&lone_surrogate, ByteOrder::Big, V12);
    assert_eq!(dec.read_wstring(), Err(Error::InvalidUtf16));
}

#[test]
fn wstring_giop_1_1() {
    let v11 = Encoding::Giop1_1;
    let mut enc = Encoder::new(ByteOrder::Little, v11);
    enc.write_octet(9);
    enc.write_wstring("Hi").unwrap();
    // Length counts code units including the NUL; units are aligned and in
    // the stream byte order.
    assert_eq!(
        enc.as_bytes(),
        [9, 0, 0, 0, 3, 0, 0, 0, b'H', 0, b'i', 0, 0, 0]
    );
    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Little, v11);
    dec.read_octet().unwrap();
    assert_eq!(dec.read_wstring().unwrap(), "Hi");
}

#[test]
fn wchar_by_version() {
    let mut enc = Encoder::new(ByteOrder::Big, Encoding::Giop1_0);
    assert_eq!(enc.write_wchar(0x41), Err(Error::WcharNotSupported));
    assert_eq!(enc.write_wstring("A"), Err(Error::WcharNotSupported));

    let mut enc = Encoder::new(ByteOrder::Little, Encoding::Giop1_1);
    enc.write_octet(0);
    enc.write_wchar(0x3042).unwrap();
    assert_eq!(enc.as_bytes(), [0, 0, 0x42, 0x30]);

    let mut enc = Encoder::new(ByteOrder::Little, V12);
    enc.write_wchar(0x3042).unwrap();
    assert_eq!(enc.as_bytes(), [2, 0x30, 0x42]);
    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Little, V12);
    assert_eq!(dec.read_wchar().unwrap(), 0x3042);

    let with_bom = [4, 0xFF, 0xFE, 0x42, 0x30];
    let mut dec = Decoder::new(&with_bom, ByteOrder::Big, V12);
    assert_eq!(dec.read_wchar().unwrap(), 0x3042);

    let mut dec = Decoder::new(&[3, 0, 0, 0], ByteOrder::Big, V12);
    assert_eq!(dec.read_wchar(), Err(Error::InvalidWcharLength(3)));
}

#[test]
fn sequences() {
    assert_eq!(
        encode(&vec![1u16, 2, 3], ByteOrder::Big),
        [0, 0, 0, 3, 0, 1, 0, 2, 0, 3]
    );
    assert_eq!(
        encode(&vec![1u8, 2, 3], ByteOrder::Little),
        [3, 0, 0, 0, 1, 2, 3]
    );
    roundtrip(Vec::<u32>::new());
    roundtrip(vec![1.5f64, -0.25]);
    roundtrip(vec![String::from("a"), String::from("bc")]);
    roundtrip(vec![vec![1i16], vec![], vec![2, 3]]);
}

#[test]
fn sequence_length_guard() {
    // A huge length must fail before allocating.
    let bytes = [0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0];
    let mut dec = Decoder::new(&bytes, ByteOrder::Big, V12);
    assert!(matches!(
        Vec::<u64>::decode(&mut dec),
        Err(Error::LengthTooLarge { .. })
    ));
    let mut dec = Decoder::new(&bytes, ByteOrder::Big, V12);
    assert!(matches!(dec.read_len(8), Err(Error::LengthTooLarge { .. })));
}

#[test]
fn arrays_have_no_length() {
    assert_eq!(encode(&[1u16, 2], ByteOrder::Big), [0, 1, 0, 2]);
    roundtrip([[1i32, 2], [3, 4]]);
    roundtrip([7u8; 5]);
}

/// A struct as generated code would implement it.
#[derive(Debug, PartialEq)]
struct Sample {
    flag: bool,
    value: f64,
    name: String,
    points: Vec<Point>,
}

#[derive(Debug, PartialEq)]
struct Point {
    x: i16,
    y: i32,
}

impl CdrEncode for Point {
    fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
        self.x.encode(enc)?;
        self.y.encode(enc)
    }
}

impl CdrDecode for Point {
    fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
        Ok(Point {
            x: i16::decode(dec)?,
            y: i32::decode(dec)?,
        })
    }
}

impl CdrEncode for Sample {
    fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
        self.flag.encode(enc)?;
        self.value.encode(enc)?;
        self.name.encode(enc)?;
        self.points.encode(enc)
    }
}

impl CdrDecode for Sample {
    fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
        Ok(Sample {
            flag: bool::decode(dec)?,
            value: f64::decode(dec)?,
            name: String::decode(dec)?,
            points: Vec::decode(dec)?,
        })
    }
}

#[test]
fn nested_struct() {
    let sample = Sample {
        flag: true,
        value: 0.5,
        name: "pt".into(),
        points: vec![Point { x: 1, y: -1 }, Point { x: 2, y: 3 }],
    };
    let bytes = encode(&sample, ByteOrder::Big);
    assert_eq!(
        bytes,
        [
            1, 0, 0, 0, 0, 0, 0, 0, // flag + pad
            0x3F, 0xE0, 0, 0, 0, 0, 0, 0, // value
            0, 0, 0, 3, b'p', b't', 0, 0, // name + pad to 4
            0, 0, 0, 2, // points length
            0, 1, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, // Point { 1, -1 }
            0, 2, 0, 0, 0, 0, 0, 3, // Point { 2, 3 }
        ]
    );
    roundtrip(sample);
}

#[test]
fn encapsulation() {
    // The outer stream is misaligned on purpose; the encapsulation restarts
    // alignment at its byte order octet.
    let mut enc = Encoder::new(ByteOrder::Big, V12);
    enc.write_octet(0xEE);
    enc.write_encapsulation(|inner| {
        inner.write_u32(0x0001_0001);
        inner.write_u64(5);
        Ok(())
    })
    .unwrap();
    assert_eq!(
        enc.as_bytes(),
        [
            0xEE, 0, 0, 0, // octet + pad
            0, 0, 0, 16, // encapsulation length
            0, 0, 0, 0, // byte order + pad
            0, 1, 0, 1, // ulong
            0, 0, 0, 0, 0, 0, 0, 5, // ulonglong
        ]
    );

    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Big, V12);
    dec.read_octet().unwrap();
    let mut inner = dec.read_encapsulation().unwrap();
    assert!(dec.is_empty());
    assert_eq!(inner.byte_order(), ByteOrder::Big);
    assert_eq!(inner.read_u32().unwrap(), 0x0001_0001);
    assert_eq!(inner.read_u64().unwrap(), 5);
    assert!(inner.is_empty());
}

#[test]
fn encapsulation_with_different_byte_order() {
    let mut inner = Encoder::encapsulation(ByteOrder::Little, V12);
    inner.write_u32(1);
    let mut enc = Encoder::new(ByteOrder::Big, V12);
    enc.write_octet_seq(inner.as_bytes()).unwrap();

    let mut dec = Decoder::new(enc.as_bytes(), ByteOrder::Big, V12);
    let mut inner = dec.read_encapsulation().unwrap();
    assert_eq!(inner.byte_order(), ByteOrder::Little);
    assert_eq!(inner.read_u32().unwrap(), 1);
}

#[test]
fn encapsulation_errors() {
    assert_eq!(
        Decoder::encapsulation(&[], V12).unwrap_err(),
        Error::EmptyEncapsulation
    );
    assert_eq!(
        Decoder::encapsulation(&[7], V12).unwrap_err(),
        Error::InvalidByteOrder(7)
    );
}

#[test]
fn byte_order_flags() {
    assert_eq!(ByteOrder::Big.flag(), 0);
    assert_eq!(ByteOrder::Little.flag(), 1);
    assert_eq!(ByteOrder::from_flag(1), Ok(ByteOrder::Little));
    assert!(ByteOrder::from_flag(2).is_err());
}

#[test]
fn segments_restart_alignment() {
    // Two runs of bytes whose alignment restarts at offset 12 of a second
    // message, as in a GIOP 1.1 message joined from fragments.
    let mut first = Encoder::with_offset(ByteOrder::Little, V12, 12);
    first.write_u32(1);
    first.write_f64(2.5);
    let mut second = Encoder::with_offset(ByteOrder::Little, V12, 12);
    second.write_u16(3);
    second.write_f64(4.5);
    let mut buf = first.as_bytes().to_vec();
    let start = buf.len();
    buf.extend_from_slice(second.as_bytes());

    let segments = [Segment { start, offset: 12 }];
    let mut dec = Decoder::with_offset(&buf, ByteOrder::Little, V12, 12);
    dec.set_segments(&segments);
    assert_eq!(dec.read_u32().unwrap(), 1);
    assert_eq!(dec.read_f64().unwrap(), 2.5);
    assert_eq!(dec.position(), 12);
    assert_eq!(dec.read_u16().unwrap(), 3);
    assert_eq!(dec.read_f64().unwrap(), 4.5);
    assert!(dec.is_empty());
}

#[test]
fn eight_octet_values_align_to_eight_except_in_xcdr2() {
    for (encoding, pad) in [
        (Encoding::Giop1_2, 4),
        (Encoding::Xcdr1, 4),
        (Encoding::Xcdr2, 0),
    ] {
        let mut enc = Encoder::new(ByteOrder::Big, encoding);
        enc.write_u32(1);
        enc.write_u64(2);
        enc.write_f64(0.0);
        let mut expected = vec![0, 0, 0, 1];
        expected.extend(std::iter::repeat_n(0, pad));
        expected.extend([0, 0, 0, 0, 0, 0, 0, 2]);
        expected.extend([0; 8]);
        assert_eq!(enc.as_bytes(), expected, "{encoding:?}");

        let mut dec = Decoder::new(&expected, ByteOrder::Big, encoding);
        assert_eq!(dec.read_u32().unwrap(), 1);
        assert_eq!(dec.read_u64().unwrap(), 2);
        assert_eq!(dec.read_f64().unwrap(), 0.0);
        assert!(dec.is_empty(), "{encoding:?}");
    }
}

#[test]
fn xcdr2_aligns_long_double_to_four() {
    let mut enc = Encoder::new(ByteOrder::Little, Encoding::Xcdr2);
    enc.write_u32(7);
    enc.write_long_double(LongDouble::from_bits(1));
    assert_eq!(enc.len(), 20);
}

#[test]
fn encoding_kinds() {
    assert!(Encoding::Giop1_0.is_giop());
    assert!(Encoding::Giop1_2.is_giop());
    assert!(!Encoding::Xcdr1.is_giop());
    assert!(!Encoding::Xcdr2.is_giop());
    assert_eq!(Encoding::Giop1_2.max_align(), 8);
    assert_eq!(Encoding::Xcdr1.max_align(), 8);
    assert_eq!(Encoding::Xcdr2.max_align(), 4);
}