Skip to content

Commit

Permalink
Merge branch 'databendlabs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw authored Oct 29, 2024
2 parents e15e7c9 + ada713c commit fe81859
Show file tree
Hide file tree
Showing 13 changed files with 1,123 additions and 113 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [v0.4.3] - 2024-09-30

### Fixed
Fix: Fix compare object value with different length panic (#59)

## [v0.4.2] - 2024-09-19

### Added
Feat: make `preserve_order` a default feature (#56)

## [v0.4.1] - 2024-07-18

### Fixed
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ keywords = ["json", "jsonb", "jsonpath"]
license = "Apache-2.0"
name = "jsonb"
repository = "https://github.com/datafuselabs/jsonb"
version = "0.4.1"
version = "0.4.3"
rust-version = "1.77"

[dependencies]
Expand All @@ -33,9 +33,7 @@ nom = "7.1.3"
ordered-float = { version = "4.2", default-features = false }
rand = { version = "0.8.5", features = ["small_rng"] }
ryu = "1.0"
serde_json = { version = "1.0", default-features = false, features = [
"preserve_order",
] }
serde_json = { version = "1.0", default-features = false, features = ["std"] }

[dev-dependencies]
goldenfile = "1.7"
Expand All @@ -45,6 +43,9 @@ simd-json = "0.13.10"
mockalloc = "0.1.2"
criterion = "0.5.1"

[features]
default = ["serde_json/preserve_order"]

[[bench]]
name = "parser"
harness = false
Expand Down
26 changes: 13 additions & 13 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ use super::value::Value;
/// `Number`, `String` and `Container`. They have three different decode methods.
/// 1. `Null`, `True` and `False` can be obtained by `JEntry`, no extra work required.
/// 2. `Number` and `String` has related `RawData`, `JEntry` store the length
/// or offset of this data, the `Value` can be read out and then decoded.
/// or offset of this data, the `Value` can be read out and then decoded.
/// 3. `Container` is actually a nested `Array` or `Object` with the same structure,
/// `JEntry` store the length or offset of the lower-level `Header`,
/// from where the same decode process can begin.
/// `RawData` is the encoded `Value`.
/// `Number` is a variable-length `Decimal`, store both int and float value.
/// `String` is the original string, can be borrowed directly without extra decode.
/// `Array` and `Object` is a lower-level encoded `JSONB` value.
/// The upper-level doesn't care about the specific content.
/// Decode can be executed recursively.
/// Decode `JSONB` Value from binary bytes.
/// `JEntry` store the length or offset of the lower-level `Header`,
/// from where the same decode process can begin.
///
/// `RawData` is the encoded `Value`.
/// `Number` is a variable-length `Decimal`, store both int and float value.
/// `String` is the original string, can be borrowed directly without extra decode.
/// `Array` and `Object` is a lower-level encoded `JSONB` value.
/// The upper-level doesn't care about the specific content.
/// Decode can be executed recursively.
///
/// Decode `JSONB` Value from binary bytes.
pub fn from_slice(buf: &[u8]) -> Result<Value<'_>, Error> {
let mut decoder = Decoder::new(buf);
match decoder.decode() {
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a> Decoder<'a> {
}
NUMBER_TAG => {
let offset = jentry.length as usize;
let n = Number::decode(&self.buf[..offset]);
let n = Number::decode(&self.buf[..offset])?;
self.buf = &self.buf[offset..];
Ok(Value::Number(n))
}
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ pub enum Error {
InvalidJsonb,
InvalidJsonbHeader,
InvalidJsonbJEntry,
InvalidJsonbNumber,

InvalidJsonPath,
InvalidJsonPathPredicate,
InvalidKeyPath,

InvalidJsonType,
InvalidObject,
ObjectDuplicateKey,

Syntax(ParseErrorCode, usize),
}
Expand Down
Loading

0 comments on commit fe81859

Please sign in to comment.