12 releases

0.2.2 Dec 25, 2025
0.2.1 Nov 14, 2025
0.1.9 Sep 6, 2025
0.1.8 Aug 16, 2025
0.1.4 May 23, 2025

#671 in Encoding

Download history 48/week @ 2025-10-22 53/week @ 2025-11-05 175/week @ 2025-11-12 138/week @ 2025-11-19 192/week @ 2025-11-26 138/week @ 2025-12-03 116/week @ 2025-12-10 133/week @ 2025-12-17 186/week @ 2025-12-24 274/week @ 2025-12-31 79/week @ 2026-01-07 127/week @ 2026-01-14 48/week @ 2026-01-21 114/week @ 2026-01-28 131/week @ 2026-02-04

437 downloads per month
Used in saas-rs-sdk

MIT license

625KB
377 lines

pbbson-rs

Utilities for pbjson to BSON conversions.

License Arch

Installing

$ cargo add pbbson

Testing

$ make check

Using

Convert a Prost Protobuf message into a BSON Document

use bson::Document;
use pbbson::Model;

let doc: Document = Model::try_from(&message).unwrap().into();

Convert a BSON Document into a Prost Protobuf message

let my_struct: StructType = model.try_into().unwrap();

Status

Protobuf to BSON

  • bool → Bool
  • double → Double
  • int32 → Int32
  • int64 → Int64
  • repeated → List
  • string → String
  • uint32 → Int64
  • uint64 → String
  • pbjson types
    • Any
    • Api
    • Descriptor
    • Duration → String (Go-style duration string with humanized suffixes)
    • Empty
    • FieldMask
    • SourceContext
    • Struct → Document
    • Timestamp → DateTime
    • Type
    • Wrappers

BSON to Protobuf

  • Array
  • Binary
    • Encrypted
    • Function
    • Generic
    • Md5 → bytes
    • Md5 → String
    • Sensitive
    • Uuid → bytes
    • Uuid → String
  • Boolean
  • DateTime → Timestamp
  • Decimal128
  • Document → Struct
  • Double
  • Int32
  • Int64
  • JavaScriptCode
  • JavaScriptCodeWithScope
  • Null
  • ObjectId → String (20-byte base32hex encoded xid)
  • RegularExpression
  • String → Duration
  • String → String
  • String → Timestamp
  • Timestamp

Dependencies

~16–25MB
~373K SLoC