From 90ceffc41352cf98eb118c86ad08a4a538bff7c8 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Wed, 3 Nov 2021 22:21:05 -0400 Subject: [PATCH] turn one of the unit tests into an example in the README --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index e6e4441..55930d2 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,27 @@ This Secondary Header parsing is accomplished by allowing users of the library t ## Current status Currently this library just implements Primary Header parsing, but expanding it to be able to deal with a complete, generic spacepacket (think of generics in programming) with user defined custom secondary headers is one of the projects main goals. + + +## Usage + +```rust + // say you have some bytes you want to turn into a PrimaryHeader + let raw = b"\x00\x00\xc0\x00\x00\x40\xff\xff"; + + let expected = PrimaryHeader { + version: 0, + packet_type: types::PacketType::Data, + sec_header_flag: types::SecondaryHeaderFlag::NotPresent, + app_proc_id: 0, + sequence_flags: types::SeqFlag::Unsegmented, + sequence_count: 0, + data_length: 64, + }; + + // do the parsing and save the parsed header and any remaining bytes + let (rest, parsed) = PrimaryHeader::from_bytes((raw, 0)).expect("failed to parse header"); + + assert_eq!(parsed, expected); + assert_eq!(rest.0, [255,255]) +``` \ No newline at end of file