Skip to content

Commit

Permalink
Rename crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Flix committed Sep 28, 2024
1 parent 1c5ee4e commit 162a9eb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
authors = ["Flix <[email protected]>"]
categories = ["encoding", "parser-implementations", "no-std", "no-std::no-alloc", "embedded"]
description = "A brief, self-descriptive, serde-compatible binary format."
documentation = "https://docs.rs/brief"
documentation = "https://docs.rs/serde-brief"
edition = "2021"
exclude = ["/tests/data", "/.github"]
homepage = "https://github.com/FlixCoder/fhir-sdk"
homepage = "https://github.com/FlixCoder/serde-brief"
keywords = ["serde", "encoding", "binary", "data", "no-std"]
license = "MIT"
name = "brief"
name = "serde-brief"
readme = "README.md"
repository = "https://github.com/FlixCoder/brief"
repository = "https://github.com/FlixCoder/serde-brief"
rust-version = "1.81"
version = "0.1.0"

Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Brief
# Serde-Brief

[![crates.io page](https://img.shields.io/crates/v/brief.svg)](https://crates.io/crates/brief)
[![docs.rs page](https://docs.rs/brief/badge.svg)](https://docs.rs/brief/)
![license: MIT](https://img.shields.io/crates/l/brief.svg)
[![crates.io page](https://img.shields.io/crates/v/serde-brief.svg)](https://crates.io/crates/serde-brief)
[![docs.rs page](https://docs.rs/serde-brief/badge.svg)](https://docs.rs/serde-brief/)
![license: MIT](https://img.shields.io/crates/l/serde-brief.svg)

Brief (German for letter) is a crate for encoding and decoding data into a binary format that is self-descriptive and [serde](https://docs.rs/serde/)-compatible.
Serde-Brief (German for letter) is a crate for encoding and decoding data into a binary format that is self-descriptive and [serde](https://docs.rs/serde/)-compatible.

## Design Goals

Expand All @@ -29,35 +29,35 @@ By default, structs' field names and enums' variant names are encoded as strings

## Comparisons

How does Brief compare to ..?
How does Serde-Brief compare to ..?

### [Postcard](https://docs.rs/postcard/)

Postcard is NOT a self-describing format. It's encoding solely consists of the raw data and the deserializer needs to have the same information on the data schema. This makes it more difficult to change the data format, e.g. add new fields.

Postcard is producing way smaller encoded data due to the missing schema information and field names. It is also faster.

Brief supports decoding unknown data and parsing it into the requested structures regardless of additional fields or different orders.
Serde-Brief supports decoding unknown data and parsing it into the requested structures regardless of additional fields or different orders.

### [Pot](https://docs.rs/pot/)

Pot is a self-describing format as well. It's encoding is more space-efficient due to reducing repeated type/schema definitions. This comes at the cost of serialization/deserialization speed.

It is also not no-std compatible.

Brief is faster most of the times, but less space-efficient.
Serde-Brief is faster most of the times, but less space-efficient.

### [Serde_json](https://docs.rs/serde_json/)

JSON is a self-describing format as well. However, it is text based and therefore requires string escaping. Bytes cannot be efficiently represented. However, JSON is widely adopted, as you already know :D

In Brief, map keys can not only be strings. Unlike in JSON, keys can be nested data, so something like `HashMap<MyKeyStruct, MyValueStruct>` can be serialized and deserialized without issues.
In Serde-Brief, map keys can not only be strings. Unlike in JSON, keys can be nested data, so something like `HashMap<MyKeyStruct, MyValueStruct>` can be serialized and deserialized without issues.

Brief is both more space-efficient and faster.
Serde-Brief is both more space-efficient and faster.

## Usage

Add the library to your project with `cargo add brief`. By default, no features are enabled (currently), so it is no-std by default. You can enable use of `Vec`s and such with features like `alloc` or `std`.
Add the library to your project with `cargo add serde-brief`. By default, no features are enabled (currently), so it is no-std by default. You can enable use of `Vec`s and such with features like `alloc` or `std`.

### Example Serialization/Deserialization

Expand All @@ -74,7 +74,7 @@ struct MyBorrowedData<'a> {
}

let data = MyBorrowedData { name: "Holla", age: 21 };
let mut output: Vec<u8, 22> = brief::to_heapless_vec(&data).unwrap();
let mut output: Vec<u8, 22> = serde_brief::to_heapless_vec(&data).unwrap();

assert_eq!(output, [
17,
Expand All @@ -83,7 +83,7 @@ assert_eq!(output, [
18
]);

let parsed: MyBorrowedData = brief::from_slice(&output).unwrap();
let parsed: MyBorrowedData = serde_brief::from_slice(&output).unwrap();
assert_eq!(parsed, data);
```

Expand Down
12 changes: 6 additions & 6 deletions docs/format-specification.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Brief Binary Format
# Serde-Brief Binary Format

The format is close to JSON, modified to be better, binary and fit to [serde's data model](https://serde.rs/data-model.html).

Expand All @@ -23,8 +23,8 @@ The format includes information on the structure of the data.

## Defined Types

Every value in Brief is prepended with a byte detailing its type.
The Brief format currently contains these types:
Every value in Serde-Brief is prepended with a byte detailing its type.
The Serde-Brief format currently contains these types:

| Type | Description | Byte value |
| --- | --- | --- |
Expand Down Expand Up @@ -91,7 +91,7 @@ Values can have any type, so even maps can consist of arbitrarily complex keys a

## Mapping of Rust Types to Encoded Data

The encoding/serialization and decoding/deserialization happens via `serde`, so it follows the [serde data model](https://serde.rs/data-model.html). Please familiarize yourself with its concept to fully understand the following. In any case, the following describes how Rust types are mapped to Brief format types.
The encoding/serialization and decoding/deserialization happens via `serde`, so it follows the [serde data model](https://serde.rs/data-model.html). Please familiarize yourself with its concept to fully understand the following. In any case, the following describes how Rust types are mapped to Serde-Brief format types.

There are two modes of the format. The first and default encodes structs as maps with keys being strings of the fields' names. The second encodes structs as maps with keys being unsigned integers, where the value denotes the index/position in the struct. Similarly, the same happens for enums. Variants are encoded either as string or as unsigned integer denoting their index (NOT discriminant).

Expand All @@ -107,7 +107,7 @@ Note that (at least currently) the deserializer can parse data regardless of whi

- Smaller footprint: strings need more space in the encoding.

### Serde Datatypes in Brief (String Representation)
### Serde Datatypes in Serde-Brief (String Representation)

The list of serde's types can be found [here](https://serde.rs/data-model.html), along with how Rust types are mapped to serde's types.

Expand Down Expand Up @@ -135,7 +135,7 @@ The list of serde's types can be found [here](https://serde.rs/data-model.html),
| tuple variant | MapStart, String, SeqStart .. SeqEnd, MapEnd | Enum names are not used. Variants with values are a map with a single key-value pair. The key is the variant name as string. The value is a sequence of the encoded values. |
| struct variant | MapStart, String, MapStart .. MapEnd, MapEnd | Enum names are not used. Variants with values are a map with a single key-value pair. The key is the variant name as string. The value is a map of the field names to their values. |

### Serde Datatypes in Brief (Index Representation)
### Serde Datatypes in Serde-Brief (Index Representation)

The list of serde's types can be found [here](https://serde.rs/data-model.html), along with how Rust types are mapped to serde's types.

Expand Down
4 changes: 2 additions & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct MyBorrowedData<'a> {
fn main() {
let data = MyBorrowedData { name: "Holla", age: 21 };
let mut output = [0; 22];
let bytes = brief::to_slice(&data, &mut output).unwrap();
let bytes = serde_brief::to_slice(&data, &mut output).unwrap();

assert_eq!(
bytes,
Expand All @@ -22,7 +22,7 @@ fn main() {
]
);

let parsed: MyBorrowedData = brief::from_slice(bytes).unwrap();
let parsed: MyBorrowedData = serde_brief::from_slice(bytes).unwrap();
assert_eq!(parsed, data);
}

Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # Brief
//! # Serde-Brief
//!
//! Brief (German for letter) is a crate for encoding and decoding data into a binary format that is self-descriptive and [serde](https://docs.rs/serde/)-compatible.
//! Serde-Brief (German for letter) is a crate for encoding and decoding data into a binary format that is self-descriptive and [serde](https://docs.rs/serde/)-compatible.
//!
//! ## Design Goals
//!
Expand Down Expand Up @@ -39,9 +39,9 @@
//!
//! ## Usage
//!
//! Add the library to your project with `cargo add brief`. By default, no features are enabled
//! (currently), so it is no-std by default. You can enable use of `Vec`s and such with features
//! like `alloc` or `std`.
//! Add the library to your project with `cargo add serde-brief`. By default, no features are
//! enabled (currently), so it is no-std by default. You can enable use of `Vec`s and such with
//! features like `alloc` or `std`.
//!
//! ### Example Serialization/Deserialization
//!
Expand All @@ -59,7 +59,7 @@
//! }
//!
//! let data = MyBorrowedData { name: "Holla", age: 21 };
//! let mut output: Vec<u8, 22> = brief::to_heapless_vec(&data).unwrap();
//! let mut output: Vec<u8, 22> = serde_brief::to_heapless_vec(&data).unwrap();
//!
//! assert_eq!(
//! output,
Expand All @@ -69,7 +69,7 @@
//! ]
//! );
//!
//! let parsed: MyBorrowedData = brief::from_slice(&output).unwrap();
//! let parsed: MyBorrowedData = serde_brief::from_slice(&output).unwrap();
//! assert_eq!(parsed, data);
//! ```
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down Expand Up @@ -97,7 +97,7 @@ use ::std::io::{Read, Write};
pub use self::value::{from_value, from_value_with_config, to_value, to_value_with_config};
pub use self::{config::Config, de::Deserializer, error::Error, ser::Serializer};

/// `Result` type that uses the `brief` error.
/// `Result` type that uses the `serde-brief` error.
pub type Result<T, E = Error> = ::core::result::Result<T, E>;

/// Serialize a type into a slice of bytes using the given configuration. Returns the slice with the
Expand Down
6 changes: 3 additions & 3 deletions tests/all/json_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Test with JSON blobs.
#![cfg(feature = "std")]

use ::brief::value::Value;
use ::serde_brief::value::Value;

fn roundtrip(value: Value<'_>) {
let bytes = brief::to_vec(&value).expect("serializing");
let parsed: Value<'_> = brief::from_slice(&bytes).expect("deserializing");
let bytes = serde_brief::to_vec(&value).expect("serializing");
let parsed: Value<'_> = serde_brief::from_slice(&bytes).expect("deserializing");
assert_eq!(parsed, value);
}

Expand Down

0 comments on commit 162a9eb

Please sign in to comment.