turbomcp-wire 3.1.1

Wire format codec abstraction for TurboMCP - JSON-RPC encoding/decoding
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
//! # TurboMCP Wire Format Codec
//!
//! This crate provides wire format encoding/decoding abstractions for MCP messages.
//! It enables pluggable serialization formats while maintaining MCP protocol compliance.
//!
//! ## Design Philosophy
//!
//! - **Wire format**: JSON-RPC 2.0 (MCP protocol standard)
//! - **Extensible**: Support for alternative formats (MessagePack, etc.)
//! - **Zero-copy ready**: Integration with rkyv for internal message passing
//! - **`no_std` compatible**: Works in embedded and WASM environments
//!
//! ## Usage
//!
//! ```rust
//! use turbomcp_wire::{Codec, JsonCodec};
//! use serde::{Serialize, Deserialize};
//!
//! #[derive(Serialize, Deserialize)]
//! struct MyMessage {
//!     id: u32,
//!     method: String,
//! }
//!
//! let codec = JsonCodec::new();
//! let msg = MyMessage { id: 1, method: "test".into() };
//!
//! // Encode to bytes
//! let bytes = codec.encode(&msg).unwrap();
//!
//! // Decode from bytes
//! let decoded: MyMessage = codec.decode(&bytes).unwrap();
//! ```
//!
//! ## Features
//!
//! - `std` - Standard library support (default)
//! - `json` - JSON codec (default)
//! - `simd` - SIMD-accelerated JSON (sonic-rs, simd-json)
//! - `msgpack` - MessagePack binary format

#![cfg_attr(not(feature = "std"), no_std)]
#![deny(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]

extern crate alloc;

use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::fmt;
use serde::{Serialize, de::DeserializeOwned};

// Re-export core types for convenience
pub use turbomcp_core::error::McpError;

/// Wire format codec error
#[derive(Debug, Clone)]
pub struct CodecError {
    /// Error message
    pub message: String,
    /// Optional source location
    pub source: Option<String>,
}

impl fmt::Display for CodecError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "codec error: {}", self.message)
    }
}

#[cfg(feature = "std")]
impl std::error::Error for CodecError {}

impl CodecError {
    /// Create a new codec error
    pub fn new(message: impl Into<String>) -> Self {
        Self {
            message: message.into(),
            source: None,
        }
    }

    /// Create a codec error with source information
    pub fn with_source(message: impl Into<String>, source: impl Into<String>) -> Self {
        Self {
            message: message.into(),
            source: Some(source.into()),
        }
    }

    /// Create an encoding error
    pub fn encode(message: impl Into<String>) -> Self {
        Self::new(alloc::format!("encode: {}", message.into()))
    }

    /// Create a decoding error
    pub fn decode(message: impl Into<String>) -> Self {
        Self::new(alloc::format!("decode: {}", message.into()))
    }
}

impl From<CodecError> for McpError {
    fn from(err: CodecError) -> Self {
        McpError::parse_error(err.message)
    }
}

/// Result type for codec operations
pub type CodecResult<T> = Result<T, CodecError>;

/// Wire format codec trait
///
/// This trait abstracts over different serialization formats, allowing
/// pluggable encoding/decoding while maintaining type safety.
///
/// # Send + Sync Bounds
///
/// The `Send + Sync` bounds are required because codecs are typically shared across
/// multiple threads/tasks in multi-threaded runtimes (tokio, async-std). This enables:
///
/// - **Concurrent encoding/decoding**: Multiple tasks can use the codec simultaneously
/// - **Zero-copy sharing**: Codec instances can be wrapped in Arc and shared cheaply
/// - **Thread-safe initialization**: Codec configuration is immutable after creation
///
/// ## WASM Implications
///
/// On WASM targets (single-threaded), these bounds are automatically satisfied since
/// all types are `Send + Sync` by default in single-threaded environments. The trait
/// bounds don't add overhead on WASM - they're purely compile-time constraints that
/// prevent accidental use of non-thread-safe types on native platforms.
///
/// # Implementors
///
/// - [`JsonCodec`] - Standard JSON encoding (default)
/// - `SimdJsonCodec` - SIMD-accelerated JSON (requires `simd` feature)
/// - `MsgPackCodec` - MessagePack binary format (requires `msgpack` feature)
pub trait Codec: Send + Sync {
    /// Encode a value to bytes
    fn encode<T: Serialize>(&self, value: &T) -> CodecResult<Vec<u8>>;

    /// Decode bytes to a value
    fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> CodecResult<T>;

    /// Get the content type for this codec (e.g., "application/json")
    fn content_type(&self) -> &'static str;

    /// Check if this codec supports streaming
    fn supports_streaming(&self) -> bool {
        false
    }

    /// Get codec name for debugging
    fn name(&self) -> &'static str;
}

/// JSON codec using serde_json
///
/// This is the default codec for MCP protocol compliance.
/// It produces human-readable JSON suitable for debugging and logging.
#[derive(Debug, Clone, Default)]
pub struct JsonCodec {
    /// Pretty print output (default: false)
    pub pretty: bool,
}

impl JsonCodec {
    /// Create a new JSON codec
    pub fn new() -> Self {
        Self::default()
    }

    /// Create a JSON codec with pretty printing enabled
    pub fn pretty() -> Self {
        Self { pretty: true }
    }
}

impl Codec for JsonCodec {
    fn encode<T: Serialize>(&self, value: &T) -> CodecResult<Vec<u8>> {
        if self.pretty {
            serde_json::to_vec_pretty(value)
        } else {
            serde_json::to_vec(value)
        }
        .map_err(|e| CodecError::encode(e.to_string()))
    }

    fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> CodecResult<T> {
        serde_json::from_slice(bytes).map_err(|e| CodecError::decode(e.to_string()))
    }

    fn content_type(&self) -> &'static str {
        "application/json"
    }

    fn supports_streaming(&self) -> bool {
        true
    }

    fn name(&self) -> &'static str {
        "json"
    }
}

/// SIMD-accelerated JSON codec using sonic-rs
///
/// This codec uses SIMD instructions for faster JSON parsing.
/// Falls back to standard serde_json on unsupported platforms.
#[cfg(feature = "simd")]
#[cfg_attr(docsrs, doc(cfg(feature = "simd")))]
#[derive(Debug, Clone, Default)]
pub struct SimdJsonCodec;

#[cfg(feature = "simd")]
impl SimdJsonCodec {
    /// Create a new SIMD JSON codec
    pub fn new() -> Self {
        Self
    }
}

#[cfg(feature = "simd")]
impl Codec for SimdJsonCodec {
    fn encode<T: Serialize>(&self, value: &T) -> CodecResult<Vec<u8>> {
        sonic_rs::to_vec(value).map_err(|e| CodecError::encode(e.to_string()))
    }

    fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> CodecResult<T> {
        sonic_rs::from_slice(bytes).map_err(|e| CodecError::decode(e.to_string()))
    }

    fn content_type(&self) -> &'static str {
        "application/json"
    }

    fn supports_streaming(&self) -> bool {
        true
    }

    fn name(&self) -> &'static str {
        "simd-json"
    }
}

/// MessagePack binary codec
///
/// This codec produces compact binary output, suitable for
/// high-throughput scenarios where bandwidth is limited.
///
/// **Note**: MessagePack is not MCP-compliant for external communication
/// but can be used for internal message passing.
///
/// # Security Considerations
///
/// When using MessagePack for untrusted input, be aware of:
///
/// ## Nesting Depth
///
/// Deeply nested structures can cause stack overflow. The underlying `rmp-serde`
/// library has default recursion limits, but extremely nested payloads may still
/// cause issues. Consider validating message structure before decoding.
///
/// ## Binary Field Size
///
/// MessagePack can encode arbitrarily large binary/string fields. Applications should:
/// - Enforce maximum message size limits at the transport layer
/// - Use streaming decoders for large payloads when possible
/// - Set appropriate memory limits in production environments
///
/// ## Type Confusion
///
/// MessagePack's dynamic typing can lead to type confusion attacks. Always:
/// - Validate deserialized data matches expected schema
/// - Use strongly-typed Rust structs rather than `serde_json::Value`
/// - Check for unexpected field types after deserialization
///
/// ## Recommended Usage
///
/// For production systems handling untrusted input, prefer JSON (with schema validation)
/// or use MessagePack only within trusted boundaries (internal microservices, etc.).
#[cfg(feature = "msgpack")]
#[cfg_attr(docsrs, doc(cfg(feature = "msgpack")))]
#[derive(Debug, Clone, Default)]
pub struct MsgPackCodec;

#[cfg(feature = "msgpack")]
impl MsgPackCodec {
    /// Create a new MessagePack codec
    pub fn new() -> Self {
        Self
    }
}

#[cfg(feature = "msgpack")]
impl Codec for MsgPackCodec {
    fn encode<T: Serialize>(&self, value: &T) -> CodecResult<Vec<u8>> {
        // Use named serialization to support skip_serializing_if on optional fields
        rmp_serde::to_vec_named(value).map_err(|e| CodecError::encode(e.to_string()))
    }

    fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> CodecResult<T> {
        rmp_serde::from_slice(bytes).map_err(|e| CodecError::decode(e.to_string()))
    }

    fn content_type(&self) -> &'static str {
        "application/msgpack"
    }

    fn supports_streaming(&self) -> bool {
        false
    }

    fn name(&self) -> &'static str {
        "msgpack"
    }
}

/// Maximum streaming buffer size (1MB) - prevents DoS via unbounded memory growth
const MAX_STREAMING_BUFFER_SIZE: usize = 1024 * 1024;

/// Streaming JSON decoder for Server-Sent Events (SSE)
///
/// This decoder handles newline-delimited JSON streams commonly
/// used in HTTP/SSE transports.
///
/// # Security
///
/// The decoder enforces a maximum buffer size of 1MB to prevent
/// denial-of-service attacks via unbounded memory consumption.
/// If an attacker sends continuous data without newlines, the
/// buffer will be cleared after exceeding the limit.
#[derive(Debug)]
pub struct StreamingJsonDecoder {
    buffer: Vec<u8>,
    max_buffer_size: usize,
}

impl Default for StreamingJsonDecoder {
    fn default() -> Self {
        Self::new()
    }
}

impl StreamingJsonDecoder {
    /// Create a new streaming decoder with default 1MB buffer limit
    pub fn new() -> Self {
        Self {
            buffer: Vec::new(),
            max_buffer_size: MAX_STREAMING_BUFFER_SIZE,
        }
    }

    /// Create with pre-allocated buffer capacity and default limit
    pub fn with_capacity(capacity: usize) -> Self {
        Self {
            buffer: Vec::with_capacity(capacity),
            max_buffer_size: MAX_STREAMING_BUFFER_SIZE,
        }
    }

    /// Create with custom maximum buffer size
    ///
    /// # Arguments
    ///
    /// * `max_size` - Maximum buffer size in bytes (capped at 10MB for safety)
    ///
    /// # Security
    ///
    /// Setting this too high may allow DoS attacks via memory exhaustion.
    /// The value is capped at 10MB regardless of input.
    pub fn with_max_size(max_size: usize) -> Self {
        Self {
            buffer: Vec::new(),
            max_buffer_size: max_size.min(10 * 1024 * 1024), // Cap at 10MB
        }
    }

    /// Feed data into the decoder
    ///
    /// # Security
    ///
    /// If the buffer exceeds the maximum size, it will be cleared and
    /// an error will be returned on the next `try_decode` call.
    pub fn feed(&mut self, data: &[u8]) {
        self.buffer.extend_from_slice(data);

        // Enforce buffer size limit to prevent DoS
        if self.buffer.len() > self.max_buffer_size {
            #[cfg(feature = "std")]
            tracing::warn!(
                buffer_size = self.buffer.len(),
                max_size = self.max_buffer_size,
                "Streaming buffer exceeded maximum size, clearing buffer"
            );
            self.buffer.clear();
        }
    }

    /// Try to decode the next complete message
    ///
    /// Returns `Some(T)` if a complete message is available,
    /// `None` if more data is needed.
    pub fn try_decode<T: DeserializeOwned>(&mut self) -> CodecResult<Option<T>> {
        // Look for newline delimiter
        if let Some(pos) = self.buffer.iter().position(|&b| b == b'\n') {
            let line = &self.buffer[..pos];

            // Skip empty lines
            if line.is_empty() || line.iter().all(|b| b.is_ascii_whitespace()) {
                self.buffer.drain(..=pos);
                return Ok(None);
            }

            // Try to decode
            let result = serde_json::from_slice(line);

            // Remove processed data (including newline)
            self.buffer.drain(..=pos);

            match result {
                Ok(value) => Ok(Some(value)),
                Err(e) => Err(CodecError::decode(e.to_string())),
            }
        } else {
            Ok(None)
        }
    }

    /// Clear the internal buffer
    pub fn clear(&mut self) {
        self.buffer.clear();
    }

    /// Check if buffer is empty
    pub fn is_empty(&self) -> bool {
        self.buffer.is_empty()
    }

    /// Get current buffer length
    pub fn len(&self) -> usize {
        self.buffer.len()
    }

    /// Get maximum buffer size
    pub fn max_buffer_size(&self) -> usize {
        self.max_buffer_size
    }
}

/// Enum wrapper for all codec types
///
/// This provides a unified type for codec selection without requiring
/// dyn trait objects (which aren't compatible with generic methods).
#[derive(Debug, Clone)]
pub enum AnyCodec {
    /// Standard JSON codec
    Json(JsonCodec),
    /// SIMD-accelerated JSON codec
    #[cfg(feature = "simd")]
    #[cfg_attr(docsrs, doc(cfg(feature = "simd")))]
    SimdJson(SimdJsonCodec),
    /// MessagePack binary codec
    #[cfg(feature = "msgpack")]
    #[cfg_attr(docsrs, doc(cfg(feature = "msgpack")))]
    MsgPack(MsgPackCodec),
}

impl AnyCodec {
    /// Create a codec by name
    ///
    /// Supported names:
    /// - `"json"` - Standard JSON codec
    /// - `"simd"` or `"simd-json"` - SIMD-accelerated JSON (requires `simd` feature)
    /// - `"msgpack"` - MessagePack binary (requires `msgpack` feature)
    pub fn from_name(name: &str) -> Option<Self> {
        match name {
            "json" => Some(Self::Json(JsonCodec::new())),
            #[cfg(feature = "simd")]
            "simd" | "simd-json" => Some(Self::SimdJson(SimdJsonCodec::new())),
            #[cfg(feature = "msgpack")]
            "msgpack" => Some(Self::MsgPack(MsgPackCodec::new())),
            _ => None,
        }
    }

    /// List available codec names
    pub fn available_names() -> &'static [&'static str] {
        &[
            "json",
            #[cfg(feature = "simd")]
            "simd-json",
            #[cfg(feature = "msgpack")]
            "msgpack",
        ]
    }

    /// Encode a value to bytes
    pub fn encode<T: Serialize>(&self, value: &T) -> CodecResult<Vec<u8>> {
        match self {
            Self::Json(c) => c.encode(value),
            #[cfg(feature = "simd")]
            Self::SimdJson(c) => c.encode(value),
            #[cfg(feature = "msgpack")]
            Self::MsgPack(c) => c.encode(value),
        }
    }

    /// Decode bytes to a value
    pub fn decode<T: DeserializeOwned>(&self, bytes: &[u8]) -> CodecResult<T> {
        match self {
            Self::Json(c) => c.decode(bytes),
            #[cfg(feature = "simd")]
            Self::SimdJson(c) => c.decode(bytes),
            #[cfg(feature = "msgpack")]
            Self::MsgPack(c) => c.decode(bytes),
        }
    }

    /// Get the content type
    pub fn content_type(&self) -> &'static str {
        match self {
            Self::Json(c) => c.content_type(),
            #[cfg(feature = "simd")]
            Self::SimdJson(c) => c.content_type(),
            #[cfg(feature = "msgpack")]
            Self::MsgPack(c) => c.content_type(),
        }
    }

    /// Get codec name
    pub fn name(&self) -> &'static str {
        match self {
            Self::Json(c) => c.name(),
            #[cfg(feature = "simd")]
            Self::SimdJson(c) => c.name(),
            #[cfg(feature = "msgpack")]
            Self::MsgPack(c) => c.name(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    struct TestMessage {
        id: u32,
        method: String,
        params: Option<serde_json::Value>,
    }

    #[test]
    fn test_json_codec_roundtrip() {
        let codec = JsonCodec::new();
        let msg = TestMessage {
            id: 42,
            method: "test/method".into(),
            params: Some(serde_json::json!({"key": "value"})),
        };

        let encoded = codec.encode(&msg).unwrap();
        let decoded: TestMessage = codec.decode(&encoded).unwrap();

        assert_eq!(msg, decoded);
    }

    #[test]
    fn test_json_codec_pretty() {
        let codec = JsonCodec::pretty();
        let msg = TestMessage {
            id: 1,
            method: "test".into(),
            params: None,
        };

        let encoded = codec.encode(&msg).unwrap();
        let output = String::from_utf8(encoded).unwrap();

        // Pretty output should contain newlines
        assert!(output.contains('\n'));
    }

    #[test]
    fn test_codec_content_type() {
        let json = JsonCodec::new();
        assert_eq!(json.content_type(), "application/json");
        assert_eq!(json.name(), "json");
    }

    #[test]
    fn test_streaming_decoder() {
        let mut decoder = StreamingJsonDecoder::new();

        // Feed partial data
        decoder.feed(br#"{"id":1,"method":"a","params":null}"#);
        assert!(decoder.try_decode::<TestMessage>().unwrap().is_none());

        // Feed newline to complete
        decoder.feed(b"\n");
        let msg: TestMessage = decoder.try_decode().unwrap().unwrap();
        assert_eq!(msg.id, 1);
        assert_eq!(msg.method, "a");
    }

    #[test]
    fn test_streaming_decoder_multiple() {
        let mut decoder = StreamingJsonDecoder::new();

        // Feed multiple messages at once
        decoder.feed(
            br#"{"id":1,"method":"a","params":null}
{"id":2,"method":"b","params":null}
"#,
        );

        let msg1: TestMessage = decoder.try_decode().unwrap().unwrap();
        assert_eq!(msg1.id, 1);

        let msg2: TestMessage = decoder.try_decode().unwrap().unwrap();
        assert_eq!(msg2.id, 2);

        // No more messages
        assert!(decoder.try_decode::<TestMessage>().unwrap().is_none());
    }

    #[test]
    fn test_streaming_decoder_buffer_limit() {
        let mut decoder = StreamingJsonDecoder::with_max_size(100);

        // Feed data that exceeds buffer limit (no newline)
        let large_data = vec![b'x'; 150];
        decoder.feed(&large_data);

        // Buffer should be cleared after exceeding limit
        assert!(
            decoder.is_empty(),
            "Buffer should be cleared after exceeding limit"
        );
    }

    #[test]
    fn test_streaming_decoder_max_size_cap() {
        // Try to create decoder with absurdly large limit
        let decoder = StreamingJsonDecoder::with_max_size(100 * 1024 * 1024); // 100MB

        // Should be capped at 10MB
        assert_eq!(decoder.max_buffer_size(), 10 * 1024 * 1024);
    }

    #[test]
    fn test_streaming_decoder_default_limit() {
        let decoder = StreamingJsonDecoder::new();
        assert_eq!(decoder.max_buffer_size(), 1024 * 1024); // 1MB default
    }

    #[test]
    fn test_any_codec() {
        let codec = AnyCodec::from_name("json").unwrap();
        assert_eq!(codec.name(), "json");

        assert!(AnyCodec::from_name("unknown").is_none());
        assert!(AnyCodec::available_names().contains(&"json"));
    }

    #[test]
    fn test_codec_error() {
        let codec = JsonCodec::new();
        let result: CodecResult<TestMessage> = codec.decode(b"invalid json");
        assert!(result.is_err());

        let err = result.unwrap_err();
        assert!(err.message.contains("decode"));
    }

    #[cfg(feature = "simd")]
    #[test]
    fn test_simd_codec_roundtrip() {
        let codec = SimdJsonCodec::new();
        let msg = TestMessage {
            id: 99,
            method: "simd/test".into(),
            params: Some(serde_json::json!([1, 2, 3])),
        };

        let encoded = codec.encode(&msg).unwrap();
        let decoded: TestMessage = codec.decode(&encoded).unwrap();

        assert_eq!(msg, decoded);
    }

    #[cfg(feature = "msgpack")]
    #[test]
    fn test_msgpack_codec_roundtrip() {
        let codec = MsgPackCodec::new();
        let msg = TestMessage {
            id: 77,
            method: "msgpack/test".into(),
            params: None,
        };

        let encoded = codec.encode(&msg).unwrap();
        let decoded: TestMessage = codec.decode(&encoded).unwrap();

        assert_eq!(msg, decoded);
        assert_eq!(codec.content_type(), "application/msgpack");
    }
}