#byte #file #marks


A rust crate to mark/unmark/recover transmitted/received bytes across the wire

11 releases

0.1.11 Jan 19, 2022
0.1.10 Jan 19, 2022
0.1.9 Dec 29, 2021
0.1.0 Nov 30, 2021
Download history 8/week @ 2023-07-21 5/week @ 2023-07-28 4/week @ 2023-08-04 5/week @ 2023-08-11 16/week @ 2023-08-18 27/week @ 2023-08-25 19/week @ 2023-09-01 8/week @ 2023-09-08 5/week @ 2023-09-15 6/week @ 2023-09-22 6/week @ 2023-09-29 6/week @ 2023-10-06 5/week @ 2023-10-13 7/week @ 2023-10-20 28/week @ 2023-10-27 19/week @ 2023-11-03

59 downloads per month
Used in arrows


641 lines


A configurable bytes' boundary marker for transmitting and receiving bytes from network/files. This comes very handy while building application network protocols - for example, one could read off the demarcated bytes of the wire and could use bincode (https://github.com/bincode-org/bincode) to reconstruct a struct from those bytes.


        //message_stream -> stream of messages -> msg|suffix|msg|suffix|msg|tail
        let message_stream  = "StreamingsUfFiX withsUfFiX markssUfFiX and tailtAiL";
        //The following is for only showing validation
        let mut messages = Vec::new();
        messages.push(" with".as_bytes());
        messages.push(" marks".as_bytes());
        messages.push(" and tail".as_bytes());
        //Cursor is akin to a TcpStream
        let mut cursor = Cursor::new(message_stream.as_bytes());
        //From the stream create an iterator and validate the received message chunks
        let stream = Marked::new(&mut cursor, "sUfFiX", "tAiL");
        let zipped = stream.into_iter().zip(messages.iter());

        for (unmarked, message) in zipped {
            assert!(unmarked == message.to_vec());
     Shows how to unmark byte chunks out from a stream of marked bytes
     let random_texts = [
            "Some random",
            "strings from this array",
            "are getiing",
            "picked and being",
            "converted to",
            "to bytes",
            "then suffixed",
            "with byte marks.",
            "marked bytes",
            "are then getting",
            "stripped off of",
  let mut randomizer = rand::thread_rng();
        let num_strings: usize = randomizer.gen_range(0..1000);
        let mut orig_strings = vec![];
        let mut marked_bytes = vec![];
        let marker = ByteMarker::new("sUfFiX", "");
        for _ in 0..num_strings {
            //Pick a random index
            let index = randomizer.gen_range(0..random_texts.len());
            //Pick a random string for the given index
            let picked_string = random_texts[index];
            //Get the bytes and demarcate with byte marks
            let mut bytes = picked_string.as_bytes().to_vec();
            marker.mark_bytes(&mut bytes);//The bytes have been attached with the marker     bytes of ```sUfFiX```
           //Preserve the old string for assertion below
           //Keep extending the marked bytes
        //Marked bytes may be written to a file/sent across the wire
        //Get the orginal strings back from marked bytes on receipt
        let unmarked = marker.unmark(&marked_bytes).unwrap().0;
        //We must get same bytes back with demarcating bytes removed
        //Lets reconstruct the strings back and validate
        for i in 0..unmarked.len() {