You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-9Lines changed: 37 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,10 +21,47 @@ The main optimization in sonic-rs is the use of SIMD. However, we do not use the
21
21
22
22
More details about optimization can be found in [performance.md](docs/performance.md).
23
23
24
+
***For Golang user to use `sonic_rs`, please see [for_Golang_user_zh.md](docs/for_Golang_user.md)***
25
+
26
+
-[sonic-rs](#sonic-rs)
27
+
-[Requirements/Notes](#requirementsnotes)
28
+
-[Quick to use sonic-rs](#quick-to-use-sonic-rs)
29
+
-[Features](#features)
30
+
-[Benchmark](#benchmark)
31
+
-[Deserialize Struct](#deserialize-struct)
32
+
-[Deserialize Untyped](#deserialize-untyped)
33
+
-[Serialize Untyped](#serialize-untyped)
34
+
-[Serialize Struct](#serialize-struct)
35
+
-[Get from JSON](#get-from-json)
36
+
-[Usage](#usage)
37
+
-[Serde into Rust Type](#serde-into-rust-type)
38
+
-[Get a field from JSON](#get-a-field-from-json)
39
+
-[Parse and Serialize into untyped Value](#parse-and-serialize-into-untyped-value)
40
+
-[JSON Iterator](#json-iterator)
41
+
-[JSON RawValue & Number & RawNumber](#json-rawvalue--number--rawnumber)
42
+
-[Error handle](#error-handle)
43
+
-[FAQs](#faqs)
44
+
-[About UTF-8](#about-utf-8)
45
+
-[About floating point precision](#about-floating-point-precision)
46
+
-[Acknowledgement](#acknowledgement)
47
+
-[Contributing](#contributing)
48
+
24
49
## Requirements/Notes
25
50
26
51
1. Support x86_64 or aarch64. Note that the performance in aarch64 is lower and needs optimization.
27
52
2. Requires Rust nightly version, as we use the `packed_simd` crate.
53
+
3. please add the compile options `-C target-cpu=native`
54
+
55
+
## Quick to use sonic-rs
56
+
57
+
To ensure that SIMD instruction is used in sonic-rs, you need to add rustflags `-C target-cpu=native` and compile on the host machine. For example, Rust flags can be configured in Cargo [config](.cargo/config).
58
+
59
+
Add sonic-rs in `Cargo.toml`
60
+
61
+
```
62
+
[dependencies]
63
+
sonic-rs = 0.2
64
+
```
28
65
29
66
## Features
30
67
1. Serde into Rust struct as `serde_json` and `serde`.
@@ -39,15 +76,6 @@ More details about optimization can be found in [performance.md](docs/performanc
39
76
40
77
6. The floating parsing percision is as Rust std in default.
41
78
42
-
## Quick to use sonic-rs
43
-
44
-
To ensure that SIMD instruction is used in sonic-rs, you need to add rustflags `-C target-cpu=native` and compile on the host machine. For example, Rust flags can be configured in Cargo [config](.cargo/config).
sonic-go/encoding-json Marshal => sonic_rs::to_string/to_vec, etc.
14
+
15
+
- Parsing into Golang interface{}/any or sonic-go AST:
16
+
17
+
If it is a standalone `interface{}`, it is recommended to use `sonic_rs::Document` for better performance.
18
+
19
+
If it is an `interface{}` inside a Golang structure, it is recommended to replace `interface{}/any` with `serde_json::Value`. Note: `sonic_rs::Value` and `sonic_rs::Document` are not currently supported for embedding into Rust structures but will be supported later.
20
+
21
+
- Using gjson/jsonparser for on-demand parsing:
22
+
23
+
Regarding gjson/jsonparser get API:
24
+
25
+
The gjson/jsonparser get API itself does not perform strict JSON validation, so you can use `sonic_rs::get_unchecked` for replacement. The sonic_rs get API will return a `Result<LazyValue>`, `LazyValue` can be further ***parsed into the corresponding type** by using `as_bool, as_str`, etc. If you need to get the original raw JSON, ***without parsing***, please use `as_raw_str, as_raw_slice` API. Refer to the example: [get_from.rs](examples/get_from.rs)
26
+
27
+
Regarding jsonparser `ArrayEach` and `ObjectEach` API:
28
+
29
+
The gjson/jsonparser get API itself does not perform strict JSON validation, so you can use `sonic_rs::to_object_iter_unchecked` for replacement. Refer to the example [iterator.rs](examples/iterator.rs)
30
+
31
+
If you need to get multiple fields from JSON, it is recommended to use `get_many`. Reference example: [get_many.rs](examples/get_many.rs)
0 commit comments