Expand description
A fast, variation-tolerant CBOR codec implementing RFC 8949.
FCPW provides an allocation-free event parser and encoder, zero-copy deserialization from byte slices, Serde integration, dynamic CBOR values, deterministic encoding and validation, RFC 8742 sequence decoding, and optional diagnostic-notation and parallel APIs.
§Quick start
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Message<'a> {
id: u64,
text: &'a str,
}
let message = Message { id: 7, text: "hello" };
let encoded = fcpw::to_vec(&message)?;
let decoded: Message<'_> = fcpw::from_slice(&encoded)?;
assert_eq!(decoded, message);For allocation-free processing, start with SliceDecoder, Parser, and
Encoder. With the alloc feature, Value and BorrowedValue retain
CBOR-specific constructs such as tags, simple values, undefined values,
duplicate map keys, and bignums.
§Cargo features
std(default): reader and writer integration; impliesalloc.alloc(default): owned values and collection helpers.serde(default): serialization and deserialization through Serde; impliesalloc.diagnostic: RFC 8949 diagnostic notation; impliesalloc.parallel: Rayon-backed batch decoding; implies the default public API features.
The scalar parser and encoder remain available with default-features = false.
The crate contains no unsafe code and requires Rust 1.97 or newer.
Re-exports§
pub use tag::Tagged;pub use value::BorrowedValue;pub use value::Value;
Modules§
- de
- Serde deserialization APIs.
- diagnostic
- RFC 8949 diagnostic notation for dynamic values.
- parallel
- Parallel decoding for independent CBOR items.
- ser
- Serde serialization APIs.
- tag
- Typed support for CBOR semantic tags.
- value
- Dynamic CBOR values and conversions.
Structs§
- Decode
Options - Validation and resource-limit settings for decoding.
- Deserializer
- A stateful Serde deserializer over a borrowed CBOR byte slice.
- Deterministic
Scratch - Reusable temporary storage for deterministic map encoding.
- Encode
Config - A reusable choice between ordinary and deterministic vector encoding.
- Encoder
- A low-level encoder for writing individual CBOR data items.
- Error
- An error with its category and byte offset.
- IoWrite
- Adapts a
std::io::Writedestination toOutput. - Parser
- A streaming iterator over the tokens in CBOR input.
- RawValue
- The complete encoded bytes of one CBOR data item.
- Reader
Deserializer - A stateful decoder for consecutive owned CBOR items from a reader.
- Sequence
Decoder - An iterator over the raw items in a CBOR sequence.
- Serializer
- A stateful Serde serializer that writes CBOR to a caller-owned output.
- Slice
Decoder - A cursor for decoding typed values from a byte slice.
- Slice
Output - A fixed-capacity
Outputbacked by a mutable byte slice.
Enums§
- Error
Kind - The category of a CBOR encoding or decoding error.
- Event
- A token produced while parsing a CBOR item stream.
- Validation
- The level of validation applied while decoding.
Traits§
- Output
- A destination that accepts encoded CBOR bytes.
Functions§
- from_
reader - Deserializes one CBOR item read to the end of
reader. - from_
reader_ with_ buffer - Decodes from
readerusing caller-owned reusable input storage. - from_
slice - Deserializes exactly one CBOR item from
input. - from_
slice_ bool_ array - Decodes one CBOR array of booleans without per-element Serde dispatch.
- from_
slice_ bool_ array_ into - Decodes a boolean array into
output, retaining its allocation for reuse. - from_
slice_ f32_ array - Decodes one CBOR array of numeric values directly into binary32 values.
- from_
slice_ f32_ array_ into - Decodes a numeric array into
output, retaining its allocation for reuse. - from_
slice_ f64_ array - Decodes one CBOR array of numeric values directly into binary64 values.
- from_
slice_ f64_ array_ into - Decodes a numeric array into
output, retaining its allocation for reuse. - from_
slice_ i8_ array - Decodes one CBOR array of native integers directly into
i8values. - from_
slice_ i8_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ i16_ array - Decodes one CBOR array of native integers directly into
i16values. - from_
slice_ i16_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ i32_ array - Decodes one CBOR array of native integers directly into
i32values. - from_
slice_ i32_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ i64_ array - Decodes one CBOR array of native integers directly into
i64values. - from_
slice_ i64_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ u8_ array - Decodes one CBOR array of unsigned integers directly into
u8values. - from_
slice_ u8_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ u16_ array - Decodes one CBOR array of unsigned integers directly into
u16values. - from_
slice_ u16_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ u32_ array - Decodes one CBOR array of unsigned integers directly into
u32values. - from_
slice_ u32_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ u64_ array - Decodes one CBOR array of native unsigned integers directly into
u64values. - from_
slice_ u64_ array_ into - Decodes into
output, clearing its contents while retaining capacity. - from_
slice_ value - Decodes an owned dynamic CBOR value.
- from_
slice_ with_ options - Deserializes exactly one CBOR item using explicit decoding options.
- into_
writer - Serializes
valuetowriter, using Ciborium’s argument order. - serialized_
size - Computes the number of bytes produced by ordinary CBOR serialization.
- to_
slice - Serializes
valueintooutput, returning the initialized prefix. - to_vec
- Serializes
valueas CBOR into a newly allocated byte vector. - to_
vec_ deterministic - Deterministically serializes
valueinto a new byte vector. - to_
vec_ deterministic_ into - Deterministically encodes into
output, retaining its allocation for reuse. - to_
vec_ deterministic_ into_ with_ scratch - Deterministically encodes into
output, reusing map sorting storage. - to_
vec_ into - Encodes into
output, clearing its contents while retaining its allocation. - to_
vec_ packed - Serializes in packed form, replacing struct field and enum variant names with their zero-based declaration indices.
- to_
vec_ value - Encodes a dynamic value into a new buffer.
- to_
writer - Serializes
valueas CBOR and writes it towriter. - validate
- Validates exactly one CBOR data item.
- validate_
deterministic - Validates exactly one deterministically encoded CBOR data item.
- write_
self_ describe - Writes CBOR’s self-described-CBOR tag (55799) to an output.
Type Aliases§
- Result
- The result type returned by this crate.