Skip to main content

Crate fcpw

Crate fcpw 

Source
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; implies alloc.
  • alloc (default): owned values and collection helpers.
  • serde (default): serialization and deserialization through Serde; implies alloc.
  • diagnostic: RFC 8949 diagnostic notation; implies alloc.
  • 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§

DecodeOptions
Validation and resource-limit settings for decoding.
Deserializer
A stateful Serde deserializer over a borrowed CBOR byte slice.
DeterministicScratch
Reusable temporary storage for deterministic map encoding.
EncodeConfig
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::Write destination to Output.
Parser
A streaming iterator over the tokens in CBOR input.
RawValue
The complete encoded bytes of one CBOR data item.
ReaderDeserializer
A stateful decoder for consecutive owned CBOR items from a reader.
SequenceDecoder
An iterator over the raw items in a CBOR sequence.
Serializer
A stateful Serde serializer that writes CBOR to a caller-owned output.
SliceDecoder
A cursor for decoding typed values from a byte slice.
SliceOutput
A fixed-capacity Output backed by a mutable byte slice.

Enums§

ErrorKind
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 reader using 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 i8 values.
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 i16 values.
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 i32 values.
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 i64 values.
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 u8 values.
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 u16 values.
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 u32 values.
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 u64 values.
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 value to writer, using Ciborium’s argument order.
serialized_size
Computes the number of bytes produced by ordinary CBOR serialization.
to_slice
Serializes value into output, returning the initialized prefix.
to_vec
Serializes value as CBOR into a newly allocated byte vector.
to_vec_deterministic
Deterministically serializes value into 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 value as CBOR and writes it to writer.
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.