Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
478a085ffe |
13 changed files with 155 additions and 219 deletions
109
.github/workflows/ci.yml
vendored
Normal file
109
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,109 @@
|
|||
name: Simple build & test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: ${{ matrix.make.name }} (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
rust: [stable, nightly]
|
||||
task:
|
||||
- name: Clippy
|
||||
cmd: "cargo clippy -D warnings"
|
||||
- name: Test
|
||||
cmd: "cargo test"
|
||||
- name: Format
|
||||
cmd: "cargo fmt --all --check"
|
||||
- name: Build
|
||||
cmd: "cargo build --frozen --release"
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
sccache-path: /home/runner/.cache/sccache
|
||||
- os: macos-latest
|
||||
sccache-path: /Users/runner/Library/Caches/Mozilla.sccache
|
||||
exclude:
|
||||
- os: macos-latest
|
||||
rust: stable
|
||||
task:
|
||||
name: Clippy
|
||||
- os: macos-latest
|
||||
rust: nightly
|
||||
task:
|
||||
name: Clippy
|
||||
- os: macos-latest
|
||||
rust: stable
|
||||
task:
|
||||
name: Format
|
||||
- os: macos-latest
|
||||
rust: nightly
|
||||
task:
|
||||
name: Format
|
||||
env:
|
||||
RUST_BACKTRACE: full
|
||||
RUSTC_WRAPPER: sccache
|
||||
RUSTV: ${{ matrix.rust }}
|
||||
SCCACHE_CACHE_SIZE: 2G
|
||||
SCCACHE_DIR: ${{ matrix.sccache-path }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install sccache (ubuntu-latest)
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
env:
|
||||
LINK: https://github.com/mozilla/sccache/releases/download
|
||||
SCCACHE_VERSION: 0.2.13
|
||||
run: |
|
||||
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
|
||||
mkdir -p $HOME/.local/bin
|
||||
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
|
||||
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
|
||||
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||
- name: Install sccache (macos-latest)
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: |
|
||||
brew update
|
||||
brew install sccache
|
||||
- name: Install Rust ${{ matrix.rust }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
- name: Save sccache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ matrix.sccache-path }}
|
||||
key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-sccache-
|
||||
- name: Start sccache server
|
||||
run: sccache --start-server
|
||||
- name: Install rustfmt
|
||||
if: matrix.task.name == 'Format'
|
||||
run: rustup component add rustfmt
|
||||
- name: ${{ matrix.task.name }}
|
||||
run: ${{ matrix.task.cmd }}
|
||||
- name: Print sccache stats
|
||||
run: sccache --show-stats
|
||||
- name: Stop sccache server
|
||||
run: sccache --stop-server
|
||||
continue-on-error: true
|
|
@ -1,69 +1,65 @@
|
|||
# Changelog
|
||||
= Changelog
|
||||
:toc:
|
||||
:toclevels: 1
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
|
||||
<!-- next-header -->
|
||||
== [Unreleased]
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
== [v1.1.0] - 2024-03-21
|
||||
|
||||
## [1.2.0] - 2024-03-21
|
||||
|
||||
### Added
|
||||
|
||||
- publishing to [crates.io](https://crates.io)
|
||||
|
||||
## [v1.1.0] - 2024-03-21
|
||||
|
||||
### Added
|
||||
=== Added
|
||||
|
||||
- implement serializing into generic `io::Write`
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- fix parsing CRLF
|
||||
|
||||
## [v1.0.0] - 2023-03-10
|
||||
== [v1.0.0] - 2023-03-10
|
||||
|
||||
### Added
|
||||
=== Added
|
||||
|
||||
- implement literal strings
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- fix serializing strings containing `:`
|
||||
- fix serializing certain escaped characters
|
||||
|
||||
## [v0.2.4] - 2023-03-01
|
||||
== [v0.2.4] - 2023-03-01
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- fix incorrect parsing of unquoted strings
|
||||
|
||||
## [v0.2.3] - 2023-02-24
|
||||
== [v0.2.3] - 2023-02-24
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- support backslashes in delimited strings
|
||||
|
||||
## [v0.2.2] - 2023-02-18
|
||||
== [v0.2.2] - 2023-02-18
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- fix deserialization failing on arrays and objects in some cases
|
||||
|
||||
## [v0.2.1] - 2022-12-28
|
||||
== [v0.2.1] - 2022-12-28
|
||||
|
||||
### Fixed
|
||||
=== Fixed
|
||||
|
||||
- fix serializing Unicode
|
||||
|
||||
## [v0.2.0] - 2022-11-25
|
||||
== [v0.2.0] - 2022-11-25
|
||||
|
||||
### Added
|
||||
=== Added
|
||||
|
||||
* parsing & deserialization
|
||||
|
||||
## [v0.1.0] - 2022-11-18
|
||||
== [v0.1.0] - 2022-11-18
|
||||
|
||||
### Added
|
||||
=== Added
|
||||
|
||||
* initial release
|
||||
* serialization
|
26
Cargo.toml
26
Cargo.toml
|
@ -1,27 +1,15 @@
|
|||
[package]
|
||||
name = "serde_sjson"
|
||||
version = "1.2.0"
|
||||
authors = ["Lucas Schwiderski"]
|
||||
categories = ["encoding", "parser-implementations"]
|
||||
description = "An SJSON serialization file format"
|
||||
documentation = "https://docs.rs/serde_sjson"
|
||||
version = "1.1.0"
|
||||
edition = "2021"
|
||||
keywords = ["serde", "serialization", "sjson"]
|
||||
license-file = "LICENSE"
|
||||
repository = "https://github.com/sclu1034/serde_sjson"
|
||||
exclude = [
|
||||
".github/",
|
||||
".ci/",
|
||||
"Justfile"
|
||||
]
|
||||
description = "An SJSON serialization file format"
|
||||
categories = ["encoding", "parser-implementations"]
|
||||
|
||||
[dependencies]
|
||||
nom = "7"
|
||||
nom_locate = "4.1"
|
||||
serde = { version = "1.0", default-features = false }
|
||||
nom = "7.1.3"
|
||||
nom_locate = "4.1.0"
|
||||
serde = { version = "1.0.154", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0.194", features = ["derive"] }
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "passively-maintained" }
|
||||
serde = { version = "1.0.154", features = ["derive"] }
|
||||
|
|
14
Justfile
14
Justfile
|
@ -1,26 +1,12 @@
|
|||
project := "serde_sjson"
|
||||
default := "run"
|
||||
|
||||
build *ARGS:
|
||||
cargo build {{ARGS}}
|
||||
cargo readme > README.md
|
||||
|
||||
run *ARGS:
|
||||
cargo run -- {{ARGS}}
|
||||
|
||||
test *ARGS:
|
||||
cargo test {{ARGS}}
|
||||
|
||||
doc:
|
||||
cargo doc --no-deps
|
||||
cargo readme > README.md
|
||||
|
||||
serve-doc port='8000': doc
|
||||
python3 -m http.server {{port}} --directory target/doc
|
||||
|
||||
release version execute='':
|
||||
cargo release --sign --allow-branch master {{ if execute != "" { '-x' } else { '' } }} {{version}}
|
||||
|
||||
coverage *ARGS:
|
||||
RUSTFLAGS="-C instrument-coverage" cargo test --tests {{ARGS}} || true
|
||||
cargo profdata -- merge -sparse default*.profraw -o {{project}}.profdata
|
||||
|
|
13
README.adoc
Normal file
13
README.adoc
Normal file
|
@ -0,0 +1,13 @@
|
|||
= Serde SJSON
|
||||
:idprefix:
|
||||
:idseparator:
|
||||
:toc: macro
|
||||
:toclevels: 1
|
||||
:!toc-title:
|
||||
:caution-caption: :fire:
|
||||
:important-caption: :exclamtion:
|
||||
:note-caption: :paperclip:
|
||||
:tip-caption: :bulb:
|
||||
:warning-caption: :warning:
|
||||
|
||||
A __ser__ialization/__de__serialization library for __Simplified JSON__, specifically, the Bitsquid/Stingray flavor.
|
69
README.md
69
README.md
|
@ -1,69 +0,0 @@
|
|||
# serde_sjson
|
||||
|
||||
A **ser**ialization/**de**serialization library for Simplified JSON,
|
||||
the Bitsquid/Stingray flavor of JSON.
|
||||
|
||||
## Usage
|
||||
|
||||
### Serializing
|
||||
|
||||
```rust
|
||||
use serde::Serialize;
|
||||
use serde_sjson::Result;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Person {
|
||||
name: String,
|
||||
age: u8,
|
||||
friends: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let data = Person {
|
||||
name: String::from("Marc"),
|
||||
age: 21,
|
||||
friends: vec![String::from("Jessica"), String::from("Paul")],
|
||||
};
|
||||
|
||||
let s = serde_sjson::to_string(&data)?;
|
||||
|
||||
println!("{}", s);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### Deserializing
|
||||
|
||||
```rust
|
||||
use serde::Deserialize;
|
||||
use serde_sjson::Result;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Person {
|
||||
name: String,
|
||||
age: u8,
|
||||
friends: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let sjson = r#"
|
||||
name = Marc
|
||||
age = 21
|
||||
friends = [
|
||||
Jessica
|
||||
Paul
|
||||
]"#;
|
||||
|
||||
let data: Person = serde_sjson::from_str(sjson)?;
|
||||
|
||||
println!(
|
||||
"{} is {} years old and has {} friends.",
|
||||
data.name,
|
||||
data.age,
|
||||
data.friends.len()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
|
@ -1,3 +0,0 @@
|
|||
# {{crate}}
|
||||
|
||||
{{readme}}
|
|
@ -1,5 +0,0 @@
|
|||
pre-release-replacements = [
|
||||
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}"},
|
||||
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}"},
|
||||
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n\n## [Unreleased] - ReleaseDate", exactly=1},
|
||||
]
|
|
@ -5,7 +5,6 @@ use serde::Deserialize;
|
|||
use crate::error::{Error, ErrorCode, Result};
|
||||
use crate::parser::*;
|
||||
|
||||
/// A container for deserializing Rust values from SJSON.
|
||||
pub struct Deserializer<'de> {
|
||||
input: Span<'de>,
|
||||
is_top_level: bool,
|
||||
|
@ -13,7 +12,7 @@ pub struct Deserializer<'de> {
|
|||
|
||||
impl<'de> Deserializer<'de> {
|
||||
#![allow(clippy::should_implement_trait)]
|
||||
pub(crate) fn from_str(input: &'de str) -> Self {
|
||||
pub fn from_str(input: &'de str) -> Self {
|
||||
Self {
|
||||
input: Span::from(input),
|
||||
is_top_level: true,
|
||||
|
@ -66,8 +65,6 @@ impl<'de> Deserializer<'de> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deserializes an SJSON string to a Rust value.
|
||||
#[inline]
|
||||
pub fn from_str<'a, T>(input: &'a str) -> Result<T>
|
||||
where
|
||||
T: Deserialize<'a>,
|
||||
|
|
|
@ -2,11 +2,8 @@ use std::{fmt, io};
|
|||
|
||||
use crate::parser::Token;
|
||||
|
||||
/// An alias for a `Result` with `serde_sjson::Error`.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// A type encapsulating the different errors that might occurr
|
||||
/// during serialization or deserialization.
|
||||
#[derive(PartialEq)]
|
||||
pub struct Error {
|
||||
inner: Box<ErrorImpl>,
|
||||
|
|
68
src/lib.rs
68
src/lib.rs
|
@ -1,71 +1,3 @@
|
|||
//! A **ser**ialization/**de**serialization library for Simplified JSON,
|
||||
//! the Bitsquid/Stingray flavor of JSON.
|
||||
//!
|
||||
//! # Usage
|
||||
//!
|
||||
//! ## Serializing
|
||||
//!
|
||||
//! ```
|
||||
//! use serde::Serialize;
|
||||
//! use serde_sjson::Result;
|
||||
//!
|
||||
//! #[derive(Serialize)]
|
||||
//! struct Person {
|
||||
//! name: String,
|
||||
//! age: u8,
|
||||
//! friends: Vec<String>,
|
||||
//! }
|
||||
//!
|
||||
//! fn main() -> Result<()> {
|
||||
//! let data = Person {
|
||||
//! name: String::from("Marc"),
|
||||
//! age: 21,
|
||||
//! friends: vec![String::from("Jessica"), String::from("Paul")],
|
||||
//! };
|
||||
//!
|
||||
//! let s = serde_sjson::to_string(&data)?;
|
||||
//!
|
||||
//! println!("{}", s);
|
||||
//!
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ## Deserializing
|
||||
//!
|
||||
//! ```
|
||||
//! use serde::Deserialize;
|
||||
//! use serde_sjson::Result;
|
||||
//!
|
||||
//! #[derive(Deserialize)]
|
||||
//! struct Person {
|
||||
//! name: String,
|
||||
//! age: u8,
|
||||
//! friends: Vec<String>,
|
||||
//! }
|
||||
//!
|
||||
//! fn main() -> Result<()> {
|
||||
//! let sjson = r#"
|
||||
//! name = Marc
|
||||
//! age = 21
|
||||
//! friends = [
|
||||
//! Jessica
|
||||
//! Paul
|
||||
//! ]"#;
|
||||
//!
|
||||
//! let data: Person = serde_sjson::from_str(sjson)?;
|
||||
//!
|
||||
//! println!(
|
||||
//! "{} is {} years old and has {} friends.",
|
||||
//! data.name,
|
||||
//! data.age,
|
||||
//! data.friends.len()
|
||||
//! );
|
||||
//!
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
mod de;
|
||||
mod error;
|
||||
mod parser;
|
||||
|
|
|
@ -7,14 +7,12 @@ use crate::error::{Error, ErrorCode, Result};
|
|||
// TODO: Make configurable
|
||||
const INDENT: [u8; 2] = [0x20, 0x20];
|
||||
|
||||
/// A container for serializing Rust values into SJSON.
|
||||
pub struct Serializer<W> {
|
||||
// The current indentation level
|
||||
level: usize,
|
||||
writer: W,
|
||||
}
|
||||
|
||||
/// Serializes a value into a generic `io::Write`.
|
||||
#[inline]
|
||||
pub fn to_writer<T, W>(writer: &mut W, value: &T) -> Result<()>
|
||||
where
|
||||
|
@ -25,7 +23,6 @@ where
|
|||
value.serialize(&mut serializer)
|
||||
}
|
||||
|
||||
/// Serializes a value into a byte vector.
|
||||
#[inline]
|
||||
pub fn to_vec<T>(value: &T) -> Result<Vec<u8>>
|
||||
where
|
||||
|
@ -36,7 +33,6 @@ where
|
|||
Ok(vec)
|
||||
}
|
||||
|
||||
/// Serializes a value into a string.
|
||||
#[inline]
|
||||
pub fn to_string<T>(value: &T) -> Result<String>
|
||||
where
|
||||
|
@ -55,7 +51,6 @@ impl<W> Serializer<W>
|
|||
where
|
||||
W: io::Write,
|
||||
{
|
||||
/// Creates a new `Serializer`.
|
||||
pub fn new(writer: W) -> Self {
|
||||
Self { level: 0, writer }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use serde_sjson::to_string;
|
||||
use serde_sjson::{to_string, Error};
|
||||
|
||||
#[test]
|
||||
fn serialize_null() {
|
||||
|
|
Loading…
Add table
Reference in a new issue