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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 ZeroDDS Contributors
//! Serde bridge for the XCDR2 encoder/decoder.
//!
//! Implements `zerodds-xcdr2-rust-1.0` §11.3 — the optional `serde-bridge`
//! feature. Lets you encode any `serde::Serialize` type, via a JSON
//! intermediate form, into a `Vec<u8>` that follows the **same wire
//! format** as a native `DdsType` implementation — provided the type has
//! a deterministic field layout.
//!
//! **Important:** This bridge is **not a replacement** for `#[derive(DdsType)]`
//! or `idl-rust` codegen. It is a convenience layer for apps that already
//! model their data with `serde` and want to produce XCDR2 wire output
//! without a separate type definition.
//!
//! Wire format: serde -> JSON string -> XCDR2 string-encoded. The decoder
//! parses the JSON string back. Compatible with any DDS topic type
//! `Greeting{ string text; }` that receives the JSON as a plain string.
//!
//! The module is only compiled when the `serde-bridge` feature is active;
//! the `#[cfg(...)]` gate sits on `pub mod serde_bridge` in `lib.rs`.
use String;
use Vec;
use Serialize;
use DeserializeOwned;
use crate;
use crateEndianness;
use crate;
/// Serializes a `serde::Serialize` type to JSON, then XCDR2-string
/// encodes it. Default endianness: little-endian.
///
/// # Errors
/// - `EncodeError::ValueOutOfRange` on a serde serialization error.
/// - `EncodeError::*` from the CDR string writer.
/// Deserializes an XCDR2-encoded string back into a
/// `serde::DeserializeOwned` type via JSON.
///
/// # Errors
/// - `DecodeError::*` from the CDR string reader.
/// - `DecodeError::InvalidUtf8` on a serde deserialization error
/// (offset = 0; the serde error detail is currently not propagated in
/// the error string, because `DecodeError` variants use
/// `&'static str`).
/// Convenience wrapper: return encoded bytes as a JSON string.
///
/// Useful for logging/debugging — returns the JSON intermediate form,
/// not the bytes.
///
/// # Errors
/// `DecodeError` if the bytes are not a valid XCDR2 string.