grpc-webnext 0.1.0

Full bidirectional gRPC for the browser — real HTTP/2 over WebSockets (h2ts), plus JSON, REST, and a single-stream Frame protocol — served in front of any gRPC service, in-process (wrap a tonic Router) or as a standalone proxy.
Documentation
//! Encode/decode a single WebSocket `Frame` (one frame per WS message).

use crate::pb::Frame;
use bytes::{Bytes, BytesMut};
use prost::Message;

#[derive(Debug, thiserror::Error)]
pub enum FrameError {
    #[error("failed to decode Frame: {0}")]
    Decode(#[from] prost::DecodeError),
}

/// Decode one WebSocket binary message into a `Frame`.
pub fn decode_frame(bytes: &[u8]) -> Result<Frame, FrameError> {
    Ok(Frame::decode(bytes)?)
}

/// Encode a `Frame` into the bytes of one WebSocket binary message.
pub fn encode_frame(frame: &Frame) -> Bytes {
    let mut buf = BytesMut::with_capacity(frame.encoded_len());
    frame.encode(&mut buf).expect("BytesMut has capacity");
    buf.freeze()
}