Skip to main content

watchwoman_protocol/
lib.rs

1//! Watchman wire protocol codecs.
2//!
3//! Two encodings live side by side: newline-delimited JSON (for CLI users
4//! and scripts) and BSER, the binary encoding watchman ships for its
5//! language bindings. Both produce and consume the same [`Value`] tree so
6//! the daemon stays codec-agnostic.
7
8pub mod bser;
9pub mod json;
10pub mod value;
11
12pub use value::{Value, ValueRef};
13
14#[derive(Debug, thiserror::Error)]
15pub enum ProtocolError {
16    #[error("io: {0}")]
17    Io(#[from] std::io::Error),
18    #[error("json: {0}")]
19    Json(#[from] serde_json::Error),
20    #[error("bser: {0}")]
21    Bser(String),
22    #[error("truncated PDU")]
23    Truncated,
24    #[error("unknown encoding tag: {0:#x}")]
25    UnknownEncoding(u8),
26}
27
28pub type Result<T> = std::result::Result<T, ProtocolError>;
29
30/// Wire encoding selected during the handshake.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum Encoding {
33    Json,
34    BserV1,
35    BserV2,
36}