forked from squidpickles/ais
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6545e09
commit d60c16c
Showing
28 changed files
with
187 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
use ais::lib; | ||
use ais::sentence::{AisFragments, AisParser, AisSentence}; | ||
use lib::std::io::{self, BufRead}; | ||
use serde_json; | ||
|
||
use ais::sentence::{AisFragments, AisParser}; | ||
use lib::std::io::BufRead; | ||
|
||
use lib::std::io; | ||
|
||
fn parse_nmea_line(parser: &mut AisParser, line: &[u8]) -> Result<(), ais::errors::Error> { | ||
fn parse_nmea_line_to_json(parser: &mut AisParser, line: &[u8]) -> Result<(), ais::errors::Error> { | ||
let sentence = parser.parse(line, true)?; | ||
if let AisFragments::Complete(sentence) = sentence { | ||
println!( | ||
"{:?}\t{:?}", | ||
lib::std::str::from_utf8(line).unwrap(), | ||
sentence.message | ||
); | ||
match serialize_to_json(&sentence) { | ||
Ok(json) => println!("{}", json), | ||
Err(err) => eprintln!("Error serializing to JSON: {}", err), | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn serialize_to_json(sentence: &AisSentence) -> serde_json::Result<String> { | ||
serde_json::to_string(sentence) | ||
} | ||
|
||
pub fn deserialize_from_json(json_data: &str) -> serde_json::Result<AisSentence> { | ||
serde_json::from_str(json_data) | ||
} | ||
|
||
fn main() { | ||
let mut parser = AisParser::new(); | ||
let stdin = io::stdin(); | ||
{ | ||
let handle = stdin.lock(); | ||
let handle = stdin.lock(); | ||
|
||
handle | ||
.split(b'\n') | ||
.map(|line| line.unwrap()) | ||
.for_each(|line| { | ||
parse_nmea_line(&mut parser, &line).unwrap_or_else(|err| { | ||
eprintln!("{:?}\t{:?}", lib::std::str::from_utf8(&line).unwrap(), err); | ||
}); | ||
handle | ||
.split(b'\n') | ||
.map(|line| line.unwrap()) | ||
.for_each(|line| { | ||
parse_nmea_line_to_json(&mut parser, &line).unwrap_or_else(|err| { | ||
eprintln!( | ||
"Error parsing line: {:?}\t{:?}", | ||
lib::std::str::from_utf8(&line).unwrap(), | ||
err | ||
); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.