#[allow(unused_imports)]
use crate::util::FixedLengthFromBytes;
#[allow(unused_imports)]
use crate::util::FixedLengthSerialize;
#[allow(unused_imports)]
use crate::util::VariableLengthFromBytes;
#[allow(unused_imports)]
use crate::util::VariableLengthSerialize;
pub const EXTENSION_NAME: &str = "XpExtension";
pub type String8 = u8;
#[derive(Debug, Clone, PartialEq)]
pub struct Printer {
pub name: alloc::vec::Vec<String8>,
pub description: alloc::vec::Vec<String8>,
}
impl VariableLengthSerialize for Printer {
fn serialize_into(self, buf: &mut [u8]) -> crate::error::Result<usize> {
let buf_ptr = buf;
let name_len =
u32::try_from(self.name.len()).map_err(|_| crate::error::Error::Serialize)?;
buf_ptr
.get_mut(0..4)
.ok_or(crate::error::Error::Serialize)?
.copy_from_slice(
&(u32::try_from(name_len).map_err(|_| crate::error::Error::Serialize)?)
.serialize_fixed(),
);
let list_len = self.name.len();
crate::util::u8_vec_serialize_into(
buf_ptr.get_mut(4..).ok_or(crate::error::Error::Serialize)?,
&self.name,
)?;
let mut offset = list_len + 4;
offset += (4 - (offset % 4)) % 4;
let desc_len =
u32::try_from(self.description.len()).map_err(|_| crate::error::Error::Serialize)?;
buf_ptr
.get_mut(offset..offset + 4)
.ok_or(crate::error::Error::Serialize)?
.copy_from_slice(
&(u32::try_from(desc_len).map_err(|_| crate::error::Error::Serialize)?)
.serialize_fixed(),
);
offset += 4;
let list_len = self.description.len();
crate::util::u8_vec_serialize_into(
buf_ptr
.get_mut(offset..)
.ok_or(crate::error::Error::Serialize)?,
&self.description,
)?;
offset += list_len;
offset += (4 - (offset % 4)) % 4;
Ok(offset)
}
}
impl VariableLengthFromBytes for Printer {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let name_len = u32::from_bytes(ptr.get(0..4).ok_or(crate::error::Error::FromBytes)?)?;
let length_expr = name_len as usize;
let name: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
ptr.get(4..).ok_or(crate::error::Error::FromBytes)?,
length_expr,
)?;
let mut offset = length_expr + 4;
offset += (4 - (offset % 4)) % 4;
let desc_len = u32::from_bytes(
ptr.get(offset..offset + 4)
.ok_or(crate::error::Error::FromBytes)?,
)?;
offset += 4;
let length_expr = desc_len as usize;
let description: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
length_expr,
)?;
offset += length_expr;
offset += (4 - (offset % 4)) % 4;
Ok((Self { name, description }, offset))
}
}
pub type Pcontext = u32;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintQueryVersionReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub major_version: u16,
pub minor_version: u16,
}
impl FixedLengthFromBytes<12> for PrintQueryVersionReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
major_version: u16::from_bytes(
bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?,
)?,
minor_version: u16::from_bytes(
bytes.get(10..12).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrintGetPrinterListReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub printers: alloc::vec::Vec<Printer>,
}
impl VariableLengthFromBytes for PrintGetPrinterListReply {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
let list_count = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
let printers_length = list_count as usize;
let mut offset = 32;
let printers = crate::vec_from_bytes_var!(ptr, Printer, offset, printers_length,);
Ok((
Self {
response_type,
sequence,
length,
printers,
},
offset,
))
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintGetContextReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub context: u32,
}
impl FixedLengthFromBytes<12> for PrintGetContextReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
context: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
})
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintGetScreenOfContextReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub root: crate::proto::xproto::Window,
}
impl FixedLengthFromBytes<12> for PrintGetScreenOfContextReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
root: crate::proto::xproto::Window::from_bytes(
bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrintGetDocumentDataReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub status_code: u32,
pub finished_flag: u32,
pub data: alloc::vec::Vec<u8>,
}
impl VariableLengthFromBytes for PrintGetDocumentDataReply {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
let status_code = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
let finished_flag =
u32::from_bytes(ptr.get(12..16).ok_or(crate::error::Error::FromBytes)?)?;
let data_len = u32::from_bytes(ptr.get(16..20).ok_or(crate::error::Error::FromBytes)?)?;
let length_expr = data_len as usize;
let data: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
length_expr,
)?;
let offset = length_expr + 32;
Ok((
Self {
response_type,
sequence,
length,
status_code,
finished_flag,
data,
},
offset,
))
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintInputSelectedReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub event_mask: u32,
pub all_events_mask: u32,
}
impl FixedLengthFromBytes<16> for PrintInputSelectedReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
event_mask: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
all_events_mask: u32::from_bytes(
bytes.get(12..16).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrintGetAttributesReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub attributes: alloc::vec::Vec<String8>,
}
impl VariableLengthFromBytes for PrintGetAttributesReply {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
let string_len = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
let length_expr = string_len as usize;
let attributes: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
length_expr,
)?;
let offset = length_expr + 32;
Ok((
Self {
response_type,
sequence,
length,
attributes,
},
offset,
))
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrintGetOneAttributesReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub value: alloc::vec::Vec<String8>,
}
impl VariableLengthFromBytes for PrintGetOneAttributesReply {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
let value_len = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
let length_expr = value_len as usize;
let value: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
length_expr,
)?;
let offset = length_expr + 32;
Ok((
Self {
response_type,
sequence,
length,
value,
},
offset,
))
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintGetPageDimensionsReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub width: u16,
pub height: u16,
pub offset_x: u16,
pub offset_y: u16,
pub reproducible_width: u16,
pub reproducible_height: u16,
}
impl FixedLengthFromBytes<20> for PrintGetPageDimensionsReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
width: u16::from_bytes(bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?)?,
height: u16::from_bytes(bytes.get(10..12).ok_or(crate::error::Error::FromBytes)?)?,
offset_x: u16::from_bytes(bytes.get(12..14).ok_or(crate::error::Error::FromBytes)?)?,
offset_y: u16::from_bytes(bytes.get(14..16).ok_or(crate::error::Error::FromBytes)?)?,
reproducible_width: u16::from_bytes(
bytes.get(16..18).ok_or(crate::error::Error::FromBytes)?,
)?,
reproducible_height: u16::from_bytes(
bytes.get(18..20).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrintQueryScreensReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub roots: alloc::vec::Vec<crate::proto::xproto::Window>,
}
impl VariableLengthFromBytes for PrintQueryScreensReply {
fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
let ptr = bytes;
let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
let list_count = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
let length_expr = list_count as usize;
let roots: alloc::vec::Vec<crate::proto::xproto::Window> = crate::vec_from_bytes_fixed!(
ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
crate::proto::xproto::Window,
length_expr,
4
);
let offset = length_expr * 4 + 32;
Ok((
Self {
response_type,
sequence,
length,
roots,
},
offset,
))
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintSetImageResolutionReply {
pub response_type: u8,
pub status: u8,
pub sequence: u16,
pub length: u32,
pub previous_resolutions: u16,
}
impl FixedLengthFromBytes<10> for PrintSetImageResolutionReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
status: u8::from_bytes(bytes.get(1..2).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
previous_resolutions: u16::from_bytes(
bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct PrintGetImageResolutionReply {
pub response_type: u8,
pub sequence: u16,
pub length: u32,
pub image_resolution: u16,
}
impl FixedLengthFromBytes<10> for PrintGetImageResolutionReply {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
image_resolution: u16::from_bytes(
bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?,
)?,
})
}
}
pub const NOTIFY_EVENT: u8 = 0;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct NotifyEvent {
pub opcode: u8,
pub detail: u8,
pub sequence: u16,
pub context: Pcontext,
pub cancel: u8,
}
impl FixedLengthFromBytes<9> for NotifyEvent {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
opcode: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
detail: u8::from_bytes(bytes.get(1..2).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
context: Pcontext::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
cancel: u8::from_bytes(bytes.get(8..9).ok_or(crate::error::Error::FromBytes)?)?,
})
}
}
pub const ATTRIBUT_NOTIFY_EVENT: u8 = 1;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct AttributNotifyEvent {
pub opcode: u8,
pub detail: u8,
pub sequence: u16,
pub context: Pcontext,
}
impl FixedLengthFromBytes<8> for AttributNotifyEvent {
#[inline]
fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
Ok(Self {
opcode: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
detail: u8::from_bytes(bytes.get(1..2).ok_or(crate::error::Error::FromBytes)?)?,
sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
context: Pcontext::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
})
}
}
pub const BAD_CONTEXT_ERROR: u8 = 0;
pub const BAD_SEQUENCE_ERROR: u8 = 1;