Skip to main content

decode_datagram

Function decode_datagram 

Source
pub fn decode_datagram(datagram: &[u8]) -> Result<Option<PonkFrame>, PonkError>
Examples found in repository?
examples/roundtrip.rs (line 38)
9fn main() {
10    let frame = PonkFrame {
11        sender_id: 1,
12        sender_name: "roundtrip-example".to_string(),
13        frame_number: 0,
14        paths: vec![PonkPath {
15            metadata: vec![PonkMetadata {
16                key: "PATHNUMB".to_string(),
17                value: 0.0,
18            }],
19            points: vec![
20                PonkPoint {
21                    x: -0.5,
22                    y: -0.5,
23                    rgb: [255, 0, 0],
24                },
25                PonkPoint {
26                    x: 0.5,
27                    y: 0.5,
28                    rgb: [0, 255, 0],
29                },
30            ],
31        }],
32    };
33
34    let datagrams =
35        encode_datagrams(&frame, DataFormat::XyF32RgbU8, 1200).expect("frame should encode");
36    println!("encoded into {} datagram(s)", datagrams.len());
37
38    let decoded = decode_datagram(&datagrams[0])
39        .expect("valid datagram")
40        .expect("single-chunk frame");
41
42    println!(
43        "decoded frame from '{}' with {} path(s), {} point(s)",
44        decoded.sender_name,
45        decoded.paths.len(),
46        decoded.paths[0].points.len(),
47    );
48    assert_eq!(decoded.paths[0].points, frame.paths[0].points);
49    println!("roundtrip ok");
50}