Skip to content

Commit 0254376

Browse files
committed
Do some rename for a cleaner API
Aligns with the naming of Oxigraph parsers and serializers
1 parent ed31c7f commit 0254376

File tree

8 files changed

+240
-168
lines changed

8 files changed

+240
-168
lines changed

README.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
1-
JSON streaming parser
2-
=================
1+
JSON streaming parser and serializer
2+
====================================
33

44
[![actions status](https://github.com/oxigraph/json-event-parser/workflows/build/badge.svg)](https://github.com/oxigraph/json-event-parser/actions)
55
[![Latest Version](https://img.shields.io/crates/v/json-event-parser.svg)](https://crates.io/crates/json-event-parser)
66
[![Released API docs](https://docs.rs/json-event-parser/badge.svg)](https://docs.rs/json-event-parser)
77

88
JSON event parser is a simple streaming JSON parser and serializer implementation in Rust.
99

10-
It does not aims to be the fastest JSON parser possible but to be a simple implementation.
10+
It does not aims to be the fastest JSON parser possible but to be a simple implementation allowing to parse larger than
11+
memory files.
1112

12-
If you want fast and battle-tested code you might prefer to use [json](https://crates.io/crates/json), [serde_json](https://crates.io/crates/serde_json) or [simd-json](https://crates.io/crates/simd-json).
13+
If you want fast and battle-tested code you might prefer to
14+
use [json](https://crates.io/crates/json), [serde_json](https://crates.io/crates/serde_json)
15+
or [simd-json](https://crates.io/crates/simd-json).
1316

14-
Reader example:
17+
Parser example:
1518

1619
```rust
17-
use json_event_parser::{FromReadJsonReader, JsonEvent};
20+
use json_event_parser::{ReaderJsonParser, JsonEvent};
1821

1922
let json = b"{\"foo\": 1}";
20-
let mut reader = FromReadJsonReader::new(json.as_slice());
21-
assert_eq!(reader.read_next_event()?, JsonEvent::StartObject);
22-
assert_eq!(reader.read_next_event()?, JsonEvent::ObjectKey("foo".into()));
23-
assert_eq!(reader.read_next_event()?, JsonEvent::Number("1".into()));
24-
assert_eq!(reader.read_next_event()?, JsonEvent::EndObject);
25-
assert_eq!(reader.read_next_event()?, JsonEvent::Eof);
23+
let mut reader = ReaderJsonParser::new(json.as_slice());
24+
assert_eq!(reader.parse_next()?, JsonEvent::StartObject);
25+
assert_eq!(reader.parse_next()?, JsonEvent::ObjectKey("foo".into()));
26+
assert_eq!(reader.parse_next()?, JsonEvent::Number("1".into()));
27+
assert_eq!(reader.parse_next()?, JsonEvent::EndObject);
28+
assert_eq!(reader.parse_next()?, JsonEvent::Eof);
2629
# std::io::Result::Ok(())
2730
```
2831

29-
Writer example:
32+
Serializer example:
3033

3134
```rust
32-
use json_event_parser::{ToWriteJsonWriter, JsonEvent};
35+
use json_event_parser::{WriterJsonSerializer, JsonEvent};
3336

34-
let mut writer = ToWriteJsonWriter::new(Vec::new());
35-
writer.write_event(JsonEvent::StartObject)?;
36-
writer.write_event(JsonEvent::ObjectKey("foo".into()))?;
37-
writer.write_event(JsonEvent::Number("1".into()))?;
38-
writer.write_event(JsonEvent::EndObject)?;
37+
let mut writer = WriterJsonSerializer::new(Vec::new());
38+
writer.write_event(JsonEvent::StartObject) ?;
39+
writer.write_event(JsonEvent::ObjectKey("foo".into())) ?;
40+
writer.write_event(JsonEvent::Number("1".into())) ?;
41+
writer.write_event(JsonEvent::EndObject) ?;
3942

4043
assert_eq!(writer.finish()?.as_slice(), b"{\"foo\":1}");
4144
# std::io::Result::Ok(())
4245
```
4346

44-
4547
## License
4648

4749
This project is licensed under either of
4850

49-
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
50-
`<http://www.apache.org/licenses/LICENSE-2.0>`)
51-
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
52-
`<http://opensource.org/licenses/MIT>`)
53-
54-
at your option.
51+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
52+
`<http://www.apache.org/licenses/LICENSE-2.0>`)
53+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
54+
`<http://opensource.org/licenses/MIT>`)
5555

56+
at your option.
5657

5758
### Contribution
5859

59-
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in json-event-parser by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
60+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in json-event-parser by
61+
you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

benches/parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
2-
use json_event_parser::{FromReadJsonReader, JsonEvent};
2+
use json_event_parser::{JsonEvent, ReaderJsonParser};
33
use std::fs::{self, read_dir};
44

55
fn bench_parse_json_benchmark(c: &mut Criterion) {
@@ -11,9 +11,9 @@ fn bench_parse_json_benchmark(c: &mut Criterion) {
1111
.unwrap();
1212
c.bench_function(dataset, |b| {
1313
b.iter(|| {
14-
let mut reader = FromReadJsonReader::new(data.as_slice());
15-
while reader.read_next_event().unwrap() != JsonEvent::Eof {
16-
//read more
14+
let mut reader = ReaderJsonParser::new(data.as_slice());
15+
while reader.parse_next().unwrap() != JsonEvent::Eof {
16+
// read more
1717
}
1818
})
1919
});
@@ -25,9 +25,9 @@ fn bench_parse_testsuite(c: &mut Criterion) {
2525

2626
c.bench_function("JSON test suite", |b| {
2727
b.iter(|| {
28-
let mut reader = FromReadJsonReader::new(example.as_slice());
29-
while reader.read_next_event().unwrap() != JsonEvent::Eof {
30-
//read more
28+
let mut reader = ReaderJsonParser::new(example.as_slice());
29+
while reader.parse_next().unwrap() != JsonEvent::Eof {
30+
// read more
3131
}
3232
})
3333
});

fuzz/fuzz_targets/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn parse_chunks(chunks: &[&[u8]]) -> (String, Option<SyntaxError>) {
1818
let LowLevelJsonReaderResult {
1919
event,
2020
consumed_bytes,
21-
} = reader.read_next_event(&input_buffer[input_cursor..], i == chunks.len() - 1);
21+
} = reader.parse_next(&input_buffer[input_cursor..], i == chunks.len() - 1);
2222
input_cursor += consumed_bytes;
2323
match event {
2424
Some(Ok(JsonEvent::Eof)) => {

src/lib.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ mod read;
1515
mod write;
1616

1717
#[cfg(feature = "async-tokio")]
18-
pub use crate::read::FromTokioAsyncReadJsonReader;
18+
pub use crate::read::TokioAsyncReaderJsonParser;
1919
pub use crate::read::{
20-
FromBufferJsonReader, FromReadJsonReader, LowLevelJsonReader, LowLevelJsonReaderResult,
21-
ParseError, SyntaxError, TextPosition,
20+
JsonParseError, JsonSyntaxError, LowLevelJsonParser, LowLevelJsonParserResult,
21+
ReaderJsonParser, SliceJsonParser, TextPosition,
2222
};
2323
#[cfg(feature = "async-tokio")]
24-
pub use crate::write::ToTokioAsyncWriteJsonWriter;
25-
pub use crate::write::{LowLevelJsonWriter, ToWriteJsonWriter};
24+
pub use crate::write::TokioAsyncWriterJsonSerializer;
25+
pub use crate::write::{LowLevelJsonSerializer, WriterJsonSerializer};
2626
use std::borrow::Cow;
2727

2828
/// Possible events during JSON parsing.
@@ -39,3 +39,26 @@ pub enum JsonEvent<'a> {
3939
ObjectKey(Cow<'a, str>),
4040
Eof,
4141
}
42+
43+
#[cfg(feature = "async-tokio")]
44+
#[deprecated(note = "Use TokioAsyncReaderJsonParser")]
45+
pub type FromTokioAsyncReadJsonReader<R> = TokioAsyncReaderJsonParser<R>;
46+
#[deprecated(note = "Use SliceJsonParser")]
47+
pub type FromBufferJsonReader<'a> = SliceJsonParser<'a>;
48+
#[deprecated(note = "Use ReaderJsonParser")]
49+
pub type FromReadJsonReader<R> = ReaderJsonParser<R>;
50+
#[deprecated(note = "Use LowLevelJsonParser")]
51+
pub type LowLevelJsonReader = LowLevelJsonParser;
52+
#[deprecated(note = "Use LowLevelJsonParserResult")]
53+
pub type LowLevelJsonReaderResult<'a> = LowLevelJsonParserResult<'a>;
54+
#[deprecated(note = "Use JsonParseError")]
55+
pub type ParseError = JsonParseError;
56+
#[deprecated(note = "Use JsonSyntaxError")]
57+
pub type SyntaxError = JsonSyntaxError;
58+
#[cfg(feature = "async-tokio")]
59+
#[deprecated(note = "Use TokioAsyncWriterJsonSerializer")]
60+
pub type ToTokioAsyncWriteJsonWriter<W> = TokioAsyncWriterJsonSerializer<W>;
61+
#[deprecated(note = "Use WriterJsonSerializer")]
62+
pub type ToWriteJsonWriter<W> = WriterJsonSerializer<W>;
63+
#[deprecated(note = "Use LowLevelJsonSerializer")]
64+
pub type LowLevelJsonWriter = LowLevelJsonSerializer;

0 commit comments

Comments
 (0)