Skip to content

Commit

Permalink
moved traits for Stream in main copper.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbin committed May 29, 2024
1 parent 918c065 commit 45fc647
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions copper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ uom = { version = "0.36.0", features = ["rational"] }
ron = "0.8.1"
copper-log = { path = "../copper_log" }
copper-log-runtime = { path = "../copper_log_runtime" }
bincode = "2.0.0-rc.3"



6 changes: 6 additions & 0 deletions copper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod cutask;
pub mod monitoring;
pub mod serde;

use bincode::Encode;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};

Expand Down Expand Up @@ -55,3 +56,8 @@ impl CuError {
}

pub type CuResult<T> = Result<T, CuError>;

/// Defines a basic write, append only stream trait to be able to log or send serializable objects.
pub trait Stream {
fn log(&mut self, obj: &impl Encode);
}
1 change: 1 addition & 0 deletions copper_datalogger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bincode = { version = "2.0.0-rc.3", features = ["serde", "bincode_derive"] }
bincode_derive = { version = "2.0.0-rc.3" }
memmap2 = "0.9.4"
libc = "0.2.155"
copper = { path = "../copper" }

[dev-dependencies]
tempfile = "3.2.0"
Expand Down
27 changes: 13 additions & 14 deletions copper_datalogger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use libc;

use std::fs::{File, OpenOptions};
use std::io;
use std::io::Read;
use std::io::{BufReader, Seek};
use std::path::Path;
use std::slice::from_raw_parts_mut;
use std::sync::{Arc, Mutex};

use memmap2::{MmapMut, RemapOptions};

use bincode::config::standard;
use bincode::de::read::Reader;
use bincode::encode_into_slice;
use bincode::error::EncodeError;
use bincode::Encode;
use bincode::{decode_from_reader, decode_from_slice};
use bincode_derive::Decode as dDecode;
use bincode_derive::Encode as dEncode;

use bincode::config::{standard, Configuration};
use bincode::de::read::Reader;
use memmap2::{MmapMut, RemapOptions};
use std::fs::{File, OpenOptions};
use std::io;
use std::io::{BufReader, Seek};
use std::io::{Read, SeekFrom};
use std::path::Path;
use std::slice::from_raw_parts_mut;
use std::sync::{Arc, Mutex};
use copper::Stream;

const MAIN_MAGIC: [u8; 4] = [0xB4, 0xA5, 0x50, 0xFF];

Expand All @@ -41,10 +44,6 @@ struct SectionHeader {
section_size: u32, // offset of section_magic + section_size -> should be the index of the next section_magic
}

pub trait Stream {
fn log(&mut self, obj: &impl Encode);
}

struct MmapStream {
entry_type: EntryType,
parent_logger: Arc<Mutex<DataLogger>>,
Expand Down

0 comments on commit 45fc647

Please sign in to comment.