crowdstrike_cloudproto/
framing.rs

1//! This module provides an async [`CloudProtoSocket`](socket::CloudProtoSocket) Stream + Sink that handles [`CloudProtoPacket`](packet::CloudProtoPacket)s.
2//!
3//! CLOUDPROTO is a packet-based big endian binary protocol that transports events or other payloads.
4//! The framing layer handles the common outer header/framing,
5//! but ignores the inner service-specific payload format and interpretation of packet kinds.
6
7mod hdr_version;
8mod packet;
9mod socket;
10
11pub use hdr_version::CloudProtoVersion;
12pub use packet::CloudProtoPacket;
13pub use socket::{CloudProtoSocket, DEFAULT_MAX_FRAME_LENGTH};
14
15use crate::services::CloudProtoMagic;
16use thiserror::Error;
17
18#[derive(Error, Debug)]
19pub enum CloudProtoError {
20    #[error("Bad CloudProto magic {0:#x}, expected {1:#x}")]
21    BadMagic(CloudProtoMagic, CloudProtoMagic),
22    #[error("Bad CloudProto header version {0:#x}, expected {1:#x}")]
23    BadVersion(CloudProtoVersion, CloudProtoVersion),
24    #[error("Bad CloudProto payload size {0:#x}, frame header announced {1:#x}")]
25    BadFrameSize(usize, usize),
26    #[error("Received payload size too short, got {0:#x} but wanted at least {1:#x}")]
27    PayloadTooShort(usize, usize),
28    #[error("Received payload with invalid size, got {0:#x} but expected {1:#x}")]
29    PayloadInvalidSize(usize, usize),
30    #[error("Received packet kind {0} while connecting, but expected {1}")]
31    WrongConnectionPacketKind(u8, u8),
32    #[error("{0}")]
33    ClosedByPeer(String),
34    #[error("CloudProto IO error")]
35    Io {
36        #[from]
37        source: std::io::Error,
38    },
39}