Skip to content

Commit

Permalink
introduce ParsingContext
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Apr 8, 2020
1 parent 42070cd commit 205d4b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::parsing::ParsingContext;
use amq_protocol::frame::{BackToTheBuffer, GenError, GenResult, WriteContext};
use std::{
cmp,
Expand Down Expand Up @@ -135,6 +136,14 @@ impl Buffer {
}
}

pub(crate) fn parsing_context(&self) -> ParsingContext<'_> {
if self.end > self.position {
self.memory[self.position..self.end].into()
} else {
[&self.memory[self.position..], &self.memory[..self.end]].into()
}
}

pub(crate) fn data(&self) -> &[u8] {
// FIXME: drop
&self.memory[self.position..self.end]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ mod exchange;
mod frames;
mod id_sequence;
mod io_loop;
mod parsing;
mod promises;
mod queue;
mod queues;
Expand Down
17 changes: 17 additions & 0 deletions src/parsing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub(crate) struct ParsingContext<'a> {
buffers: [&'a [u8]; 2],
}

impl<'a> From<&'a [u8]> for ParsingContext<'a> {
fn from(buffer: &'a [u8]) -> Self {
Self {
buffers: [buffer, &buffer[..0]],
}
}
}

impl<'a> From<[&'a [u8]; 2]> for ParsingContext<'a> {
fn from(buffers: [&'a [u8]; 2]) -> Self {
Self { buffers }
}
}

0 comments on commit 205d4b7

Please sign in to comment.