mod framing;
mod reader;
mod writer;
#[cfg(test)]
mod tests;
use crate::core::core_types::Orientation;
use crate::core::graph_dto::CoreGraphDTO;
use crate::error::PanResult;
use crate::traits::{GraphParser, GraphSerializer};
use std::io::{Read, Seek, Write};
pub struct VGCodec;
impl<R: Read + Seek> GraphParser<R> for VGCodec {
fn parse(&self, reader: &mut R) -> PanResult<CoreGraphDTO> {
reader::parse_vg(reader, reader::VG_READ_WINDOW)
}
}
impl GraphSerializer for VGCodec {
fn serialize(&self, graph: &CoreGraphDTO, writer: &mut dyn Write) -> PanResult<()> {
writer::write_vg(graph, writer)
}
}
pub(super) const fn vg_edge_to_orientations(
from_start: bool,
to_end: bool,
) -> (Orientation, Orientation) {
let from_orient = if from_start {
Orientation::Reverse
} else {
Orientation::Forward
};
let to_orient = if to_end {
Orientation::Reverse
} else {
Orientation::Forward
};
(from_orient, to_orient)
}
pub(super) fn orientations_to_vg_edge(
from_orient: Orientation,
to_orient: Orientation,
) -> (bool, bool) {
let from_start = from_orient == Orientation::Reverse;
let to_end = to_orient == Orientation::Reverse;
(from_start, to_end)
}