1use bytes::{Buf, BufMut};
4
5use super::{VarInt, VarIntUnexpectedEnd};
6use crate::grease::is_grease_value;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct UniStream(pub VarInt);
11
12impl UniStream {
13 pub fn decode<B: Buf>(buf: &mut B) -> Result<Self, VarIntUnexpectedEnd> {
15 Ok(UniStream(VarInt::decode(buf)?))
16 }
17
18 pub fn encode<B: BufMut>(&self, buf: &mut B) {
20 self.0.encode(buf)
21 }
22
23 pub fn is_grease(&self) -> bool {
25 is_grease_value(self.0.into_inner())
26 }
27
28 pub const fn from_u32(value: u32) -> Self {
30 Self(VarInt::from_u32(value))
31 }
32
33 pub const CONTROL: UniStream = UniStream::from_u32(0x00);
35 pub const PUSH: UniStream = UniStream::from_u32(0x01);
37 pub const QPACK_ENCODER: UniStream = UniStream::from_u32(0x02);
39 pub const QPACK_DECODER: UniStream = UniStream::from_u32(0x03);
41 pub const WEBTRANSPORT: UniStream = UniStream::from_u32(0x54);
43}