aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/format/binary.rs4
-rw-r--r--src/format/energymech.rs15
-rw-r--r--src/format/mod.rs47
-rw-r--r--src/format/msgpack.rs3
-rw-r--r--src/format/weechat3.rs15
-rw-r--r--src/lib.rs7
-rw-r--r--src/main.rs32
7 files changed, 60 insertions, 63 deletions
diff --git a/src/format/binary.rs b/src/format/binary.rs
index a1ca12d..367cdf9 100644
--- a/src/format/binary.rs
+++ b/src/format/binary.rs
@@ -32,14 +32,14 @@ pub struct Iter<'a, R: 'a> where R: BufRead {
impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
type Item = ::Result<Event<'a>>;
fn next(&mut self) -> Option<::Result<Event<'a>>> {
- Some(bincode::decode_from::<R, Event>(&mut self.input, SizeLimit::Infinite)
+ Some(bincode::rustc_serialize::decode_from::<R, Event>(&mut self.input, SizeLimit::Infinite)
.map_err(|_| ::IlcError::BincodeDecode))
}
}
impl<'a, W> Encode<'a, W> for Binary where W: Write {
fn encode(&'a self, _context: &'a Context, mut output: W, event: &'a Event) -> ::Result<()> {
- bincode::encode_into(event, &mut output, SizeLimit::Infinite)
+ bincode::rustc_serialize::encode_into(event, &mut output, SizeLimit::Infinite)
.map_err(|_| ::IlcError::BincodeEncode)
}
}
diff --git a/src/format/energymech.rs b/src/format/energymech.rs
index df48318..5965dfa 100644
--- a/src/format/energymech.rs
+++ b/src/format/energymech.rs
@@ -28,13 +28,13 @@ pub struct Energymech;
static TIME_FORMAT: &'static str = "%H:%M:%S";
-pub struct Iter<'a, R: 'a> where R: BufRead {
+pub struct Iter<'a> {
context: &'a Context,
- input: R,
+ input: &'a mut BufRead,
buffer: Vec<u8>
}
-impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
+impl<'a> Iterator for Iter<'a> {
type Item = ::Result<Event<'a>>;
fn next(&mut self) -> Option<::Result<Event<'a>>> {
fn parse_time(context: &Context, time: &str) -> Time {
@@ -153,14 +153,13 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
}
}
-impl<'a, R: 'a> Decode<'a, R> for Energymech where R: BufRead {
- type Output = Iter<'a, R>;
- fn decode(&'a mut self, context: &'a Context, input: R) -> Iter<R> {
- Iter {
+impl<'a> Decode<'a> for Energymech {
+ fn decode(&'a mut self, context: &'a Context, input: &'a mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a> {
+ Box::new(Iter {
context: context,
input: input,
buffer: Vec::new()
- }
+ })
}
}
diff --git a/src/format/mod.rs b/src/format/mod.rs
index f918287..4f8eaa1 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -16,55 +16,50 @@
//! As the source format may not provide the same information as the
//! target format, all formats must allow for omittable information.
+use std::iter;
use std::io::{ BufRead, Write };
use std::borrow::Cow;
use event::Event;
use context::Context;
-pub mod weechat3;
-pub mod energymech;
-pub mod binary;
-pub mod msgpack;
+//pub mod weechat3;
+//pub mod energymech;
+//pub mod binary;
+//pub mod msgpack;
pub trait Encode<'a, W> where W: Write {
fn encode(&'a self, context: &'a Context, output: W, event: &'a Event) -> ::Result<()>;
}
-pub trait Decode<'a, Input> where Input: BufRead,
- Self::Output: Iterator<Item = ::Result<Event<'a>>> + 'a {
- type Output;
- fn decode(&'a mut self, context: &'a Context, input: Input) -> Self::Output;
+pub trait Decode<'a, 'b, 'c> {
+ fn decode(&'a mut self, context: &'b Context, input: &'c mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a>;
}
-pub trait DecodeBox<'a, I> {
- fn decode_box(&'a mut self, context: &'a Context, input: I)
- -> Box<Iterator<Item = ::Result<Event>> + 'a>;
-}
+pub struct Dummy;
-impl<'a, T, I: BufRead> DecodeBox<'a, I> for T where T: Decode<'a, I> {
- fn decode_box(&'a mut self, context: &'a Context, input: I)
- -> Box<Iterator<Item = ::Result<Event>> + 'a> {
- Box::new(self.decode(context, input))
+impl <'a, 'b, 'c> Decode<'a, 'b, 'c> for Dummy {
+ fn decode(&'a mut self, _context: &'b Context, _input: &'c mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a> {
+ Box::new(iter::empty())
}
}
-pub fn decoder<'a>(format: &str) -> Option<Box<DecodeBox<'a, &'a mut BufRead>>> {
+pub fn decoder<'a, 'b, 'c>(format: &str) -> Option<Box<Decode<'a, 'b, 'c>>> {
match format {
- "energymech" => Some(Box::new(energymech::Energymech)),
- "weechat3" => Some(Box::new(weechat3::Weechat3)),
- "binary" => Some(Box::new(binary::Binary)),
- "msgpack" => Some(Box::new(msgpack::Msgpack)),
+// "energymech" => Some(Box::new(energymech::Energymech)),
+// "weechat3" => Some(Box::new(weechat3::Weechat3)),
+// "binary" => Some(Box::new(binary::Binary)),
+// "msgpack" => Some(Box::new(msgpack::Msgpack)),
_ => None
}
}
-pub fn encoder<'a>(format: &str) -> Option<Box<Encode<'a, &'a mut Write>>> {
+pub fn encoder<'a, 'b: 'a>(format: &str) -> Option<Box<Encode<'a, &'b mut Write>>> {
match format {
- "energymech" => Some(Box::new(energymech::Energymech)),
- "weechat3" => Some(Box::new(weechat3::Weechat3)),
- "binary" => Some(Box::new(binary::Binary)),
- "msgpack" => Some(Box::new(msgpack::Msgpack)),
+// "energymech" => Some(Box::new(energymech::Energymech)),
+// "weechat3" => Some(Box::new(weechat3::Weechat3)),
+// "binary" => Some(Box::new(binary::Binary)),
+// "msgpack" => Some(Box::new(msgpack::Msgpack)),
_ => None
}
}
diff --git a/src/format/msgpack.rs b/src/format/msgpack.rs
index 09bd2bb..fb71b99 100644
--- a/src/format/msgpack.rs
+++ b/src/format/msgpack.rs
@@ -22,6 +22,7 @@ use format::{ Encode, Decode };
use rustc_serialize::{ Encodable, Decodable };
use msgpack::{ Encoder, Decoder };
+use rmp::decode::ReadError;
pub struct Msgpack;
@@ -36,7 +37,7 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
use msgpack::decode;
match Event::decode(&mut Decoder::new(&mut self.input)) {
Ok(e) => Some(Ok(e)),
- Err(decode::serialize::Error::InvalidMarkerRead(decode::ReadError::UnexpectedEOF)) => None,
+ Err(decode::Error::InvalidMarkerRead(ReadError::UnexpectedEOF)) => None,
Err(e) => Some(Err(::IlcError::MsgpackDecode(e)))
}
}
diff --git a/src/format/weechat3.rs b/src/format/weechat3.rs
index e733a38..118bd3b 100644
--- a/src/format/weechat3.rs
+++ b/src/format/weechat3.rs
@@ -26,13 +26,13 @@ pub struct Weechat3;
static TIME_DATE_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";
-pub struct Iter<'a, R: 'a> where R: BufRead {
+pub struct Iter<'a> {
context: &'a Context,
- input: R,
+ input: &'a mut BufRead,
buffer: Vec<u8>
}
-impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
+impl<'a> Iterator for Iter<'a> {
type Item = ::Result<Event<'a>>;
fn next(&mut self) -> Option<::Result<Event<'a>>> {
fn parse_time(c: &Context, date: &str, time: &str) -> Time {
@@ -139,14 +139,13 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
}
}
-impl<'a, I: 'a> Decode<'a, I> for Weechat3 where I: BufRead {
- type Output = Iter<'a, I>;
- fn decode(&'a mut self, context: &'a Context, input: I) -> Iter<'a, I> {
- Iter {
+impl<'a> Decode<'a> for Weechat3 {
+ fn decode(&'a mut self, context: &'a Context, input: &'a mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a> {
+ Box::new(Iter {
context: context,
input: input,
buffer: Vec::new()
- }
+ })
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 422ca07..015af7d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,7 +20,8 @@ extern crate chrono;
extern crate log as l;
extern crate rustc_serialize;
extern crate bincode;
-extern crate rmp as msgpack;
+extern crate rmp;
+extern crate rmp_serialize as msgpack;
pub mod event;
pub mod format;
@@ -41,8 +42,8 @@ pub enum IlcError {
Chrono(ParseError),
BincodeDecode,
BincodeEncode,
- MsgpackEncode(msgpack::encode::serialize::Error),
- MsgpackDecode(msgpack::decode::serialize::Error),
+ MsgpackEncode(msgpack::encode::Error),
+ MsgpackDecode(msgpack::decode::Error),
Io(io::Error)
}
diff --git a/src/main.rs b/src/main.rs
index 9ed0646..285995c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -42,7 +42,7 @@ use chrono::naive::date::NaiveDate;
use glob::glob;
use ilc::context::Context;
-use ilc::format::{ self, Encode, Decode, DecodeBox };
+use ilc::format::{ self, Encode, Decode };
use ilc::event::{ Event, Type, NoTimeHash };
use ageset::AgeSet;
@@ -116,7 +116,7 @@ fn die(s: &str) -> ! {
process::exit(1)
}
-fn force_decoder<'a>(s: Option<String>) -> Box<DecodeBox<'a, &'a mut BufRead>> {
+fn force_decoder<'a, 'b, 'c>(s: Option<String>) -> Box<Decode<'a, 'b, 'c>> {
let inf = match s {
Some(s) => s,
None => die("You didn't specify the input format")
@@ -127,7 +127,7 @@ fn force_decoder<'a>(s: Option<String>) -> Box<DecodeBox<'a, &'a mut BufRead>> {
}
}
-fn force_encoder<'a>(s: Option<String>) -> Box<Encode<'a, &'a mut Write>> {
+fn force_encoder<'a, 'b: 'a>(s: Option<String>) -> Box<Encode<'a, &'b mut Write>> {
let outf = match s {
Some(s) => s,
None => die("You didn't specify the output format")
@@ -167,23 +167,25 @@ fn main() {
Box::new(BufReader::new(io::stdin()))
};
- let mut output: Box<Write> = if let Some(out) = args.flag_out {
+ /*let mut output: Box<Write> = if let Some(out) = args.flag_out {
match File::create(out) {
Ok(f) => Box::new(BufWriter::new(f)),
Err(e) => error(Box::new(e))
}
} else {
Box::new(BufWriter::new(io::stdout()))
- };
-
- if args.cmd_parse {
- let mut decoder = force_decoder(args.flag_inf);
- let encoder = force_encoder(args.flag_outf);
- for e in decoder.decode_box(&context, &mut input) {
- info!("Parsed: {:?}", e);
- let _ = encoder.encode(&context, &mut output, &e.unwrap());
- }
- } else if args.cmd_convert {
+ };*/
+
+ //if args.cmd_parse {
+ let mut i = io::empty();
+ let mut decoder: Box<Decode> = Box::new(format::Dummy);//force_decoder(args.flag_inf);
+ // let encoder = force_encoder(args.flag_outf);
+ let iter = decoder.decode(&context, &mut i);
+ //for e in decoder.decode_box(&context, &mut input) {
+ //let e = e.unwrap();
+ //let _ = encoder.encode(&context, &mut output, &e);
+ //}
+ /*}*/ /*else if args.cmd_convert {
let mut decoder = force_decoder(args.flag_inf);
let encoder = force_encoder(args.flag_outf);
for e in decoder.decode_box(&context, &mut input) {
@@ -274,5 +276,5 @@ fn main() {
}
}
}
- }
+ }*/
}