| 372 | |
| 373 | #[test] |
| 374 | fn json_hex_roundtrip() -> Result<()> { |
| 375 | let stream = TlvStream(vec![rec(1, &[0x01, 0x02]), rec(5, &[0xaa])]); |
| 376 | |
| 377 | // Serialize to hex string in JSON |
| 378 | let json = serde_json::to_string(&stream)?; |
| 379 | // It's a quoted hex string; check inner value |
| 380 | let s: String = serde_json::from_str(&json)?; |
| 381 | assert_eq!(s, "010201020501aa"); |
| 382 | |
| 383 | // And back from JSON hex |
| 384 | let back: TlvStream = serde_json::from_str(&json)?; |
| 385 | assert_eq!(back.0.len(), 2); |
| 386 | assert_eq!(back.0[0].type_, 1); |
| 387 | assert_eq!(back.0[0].value, vec![0x01, 0x02]); |
| 388 | assert_eq!(back.0[1].type_, 5); |
| 389 | assert_eq!(back.0[1].value, vec![0xaa]); |
| 390 | |
| 391 | Ok(()) |
| 392 | } |
| 393 | |
| 394 | #[test] |
| 395 | fn decode_with_len_prefix() -> Result<()> { |