[][src]Module bbqueue_ng::framed

A Framed flavor of BBQueue, useful for variable length packets

This module allows for a Framed mode of operation, where a size header is included in each grant, allowing for "chunks" of data to be passed through a BBQueue, rather than just a stream of bytes. This is convenient when receiving packets of variable sizes.

Example

use bbqueue_ng::BBBuffer;

let bb: BBBuffer<1000> = BBBuffer::new();
let (mut prod, mut cons) = bb.try_split_framed().unwrap();

// One frame in, one frame out
let mut wgrant = prod.grant(128).unwrap();
assert_eq!(wgrant.len(), 128);
for (idx, i) in wgrant.iter_mut().enumerate() {
    *i = idx as u8;
}
wgrant.commit(128);

let rgrant = cons.read().unwrap();
assert_eq!(rgrant.len(), 128);
for (idx, i) in rgrant.iter().enumerate() {
    assert_eq!(*i, idx as u8);
}
rgrant.release();

Frame header

An internal header is required for each frame stored inside of the BBQueue. This header is never exposed to end users of the bbqueue library.

A variable sized integer is used for the header size, and the size of this header is based on the max size requested for the grant. This header size must be factored in when calculating an appropriate total size of your buffer.

Even if a smaller portion of the grant is committed, the original requested grant size will be used for the header size calculation.

For example, if you request a 128 byte grant, the header size will be two bytes. If you then only commit 32 bytes, two bytes will still be used for the header of that grant.

Grant Size (bytes)Header size (bytes)
1..(2^7)1
(2^7)..(2^14)2
(2^14)..(2^21)3
(2^21)..(2^28)4
(2^28)..(2^35)5
(2^35)..(2^42)6
(2^42)..(2^49)7
(2^49)..(2^56)8
(2^56)..(2^64)9

Structs

FrameConsumer

A consumer of Framed data

FrameGrantR

A read grant for a single frame

FrameGrantW

A write grant for a single frame

FrameProducer

A producer of Framed data