Skip to content

Commit 143897c

Browse files
committed
Update README
1 parent 7ddcd2e commit 143897c

File tree

7 files changed

+107
-241
lines changed

7 files changed

+107
-241
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration
1+
name: Build
22
on:
33
push:
44
pull_request:

README.md

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
11
# RMP - Rust MessagePack
22

3-
RMP is a pure Rust [MessagePack](http://msgpack.org) implementation.
3+
RMP is a complete pure-Rust [MessagePack](http://msgpack.org) implementation. MessagePack a compact self-describing binary serialization format.
44

5-
[![Build Status](https://travis-ci.org/3Hren/msgpack-rust.svg?branch=master)](https://travis-ci.org/3Hren/msgpack-rust)
6-
[![Coverage Status][coveralls-img]][coveralls-url]
5+
This project consists of three crates:
76

8-
This repository consists of three separate crates: the RMP core and two implementations to ease serializing and
9-
deserializing Rust structs.
10-
11-
crates.rs | API Documentation |
12-
-------------------------------------------|---------------------------------|
13-
[![rmp][crates-rmp-img]][crates-rmp-url] | [RMP][rmp-docs-url] |
14-
[![rmps][crates-rmps-img]][crates-rmps-url] | [RMP Serde][rmps-docs-url] |
15-
[![rmpv][crates-rmpv-img]][crates-rmpv-url] | [RMP Value][rmpv-docs-url] |
7+
* [RMP-Serde][crates-rmps-url] ([Documentation][rmps-docs-url]) — easy serializing/deserializing via [Serde](https://serde.rs).
8+
* [RMP-Value][crates-rmpv-url] ([Documentation][rmpv-docs-url]) — a universal `Value` enum that can hold any MessagePack type. Allows deserializing arbitrary messages without a known schema.
9+
* [RMP][crates-rmp-url] ([Documentation][rmp-docs-url]) — low-level functions for reading/writing encoded data.
1610

1711
## Features
1812

19-
- **Convenient API**
13+
- **Convenient and powerful APIs**
2014

21-
RMP is designed to be lightweight and straightforward. There are low-level API, which gives you
22-
full control on data encoding/decoding process and makes no heap allocations. On the other hand
23-
there are high-level API, which provides you convenient interface using Rust standard library and
24-
compiler reflection, allowing to encode/decode structures using `derive` attribute.
15+
RMP is designed to be lightweight and straightforward. There is a high-level API with support for Serde,
16+
which provides you convenient interface for encode/decode Rust's data structures using `derive` attribute.
17+
There are also low-level APIs, which give you full control over data encoding/decoding process,
18+
with no-std support and without heap allocations.
2519

2620
- **Zero-copy value decoding**
2721

28-
RMP allows to decode bytes from a buffer in a zero-copy manner easily and blazingly fast, while Rust
29-
static checks guarantees that the data will be valid as long as the buffer lives.
30-
31-
- **Clear error handling**
32-
33-
RMP's error system guarantees that you never receive an error enum with unreachable variant.
22+
RMP allows to decode bytes from a buffer in a zero-copy manner. Parsing is implemented in safe Rust.
3423

35-
- **Robust and tested**
24+
- **Robust, stable and tested**
3625

3726
This project is developed using TDD and CI, so any found bugs will be fixed without breaking
3827
existing functionality.
3928

29+
## Why MessagePack?
30+
31+
Smaller and simpler to parse than JSON. Supports the same types as JSON, plus binary data, all float values, and 64-bit numbers.
32+
Encoded data is self-describing and extensible, without requiring a schema definition.
33+
4034
## Requirements
4135

42-
- Rust 1.53.0 or later
36+
- Rust 1.56.0 or later
4337

4438
[rustc-serialize]: https://github.com/rust-lang-nursery/rustc-serialize
4539
[serde]: https://github.com/serde-rs/serde
4640

41+
[ci-img]: https://github.com/3Hren/msgpack-rust/actions/workflows/ci.yml/badge.svg
42+
[ci-url]: https://github.com/3Hren/msgpack-rust/actions/workflows/ci.yml
43+
4744
[coveralls-img]: https://coveralls.io/repos/3Hren/msgpack-rust/badge.svg?branch=master&service=github
4845
[coveralls-url]: https://coveralls.io/github/3Hren/msgpack-rust?branch=master
4946

5047
[rmp-docs-url]: https://docs.rs/rmp
5148
[rmps-docs-url]: https://docs.rs/rmp-serde
5249
[rmpv-docs-url]: https://docs.rs/rmpv
5350

54-
[crates-rmp-img]: https://img.shields.io/crates/v/rmp.svg
5551
[crates-rmp-url]: https://lib.rs/crates/rmp
56-
57-
[crates-rmps-img]: https://img.shields.io/crates/v/rmp-serde.svg
5852
[crates-rmps-url]: https://lib.rs/crates/rmp-serde
59-
60-
[crates-rmpv-img]: https://img.shields.io/crates/v/rmpv.svg
6153
[crates-rmpv-url]: https://lib.rs/crates/rmpv
54+
55+
56+
[![Build][ci-img]][ci-url] [![Coverage Status][coveralls-img]][coveralls-url]

rmp-serde/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

rmp-serde/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# MessagePack + Serde
2+
3+
This crate connects Rust MessagePack library with [`serde`][serde] providing an ability to
4+
easily serialize and deserialize both Rust built-in types, the standard library and custom data
5+
structures.
6+
7+
## Motivating example
8+
9+
```rust
10+
let buf = rmp_serde::to_vec(&(42, "the Answer")).unwrap();
11+
12+
assert_eq!(
13+
vec![0x92, 0x2a, 0xaa, 0x74, 0x68, 0x65, 0x20, 0x41, 0x6e, 0x73, 0x77, 0x65, 0x72],
14+
buf
15+
);
16+
17+
assert_eq!((42, "the Answer"), rmp_serde::from_slice(&buf).unwrap());
18+
```
19+
20+
## Type-based Serialization and Deserialization
21+
22+
Serde provides a mechanism for low boilerplate serialization & deserialization of values to and
23+
from MessagePack via the serialization API.
24+
25+
To be able to serialize a piece of data, it must implement the `serde::Serialize` trait. To be
26+
able to deserialize a piece of data, it must implement the `serde::Deserialize` trait. Serde
27+
provides an annotation to automatically generate the code for these
28+
traits: `#[derive(Serialize, Deserialize)]`.
29+
30+
## Examples
31+
32+
```rust
33+
use std::collections::HashMap;
34+
use serde::{Deserialize, Serialize};
35+
use rmp_serde::{Deserializer, Serializer};
36+
37+
#[derive(Debug, PartialEq, Deserialize, Serialize)]
38+
struct Human {
39+
age: u32,
40+
name: String,
41+
}
42+
43+
fn main() {
44+
let mut buf = Vec::new();
45+
let val = Human {
46+
age: 42,
47+
name: "John".into(),
48+
};
49+
50+
val.serialize(&mut Serializer::new(&mut buf)).unwrap();
51+
}
52+
```
53+
54+
## Efficient storage of `&[u8]` types
55+
56+
MessagePack can efficiently store binary data. However, Serde's standard derived implementations *do not* use binary representations by default. Serde prefers to represent types like `&[u8; N]` or `Vec<u8>` as arrays of objects of arbitrary/unknown type, and not as slices of bytes. This creates about a 50% overhead in storage size.
57+
58+
Wrap your data in [`serde_bytes`](https://lib.rs/crates/serde_bytes) to store blobs quickly and efficiently. Alternatively, [configure an override in `rmp_serde` to force use of byte slices](https://docs.rs/rmp-serde/latest/rmp_serde/encode/struct.Serializer.html#method.with_bytes).
59+
60+
[serde]: https://serde.rs/

rmp-serde/src/encode.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ impl<W: Write, C> Serializer<W, C> {
268268
/// This reduces overhead of binary data, but it may break
269269
/// decodnig of some Serde types that happen to contain `[u8]`s,
270270
/// but don't implement Serde's `visit_bytes`.
271+
///
272+
/// ```rust
273+
/// use serde::ser::Serialize;
274+
/// let mut msgpack_data = Vec::new();
275+
/// let mut serializer = rmp_serde::Serializer::new(&mut msgpack_data)
276+
/// .with_bytes(rmp_serde::config::BytesMode::ForceAll);
277+
/// vec![255u8; 100].serialize(&mut serializer).unwrap();
278+
/// ```
271279
#[inline]
272280
pub fn with_bytes(mut self, mode: BytesMode) -> Serializer<W, C> {
273281
self.config.bytes = mode;

rmp-serde/src/lib.rs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,4 @@
1-
//! This crate connects Rust MessagePack library with [`serde`][serde] providing an ability to
2-
//! easily serialize and deserialize both Rust built-in types, the standard library and custom data
3-
//! structures.
4-
//!
5-
//! ## Motivating example
6-
//!
7-
//! ```
8-
//! let buf = rmp_serde::to_vec(&(42, "the Answer")).unwrap();
9-
//!
10-
//! assert_eq!(
11-
//! vec![0x92, 0x2a, 0xaa, 0x74, 0x68, 0x65, 0x20, 0x41, 0x6e, 0x73, 0x77, 0x65, 0x72],
12-
//! buf
13-
//! );
14-
//!
15-
//! assert_eq!((42, "the Answer"), rmp_serde::from_slice(&buf).unwrap());
16-
//! ```
17-
//!
18-
//! # Type-based Serialization and Deserialization
19-
//!
20-
//! Serde provides a mechanism for low boilerplate serialization & deserialization of values to and
21-
//! from MessagePack via the serialization API.
22-
//!
23-
//! To be able to serialize a piece of data, it must implement the `serde::Serialize` trait. To be
24-
//! able to deserialize a piece of data, it must implement the `serde::Deserialize` trait. Serde
25-
//! provides an annotation to automatically generate the code for these
26-
//! traits: `#[derive(Serialize, Deserialize)]`.
27-
//!
28-
//! # Examples
29-
//!
30-
//! ```
31-
//! use std::collections::HashMap;
32-
//! use serde::{Deserialize, Serialize};
33-
//! use rmp_serde::{Deserializer, Serializer};
34-
//!
35-
//! #[derive(Debug, PartialEq, Deserialize, Serialize)]
36-
//! struct Human {
37-
//! age: u32,
38-
//! name: String,
39-
//! }
40-
//!
41-
//! fn main() {
42-
//! let mut buf = Vec::new();
43-
//! let val = Human {
44-
//! age: 42,
45-
//! name: "John".into(),
46-
//! };
47-
//!
48-
//! val.serialize(&mut Serializer::new(&mut buf)).unwrap();
49-
//! }
50-
//! ```
51-
//!
52-
//! [serde]: https://serde.rs/
1+
#![doc = include_str!("../README.md")]
532
#![forbid(unsafe_code)]
543
#![warn(missing_debug_implementations, missing_docs)]
554

rmp/README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ RMP is a pure Rust [MessagePack](http://msgpack.org) implementation of an effici
44
serialization format. This crate provides low-level core functionality, writers and readers for
55
primitive values with direct mapping between binary MessagePack format.
66

7-
**Warning** this library is still in rapid development and everything may change until 1.0
8-
comes.
7+
[Looking for Serde support](https://lib.rs/crates/rmp-serde)?
8+
9+
This crate represents the very basic functionality needed to work with MessagePack format.
10+
Ideologically it is developed as a basis for building high-level abstractions.
911

1012
### Usage
1113

1214
To use `rmp`, first add this to your `Cargo.toml`:
1315

1416
```toml
1517
[dependencies.rmp]
16-
rmp = "^0.8"
18+
rmp = "0.8"
1719
```
1820

1921
### Features
2022

21-
- **Convenient API**
23+
- **Low-level API**
2224

23-
RMP is designed to be lightweight and straightforward. There are low-level API, which gives you
24-
full control on data encoding/decoding process and makes no heap allocations. On the other hand
25-
there are high-level API, which provides you convenient interface using Rust standard library and
26-
compiler reflection, allowing to encode/decode structures using `derive` attribute.
25+
RMP is designed to be lightweight and straightforward. There are low-level APIs, which give you
26+
full control over the encoding/decoding process. `no-std` environments are supported.
2727

2828
- **Zero-copy value decoding**
2929

30-
RMP allows to decode bytes from a buffer in a zero-copy manner easily and blazingly fast, while Rust
31-
static checks guarantees that the data will be valid until buffer lives.
30+
RMP allows to decode bytes from a buffer in a zero-copy manner, without any heap allocations.
31+
easily and blazingly fast. Rust static checks guarantee that the data will be valid until buffer lives.
3232

3333
- **Clear error handling**
3434

@@ -41,9 +41,6 @@ rmp = "^0.8"
4141

4242
### Detailed
4343

44-
This crate represents the very basic functionality needed to work with MessagePack format.
45-
Ideologically it is developed as a basis for building high-level abstractions.
46-
4744
Currently there are two large modules: encode and decode. More detail you can find in the
4845
corresponding sections.
4946

@@ -140,6 +137,6 @@ assert_eq!([0xcb, 0x40, 0x9, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18], buf[..]);
140137
assert_eq!(pi, rmp::decode::read_f64(&mut &buf[..]).unwrap());
141138
```
142139

143-
[read_int]: decode/fn.read_int.html
144-
145140
License: MIT
141+
142+
[read_int]: https://docs.rs/rmp/latest/rmp/decode/fn.read_int.html

0 commit comments

Comments
 (0)