Skip to content

Commit

Permalink
ClosedSourceMeta:
Browse files Browse the repository at this point in the history
  * the decoding process will need it

Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Nov 2, 2024
1 parent 5a40e6c commit cee4b66
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 36 deletions.
18 changes: 10 additions & 8 deletions binex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ loop {
},
Some(Ok(StreamElement::ClosedSource(element))) => {
// verify this is your organization
if element.provider == Provider::JPL {
// MID and MLEN should follow the BINEX specs
// and are provided as decoded
let mid = element.mid;
let mlen = element.mlen;
// now proceed to custom interpratetion
if element.meta.provider == Provider::JPL {
// grab fields that you probably need to decode
let mid = element.meta.mid;
let mlen = element.meta.mlen;
let big_endian = element.meta.big_endian;
let is_reversed = element.meta.reversed;
let enhanced_crc = element.meta.enhanced_crc;

// now, proceed to interpretation of this element,
// using undisclosed method
element.interprate(&|data| {
match mid {
// process custom mid and custom data
// using undisclosed method
_ => {},
}
});
Expand Down
14 changes: 10 additions & 4 deletions binex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ use crate::stream::Provider;
pub struct ClosedSourceMeta {
// decoded MID (as is)
pub mid: u32,
// decoded MLEN (as is)
/// decoded MLEN (as is)
pub mlen: usize,
// payload offset in buffer
pub offset: usize,
// [Provider] of this message. Only this organization may continue the decoding process.
/// Whether this item is reversed or not
pub reversed: bool,
/// Whether this item uses enhanced CRC or not
pub enhanced_crc: bool,
/// Whether this is big endian encoded or not
pub big_endian: bool,
/// [Provider] of this message. Only this organization may continue the decoding process.
pub provider: Provider,
// payload offset in buffer
offset: usize,
}

#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions binex/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ impl Message {
mlen,
provider,
offset: ptr,
big_endian,
reversed,
enhanced_crc,
mid: mid.into(),
}));
} else {
Expand Down
156 changes: 132 additions & 24 deletions binex/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! BINEX Stream representation
use crate::prelude::Message;
use crate::prelude::{ClosedSourceMeta, Message};

/// [Message] [Provider]
#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -49,17 +49,13 @@ impl Provider {
/// Closed source frame that we can encode but not interprate.
/// This particular [StreamElement] can be either a part of a continuous serie or self sustainable.
pub struct ClosedSourceElement<'a> {
/// Message ID as decoded
pub mid: u32,
/// Provider of this frame.
/// Only this organization may have capabilities to interprate this frame.
pub provider: Provider,
/// Total size of this [StreamElement] as it may be part of a continuous
/// serie of [StreamElement]s.
/// [ClosedSourceMeta]
pub meta: ClosedSourceMeta,
/// Size of this [StreamElement]: this is not
/// the size of the complete message, in case this is part
/// of a serie of [StreamElement]s.
pub size: usize,
/// Total message size (not the size of this element)
pub mlen: usize,
/// Raw data content that we can encode, decode but not interprate.
/// Raw data starting at first byte of undisclosed payload.
pub raw: &'a [u8],
}

Expand Down Expand Up @@ -103,19 +99,31 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of this [StreamElement]
/// - mlen: total message lenth
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn new_prototype(
provider: Provider,
mid: u32,
raw: &'a [u8],
size: usize,
mlen: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::ClosedSource(ClosedSourceElement {
raw,
mlen,
size,
mid,
provider,
meta: ClosedSourceMeta {
mid,
mlen,
reversed,
enhanced_crc,
big_endian,
provider,
offset: 0,
},
})
}

Expand All @@ -125,8 +133,28 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of the provided buffer (bytewise)
/// - total: total size of the closed source Message (bytewise)
pub fn jpl_prototype(raw: &'a [u8], mid: u32, size: usize, total: usize) -> Self {
Self::new_prototype(Provider::JPL, mid, raw, size, total)
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn jpl_prototype(
raw: &'a [u8],
mid: u32,
size: usize,
total: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::new_prototype(
Provider::JPL,
mid,
raw,
size,
total,
reversed,
enhanced_crc,
big_endian,
)
}

/// Add one closed source [StreamElement]s provided by desired [Provider::JPL].
Expand All @@ -135,8 +163,28 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of the provided buffer (bytewise)
/// - total: total size of the closed source Message (bytewise)
pub fn igs_prototype(raw: &'a [u8], mid: u32, size: usize, total: usize) -> Self {
Self::new_prototype(Provider::IGS, mid, raw, size, total)
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn igs_prototype(
raw: &'a [u8],
mid: u32,
size: usize,
total: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::new_prototype(
Provider::IGS,
mid,
raw,
size,
total,
reversed,
enhanced_crc,
big_endian,
)
}

/// Add one closed source [StreamElement]s provided by desired [Provider::ColoradoUnivBoulder].
Expand All @@ -145,8 +193,28 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of the provided buffer (bytewise)
/// - total: total size of the closed source Message (bytewise)
pub fn cuboulder_prototype(raw: &'a [u8], mid: u32, size: usize, total: usize) -> Self {
Self::new_prototype(Provider::ColoradoUnivBoulder, mid, raw, size, total)
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn cuboulder_prototype(
raw: &'a [u8],
mid: u32,
size: usize,
total: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::new_prototype(
Provider::ColoradoUnivBoulder,
mid,
raw,
size,
total,
reversed,
enhanced_crc,
big_endian,
)
}

/// Add one closed source [StreamElement]s provided by desired [Provider::NRCan].
Expand All @@ -155,8 +223,28 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of the provided buffer (bytewise)
/// - total: total size of the closed source Message (bytewise)
pub fn nrcan_prototype(raw: &'a [u8], mid: u32, size: usize, total: usize) -> Self {
Self::new_prototype(Provider::NRCan, mid, raw, size, total)
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn nrcan_prototype(
raw: &'a [u8],
mid: u32,
size: usize,
total: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::new_prototype(
Provider::NRCan,
mid,
raw,
size,
total,
reversed,
enhanced_crc,
big_endian,
)
}

/// Add one closed source [StreamElement]s provided by desired [Provider::UCAR].
Expand All @@ -165,7 +253,27 @@ impl<'a> StreamElement<'a> {
/// - raw: content we can encode, decode but not interprate
/// - size: size of the provided buffer (bytewise)
/// - total: total size of the closed source Message (bytewise)
pub fn ucar_prototype(raw: &'a [u8], mid: u32, size: usize, total: usize) -> Self {
Self::new_prototype(Provider::UCAR, mid, raw, size, total)
/// - reversed: whether this uses the reversed stream algorithm or not
/// - enhanced_crc: whether this uses the enhanced CRC or not
/// - big_endian: whether we'll use "big" endianess when encoding, or not.
pub fn ucar_prototype(
raw: &'a [u8],
mid: u32,
size: usize,
total: usize,
reversed: bool,
enhanced_crc: bool,
big_endian: bool,
) -> Self {
Self::new_prototype(
Provider::UCAR,
mid,
raw,
size,
total,
reversed,
enhanced_crc,
big_endian,
)
}
}

0 comments on commit cee4b66

Please sign in to comment.