1#![allow(clippy::identity_op)]
5
6use alloc::string::{String, ToString};
7use alloc::vec::Vec;
8
9use core::convert::TryInto;
10use core::fmt;
11
12pub fn read<T>(b: &[u8]) -> Result<T, ReadError>
13where
14 T: XimRead,
15{
16 T::read(&mut Reader::new(b))
17}
18
19pub fn write<T>(val: T, out: &mut [u8])
20where
21 T: XimWrite,
22{
23 val.write(&mut Writer::new(out));
24}
25
26#[derive(Copy, Clone, Debug, Eq, PartialEq)]
27#[repr(u8)]
28pub enum Endian {
29 #[cfg(target_endian = "little")]
30 Native = 0x6c,
31 #[cfg(target_endian = "big")]
32 Native = 0x42,
33 }
36
37#[derive(Clone, Debug, Eq, PartialEq)]
38pub enum StatusContent {
39 Text(StatusTextContent),
40 Pixmap(u32),
41}
42
43#[derive(Clone, Debug, Eq, PartialEq)]
44pub enum CommitData {
45 Keysym {
46 keysym: u32,
47 syncronous: bool,
48 },
49 Chars {
50 commited: Vec<u8>,
51 syncronous: bool,
52 },
53 Both {
54 keysym: u32,
55 commited: Vec<u8>,
56 syncronous: bool,
57 },
58}
59#[derive(Clone, Debug, Eq, PartialEq)]
60pub struct InputStyleList {
61 pub styles: Vec<InputStyle>,
62}
63impl XimRead for InputStyleList {
64 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
65 Ok(Self {
66 styles: {
67 let len = u16::read(reader)? as usize;
68 reader.consume(2)?;
69 let mut out = Vec::with_capacity(len);
70 for _ in 0..len {
71 out.push(InputStyle::read(reader)?);
72 }
73 out
74 },
75 })
76 }
77}
78impl XimWrite for InputStyleList {
79 fn write(&self, writer: &mut Writer) {
80 (self.styles.len() as u16).write(writer);
81 0u16.write(writer);
82 for elem in self.styles.iter() {
83 elem.write(writer);
84 }
85 }
86 fn size(&self) -> usize {
87 self.styles.len() * 4 + 4
88 }
89}
90
91#[derive(Clone, Debug, Eq, PartialEq)]
92pub struct HotKeyTriggers {
93 pub triggers: Vec<(TriggerKey, HotKeyState)>,
94}
95
96#[derive(Debug)]
97pub enum ReadError {
98 EndOfStream,
99 InvalidData(&'static str, String),
100 Utf8Error(alloc::string::FromUtf8Error),
101 NotNativeEndian,
102}
103
104impl From<alloc::string::FromUtf8Error> for ReadError {
105 fn from(e: alloc::string::FromUtf8Error) -> Self {
106 Self::Utf8Error(e)
107 }
108}
109
110impl fmt::Display for ReadError {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 match self {
113 Self::EndOfStream => write!(f, "End of Stream"),
114 Self::InvalidData(name, reason) => write!(f, "Invalid Data {}: {}", name, reason),
115 Self::Utf8Error(e) => write!(f, "Not a Utf8 text {}", e),
116 Self::NotNativeEndian => write!(f, "Not a native endian"),
117 }
118 }
119}
120
121#[cfg(feature = "std")]
122impl std::error::Error for ReadError {}
123
124fn pad4(len: usize) -> usize {
125 match len % 4 {
126 0 => 0,
127 x => 4 - x,
128 }
129}
130
131fn with_pad4(len: usize) -> usize {
132 len + pad4(len)
133}
134
135pub struct Reader<'b> {
136 bytes: &'b [u8],
137 start: usize,
138}
139
140impl<'b> Reader<'b> {
141 pub fn new(bytes: &'b [u8]) -> Self {
142 Self {
143 bytes,
144 start: bytes.as_ptr() as usize,
145 }
146 }
147
148 fn ptr_offset(&self) -> usize {
149 self.bytes.as_ptr() as usize - self.start
150 }
151
152 pub fn cursor(&self) -> usize {
153 self.bytes.len()
154 }
155
156 pub fn pad4(&mut self) -> Result<(), ReadError> {
157 self.consume(pad4(self.ptr_offset()))?;
158 Ok(())
159 }
160
161 #[inline(always)]
162 pub fn eos(&self) -> ReadError {
163 ReadError::EndOfStream
164 }
165
166 pub fn invalid_data(&self, ty: &'static str, item: impl ToString) -> ReadError {
167 ReadError::InvalidData(ty, item.to_string())
168 }
169
170 pub fn u8(&mut self) -> Result<u8, ReadError> {
171 let (b, new) = self.bytes.split_first().ok_or(ReadError::EndOfStream)?;
172 self.bytes = new;
173 Ok(*b)
174 }
175
176 pub fn i16(&mut self) -> Result<i16, ReadError> {
177 let bytes = self.consume(2)?.try_into().unwrap();
178 Ok(i16::from_ne_bytes(bytes))
179 }
180
181 pub fn u16(&mut self) -> Result<u16, ReadError> {
182 let bytes = self.consume(2)?.try_into().unwrap();
183 Ok(u16::from_ne_bytes(bytes))
184 }
185
186 pub fn u32(&mut self) -> Result<u32, ReadError> {
187 let bytes = self.consume(4)?.try_into().unwrap();
188 Ok(u32::from_ne_bytes(bytes))
189 }
190
191 pub fn i32(&mut self) -> Result<i32, ReadError> {
192 let bytes = self.consume(4)?.try_into().unwrap();
193 Ok(i32::from_ne_bytes(bytes))
194 }
195
196 pub fn consume(&mut self, len: usize) -> Result<&'b [u8], ReadError> {
197 if self.bytes.len() >= len {
198 let (out, new) = self.bytes.split_at(len);
199 self.bytes = new;
200 Ok(out)
201 } else {
202 Err(self.eos())
203 }
204 }
205}
206
207pub struct Writer<'b> {
208 out: &'b mut [u8],
209 idx: usize,
210}
211
212impl<'b> Writer<'b> {
213 pub fn new(out: &'b mut [u8]) -> Self {
214 Self { out, idx: 0 }
215 }
216
217 pub fn write_u8(&mut self, b: u8) {
218 self.out[self.idx] = b;
219 self.idx += 1;
220 }
221
222 pub fn write(&mut self, bytes: &[u8]) {
223 self.out[self.idx..self.idx + bytes.len()].copy_from_slice(bytes);
224 self.idx += bytes.len();
225 }
226
227 pub fn write_pad4(&mut self) {
228 let pad = pad4(self.idx);
229 let pad_bytes = [0; 4];
230 self.write(&pad_bytes[..pad]);
231 }
232}
233
234pub trait XimRead: Sized {
235 fn read(reader: &mut Reader) -> Result<Self, ReadError>;
236}
237
238pub trait XimWrite {
239 fn write(&self, writer: &mut Writer);
240 fn size(&self) -> usize;
242}
243
244impl<T> XimWrite for &T
245where
246 T: XimWrite,
247{
248 #[inline(always)]
249 fn write(&self, writer: &mut Writer) {
250 (**self).write(writer);
251 }
252 #[inline(always)]
253 fn size(&self) -> usize {
254 (**self).size()
255 }
256}
257
258impl XimRead for Endian {
259 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
260 let n = u8::read(reader)?;
261
262 if n == Endian::Native as u8 {
263 Ok(Self::Native)
264 } else {
265 Err(ReadError::NotNativeEndian)
266 }
267 }
268}
269
270impl XimWrite for Endian {
271 fn write(&self, writer: &mut Writer) {
272 (*self as u8).write(writer);
273 }
274
275 fn size(&self) -> usize {
276 1
277 }
278}
279
280impl XimRead for StatusContent {
281 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
282 let ty = u32::read(reader)?;
283
284 match ty {
285 0 => Ok(Self::Text(StatusTextContent::read(reader)?)),
286 1 => Ok(Self::Pixmap(u32::read(reader)?)),
287 _ => Err(reader.invalid_data("StatusContentType", ty)),
288 }
289 }
290}
291
292impl XimWrite for StatusContent {
293 fn write(&self, writer: &mut Writer) {
294 match self {
295 StatusContent::Text(content) => {
296 0u32.write(writer);
297 content.write(writer);
298 }
299 StatusContent::Pixmap(pixmap) => {
300 1u32.write(writer);
301 pixmap.write(writer);
302 }
303 }
304 }
305
306 fn size(&self) -> usize {
307 let size = match self {
308 StatusContent::Text(content) => content.size(),
309 StatusContent::Pixmap(pixmap) => core::mem::size_of_val(pixmap),
310 };
311
312 size + 4
313 }
314}
315
316impl XimRead for CommitData {
317 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
318 let ty = reader.u16()?;
319
320 match ty {
321 2 | 3 => {
322 let len = reader.u16()?;
323 let bytes = reader.consume(len as usize)?;
324 reader.pad4()?;
325 Ok(Self::Chars {
326 commited: bytes.to_vec(),
327 syncronous: ty == 5,
328 })
329 }
330 4 | 5 => {
331 reader.consume(2)?;
332 let keysym = reader.u32()?;
333 Ok(Self::Keysym {
334 keysym,
335 syncronous: ty == 3,
336 })
337 }
338 6 | 7 => {
339 reader.consume(2)?;
340 let keysym = reader.u32()?;
341 let len = reader.u16()?;
342 let bytes = reader.consume(len as usize)?;
343 reader.pad4()?;
344 Ok(Self::Both {
345 keysym,
346 commited: bytes.to_vec(),
347 syncronous: ty == 7,
348 })
349 }
350 _ => Err(reader.invalid_data("CommitDataType", ty)),
351 }
352 }
353}
354
355impl XimWrite for CommitData {
356 fn write(&self, writer: &mut Writer) {
357 match self {
358 Self::Chars {
359 commited,
360 syncronous,
361 } => {
362 let flag = if *syncronous { 3u16 } else { 2u16 };
363 flag.write(writer);
364 (commited.len() as u16).write(writer);
365 writer.write(&commited);
366 writer.write_pad4();
367 }
368 Self::Keysym { keysym, syncronous } => {
369 let flag = if *syncronous { 5u16 } else { 4u16 };
370 flag.write(writer);
371 0u16.write(writer);
372 keysym.write(writer);
373 }
374 Self::Both {
375 keysym,
376 commited,
377 syncronous,
378 } => {
379 let flag = if *syncronous { 7u16 } else { 6u16 };
380 flag.write(writer);
381 0u16.write(writer);
382 keysym.write(writer);
383 (commited.len() as u16).write(writer);
384 writer.write(&commited);
385 writer.write_pad4();
386 }
387 }
388 }
389
390 fn size(&self) -> usize {
391 match self {
392 Self::Keysym { .. } => with_pad4(6),
393 Self::Chars { commited, .. } => with_pad4(commited.len() + 4),
394 Self::Both { commited, .. } => with_pad4(commited.len() + 4 + 6),
395 }
396 }
397}
398
399impl XimRead for HotKeyTriggers {
400 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
401 let n = reader.u32()? as usize;
402 let mut out = Vec::with_capacity(n);
403
404 for _ in 0..n {
405 out.push((TriggerKey::read(reader)?, HotKeyState::Off));
406 }
407
408 for _ in 0..n {
409 out[n].1 = HotKeyState::read(reader)?;
410 }
411
412 Ok(Self { triggers: out })
413 }
414}
415
416impl XimWrite for HotKeyTriggers {
417 fn write(&self, writer: &mut Writer) {
418 (self.triggers.len() as u32).write(writer);
419
420 for (trigger, _) in self.triggers.iter() {
421 trigger.write(writer);
422 }
423
424 for (_, state) in self.triggers.iter() {
425 state.write(writer);
426 }
427 }
428
429 fn size(&self) -> usize {
430 self.triggers.len() * 8 + 4
431 }
432}
433
434impl XimRead for u8 {
435 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
436 reader.u8()
437 }
438}
439
440impl XimWrite for u8 {
441 fn write(&self, writer: &mut Writer) {
442 writer.write_u8(*self)
443 }
444
445 fn size(&self) -> usize {
446 1
447 }
448}
449
450impl XimRead for bool {
451 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
452 Ok(reader.u8()? != 0)
453 }
454}
455
456impl XimWrite for bool {
457 fn write(&self, writer: &mut Writer) {
458 writer.write_u8(*self as u8)
459 }
460
461 fn size(&self) -> usize {
462 1
463 }
464}
465
466macro_rules! impl_int {
467 ($ty:ident) => {
468 impl XimRead for $ty {
469 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
470 reader.$ty()
471 }
472 }
473
474 impl XimWrite for $ty {
475 fn write(&self, writer: &mut Writer) {
476 writer.write(&self.to_ne_bytes())
477 }
478
479 fn size(&self) -> usize {
480 core::mem::size_of::<$ty>()
481 }
482 }
483 };
484}
485
486impl_int!(u16);
487impl_int!(i16);
488impl_int!(u32);
489impl_int!(i32);
490#[derive(Clone, Copy, Debug, Eq, PartialEq)]
491#[repr(u16)]
492pub enum AttrType {
493 Separator = 0,
494 Byte = 1,
495 Word = 2,
496 Long = 3,
497 Char = 4,
498 Window = 5,
499 Style = 10,
500 XRectangle = 11,
501 XPoint = 12,
502 XFontSet = 13,
503 HotkeyTriggers = 15,
504 StringConversion = 17,
505 PreeditState = 18,
506 ResetState = 19,
507 NestedList = 32767,
508}
509impl XimRead for AttrType {
510 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
511 let repr = u16::read(reader)?;
512 match repr {
513 0 => Ok(Self::Separator),
514 1 => Ok(Self::Byte),
515 2 => Ok(Self::Word),
516 3 => Ok(Self::Long),
517 4 => Ok(Self::Char),
518 5 => Ok(Self::Window),
519 10 => Ok(Self::Style),
520 11 => Ok(Self::XRectangle),
521 12 => Ok(Self::XPoint),
522 13 => Ok(Self::XFontSet),
523 15 => Ok(Self::HotkeyTriggers),
524 17 => Ok(Self::StringConversion),
525 18 => Ok(Self::PreeditState),
526 19 => Ok(Self::ResetState),
527 32767 => Ok(Self::NestedList),
528 _ => Err(reader.invalid_data("AttrType", repr)),
529 }
530 }
531}
532impl XimWrite for AttrType {
533 fn write(&self, writer: &mut Writer) {
534 (*self as u16).write(writer);
535 }
536 fn size(&self) -> usize {
537 core::mem::size_of::<u16>()
538 }
539}
540#[derive(Clone, Copy, Debug, Eq, PartialEq)]
541#[repr(u32)]
542pub enum CaretDirection {
543 ForwardChar = 0,
544 BackwardChar = 1,
545 ForwardWord = 2,
546 BackwardWord = 3,
547 CaretUp = 4,
548 CaretDown = 5,
549 NextLine = 6,
550 PreviousLine = 7,
551 LineStart = 8,
552 LineEnd = 9,
553 AbsolutePosition = 10,
554 DontChange = 11,
555}
556impl XimRead for CaretDirection {
557 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
558 let repr = u32::read(reader)?;
559 match repr {
560 0 => Ok(Self::ForwardChar),
561 1 => Ok(Self::BackwardChar),
562 2 => Ok(Self::ForwardWord),
563 3 => Ok(Self::BackwardWord),
564 4 => Ok(Self::CaretUp),
565 5 => Ok(Self::CaretDown),
566 6 => Ok(Self::NextLine),
567 7 => Ok(Self::PreviousLine),
568 8 => Ok(Self::LineStart),
569 9 => Ok(Self::LineEnd),
570 10 => Ok(Self::AbsolutePosition),
571 11 => Ok(Self::DontChange),
572 _ => Err(reader.invalid_data("CaretDirection", repr)),
573 }
574 }
575}
576impl XimWrite for CaretDirection {
577 fn write(&self, writer: &mut Writer) {
578 (*self as u32).write(writer);
579 }
580 fn size(&self) -> usize {
581 core::mem::size_of::<u32>()
582 }
583}
584#[derive(Clone, Copy, Debug, Eq, PartialEq)]
585#[repr(u32)]
586pub enum CaretStyle {
587 Invisible = 0,
588 Primary = 1,
589 Secondary = 2,
590}
591impl XimRead for CaretStyle {
592 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
593 let repr = u32::read(reader)?;
594 match repr {
595 0 => Ok(Self::Invisible),
596 1 => Ok(Self::Primary),
597 2 => Ok(Self::Secondary),
598 _ => Err(reader.invalid_data("CaretStyle", repr)),
599 }
600 }
601}
602impl XimWrite for CaretStyle {
603 fn write(&self, writer: &mut Writer) {
604 (*self as u32).write(writer);
605 }
606 fn size(&self) -> usize {
607 core::mem::size_of::<u32>()
608 }
609}
610#[derive(Clone, Copy, Debug, Eq, PartialEq)]
611#[repr(u16)]
612pub enum ErrorCode {
613 BadAlloc = 1,
614 BadStyle = 2,
615 BadClientWindow = 3,
616 BadFocusWindow = 4,
617 BadArea = 5,
618 BadSpotLocation = 6,
619 BadColormap = 7,
620 BadAtom = 8,
621 BadPixel = 9,
622 BadPixmap = 10,
623 BadName = 11,
624 BadCursor = 12,
625 BadProtocol = 13,
626 BadForeground = 14,
627 BadBackground = 15,
628 LocaleNotSupported = 16,
629 BadSomething = 999,
630}
631impl XimRead for ErrorCode {
632 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
633 let repr = u16::read(reader)?;
634 match repr {
635 1 => Ok(Self::BadAlloc),
636 2 => Ok(Self::BadStyle),
637 3 => Ok(Self::BadClientWindow),
638 4 => Ok(Self::BadFocusWindow),
639 5 => Ok(Self::BadArea),
640 6 => Ok(Self::BadSpotLocation),
641 7 => Ok(Self::BadColormap),
642 8 => Ok(Self::BadAtom),
643 9 => Ok(Self::BadPixel),
644 10 => Ok(Self::BadPixmap),
645 11 => Ok(Self::BadName),
646 12 => Ok(Self::BadCursor),
647 13 => Ok(Self::BadProtocol),
648 14 => Ok(Self::BadForeground),
649 15 => Ok(Self::BadBackground),
650 16 => Ok(Self::LocaleNotSupported),
651 999 => Ok(Self::BadSomething),
652 _ => Err(reader.invalid_data("ErrorCode", repr)),
653 }
654 }
655}
656impl XimWrite for ErrorCode {
657 fn write(&self, writer: &mut Writer) {
658 (*self as u16).write(writer);
659 }
660 fn size(&self) -> usize {
661 core::mem::size_of::<u16>()
662 }
663}
664bitflags::bitflags! {
665#[derive(Clone, Copy, Debug, Eq, PartialEq)]
666pub struct ErrorFlag: u16 {
667const INPUT_METHOD_ID_VALID = 1;
668const INPUT_CONTEXT_ID_VALID = 2;
669}
670}
671impl XimRead for ErrorFlag {
672 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
673 let repr = u16::read(reader)?;
674 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("ErrorFlag", repr))
675 }
676}
677impl XimWrite for ErrorFlag {
678 fn write(&self, writer: &mut Writer) {
679 self.bits().write(writer);
680 }
681 fn size(&self) -> usize {
682 core::mem::size_of::<u16>()
683 }
684}
685bitflags::bitflags! {
686#[derive(Clone, Copy, Debug, Eq, PartialEq)]
687pub struct Feedback: u32 {
688const REVERSE = 1;
689const UNDERLINE = 2;
690const HIGHLIGHT = 4;
691const PRIMARY = 8;
692const SECONDARY = 16;
693const TERTIARY = 32;
694const VISIBLE_TO_FORWARD = 64;
695const VISIBLE_TO_BACKWARD = 128;
696const VISIBLE_CENTER = 256;
697}
698}
699impl XimRead for Feedback {
700 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
701 let repr = u32::read(reader)?;
702 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("Feedback", repr))
703 }
704}
705impl XimWrite for Feedback {
706 fn write(&self, writer: &mut Writer) {
707 self.bits().write(writer);
708 }
709 fn size(&self) -> usize {
710 core::mem::size_of::<u32>()
711 }
712}
713bitflags::bitflags! {
714#[derive(Clone, Copy, Debug, Eq, PartialEq)]
715pub struct ForwardEventFlag: u16 {
716const SYNCHRONOUS = 1;
717const REQUEST_FILTERING = 2;
718const REQUEST_LOOP_UPSTRING = 4;
719}
720}
721impl XimRead for ForwardEventFlag {
722 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
723 let repr = u16::read(reader)?;
724 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("ForwardEventFlag", repr))
725 }
726}
727impl XimWrite for ForwardEventFlag {
728 fn write(&self, writer: &mut Writer) {
729 self.bits().write(writer);
730 }
731 fn size(&self) -> usize {
732 core::mem::size_of::<u16>()
733 }
734}
735#[derive(Clone, Copy, Debug, Eq, PartialEq)]
736#[repr(u32)]
737pub enum HotKeyState {
738 On = 1,
739 Off = 2,
740}
741impl XimRead for HotKeyState {
742 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
743 let repr = u32::read(reader)?;
744 match repr {
745 1 => Ok(Self::On),
746 2 => Ok(Self::Off),
747 _ => Err(reader.invalid_data("HotKeyState", repr)),
748 }
749 }
750}
751impl XimWrite for HotKeyState {
752 fn write(&self, writer: &mut Writer) {
753 (*self as u32).write(writer);
754 }
755 fn size(&self) -> usize {
756 core::mem::size_of::<u32>()
757 }
758}
759bitflags::bitflags! {
760#[derive(Clone, Copy, Debug, Eq, PartialEq)]
761pub struct InputStyle: u32 {
762const PREEDIT_AREA = 1;
763const PREEDIT_CALLBACKS = 2;
764const PREEDIT_POSITION = 4;
765const PREEDIT_NOTHING = 8;
766const PREEDIT_NONE = 16;
767const STATUS_AREA = 256;
768const STATUS_CALLBACKS = 512;
769const STATUS_NOTHING = 1024;
770const STATUS_NONE = 2048;
771}
772}
773impl XimRead for InputStyle {
774 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
775 let repr = u32::read(reader)?;
776 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("InputStyle", repr))
777 }
778}
779impl XimWrite for InputStyle {
780 fn write(&self, writer: &mut Writer) {
781 self.bits().write(writer);
782 }
783 fn size(&self) -> usize {
784 core::mem::size_of::<u32>()
785 }
786}
787bitflags::bitflags! {
788#[derive(Clone, Copy, Debug, Eq, PartialEq)]
789pub struct PreeditDrawStatus: u32 {
790const NO_STRING = 1;
791const NO_FEEDBACK = 2;
792}
793}
794impl XimRead for PreeditDrawStatus {
795 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
796 let repr = u32::read(reader)?;
797 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("PreeditDrawStatus", repr))
798 }
799}
800impl XimWrite for PreeditDrawStatus {
801 fn write(&self, writer: &mut Writer) {
802 self.bits().write(writer);
803 }
804 fn size(&self) -> usize {
805 core::mem::size_of::<u32>()
806 }
807}
808bitflags::bitflags! {
809#[derive(Clone, Copy, Debug, Eq, PartialEq)]
810pub struct PreeditStateFlag: u32 {
811const UNKNOWN = 0;
812const ENABLE = 1;
813const DISABLE = 2;
814}
815}
816impl XimRead for PreeditStateFlag {
817 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
818 let repr = u32::read(reader)?;
819 Self::from_bits(repr).ok_or_else(|| reader.invalid_data("PreeditStateFlag", repr))
820 }
821}
822impl XimWrite for PreeditStateFlag {
823 fn write(&self, writer: &mut Writer) {
824 self.bits().write(writer);
825 }
826 fn size(&self) -> usize {
827 core::mem::size_of::<u32>()
828 }
829}
830#[derive(Clone, Copy, Debug, Eq, PartialEq)]
831#[repr(u32)]
832pub enum TriggerNotifyFlag {
833 OnKeyList = 0,
834 OffKeyList = 1,
835}
836impl XimRead for TriggerNotifyFlag {
837 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
838 let repr = u32::read(reader)?;
839 match repr {
840 0 => Ok(Self::OnKeyList),
841 1 => Ok(Self::OffKeyList),
842 _ => Err(reader.invalid_data("TriggerNotifyFlag", repr)),
843 }
844 }
845}
846impl XimWrite for TriggerNotifyFlag {
847 fn write(&self, writer: &mut Writer) {
848 (*self as u32).write(writer);
849 }
850 fn size(&self) -> usize {
851 core::mem::size_of::<u32>()
852 }
853}
854#[derive(Clone, Debug, Eq, PartialEq)]
855pub struct Attr {
856 pub id: u16,
857 pub ty: AttrType,
858 pub name: AttributeName,
859}
860impl XimRead for Attr {
861 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
862 Ok(Self {
863 id: u16::read(reader)?,
864 ty: AttrType::read(reader)?,
865 name: {
866 let inner = AttributeName::read(reader)?;
867 reader.pad4()?;
868 inner
869 },
870 })
871 }
872}
873impl XimWrite for Attr {
874 fn write(&self, writer: &mut Writer) {
875 self.id.write(writer);
876 self.ty.write(writer);
877 self.name.write(writer);
878 writer.write_pad4();
879 }
880 fn size(&self) -> usize {
881 let mut content_size = 0;
882 content_size += self.id.size();
883 content_size += self.ty.size();
884 content_size += with_pad4(self.name.size() - 0);
885 content_size
886 }
887}
888#[derive(Clone, Debug, Eq, PartialEq)]
889pub struct Attribute {
890 pub id: u16,
891 pub value: Vec<u8>,
892}
893impl XimRead for Attribute {
894 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
895 Ok(Self {
896 id: u16::read(reader)?,
897 value: {
898 let inner = {
899 let len = u16::read(reader)?;
900 reader.consume(len as usize)?.to_vec()
901 };
902 reader.pad4()?;
903 inner
904 },
905 })
906 }
907}
908impl XimWrite for Attribute {
909 fn write(&self, writer: &mut Writer) {
910 self.id.write(writer);
911 (self.value.len() as u16).write(writer);
912 writer.write(&self.value);
913 writer.write_pad4();
914 }
915 fn size(&self) -> usize {
916 let mut content_size = 0;
917 content_size += self.id.size();
918 content_size += with_pad4(self.value.len() + 2 - 2) + 2;
919 content_size
920 }
921}
922#[derive(Clone, Debug, Eq, PartialEq)]
923pub struct Extension {
924 pub major_opcode: u8,
925 pub minor_opcode: u8,
926 pub name: String,
927}
928impl XimRead for Extension {
929 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
930 Ok(Self {
931 major_opcode: u8::read(reader)?,
932 minor_opcode: u8::read(reader)?,
933 name: {
934 let inner = {
935 let len = u16::read(reader)?;
936 String::from_utf8(reader.consume(len as usize)?.to_vec())?
937 };
938 reader.pad4()?;
939 inner
940 },
941 })
942 }
943}
944impl XimWrite for Extension {
945 fn write(&self, writer: &mut Writer) {
946 self.major_opcode.write(writer);
947 self.minor_opcode.write(writer);
948 (self.name.len() as u16).write(writer);
949 writer.write(self.name.as_bytes());
950 writer.write_pad4();
951 }
952 fn size(&self) -> usize {
953 let mut content_size = 0;
954 content_size += self.major_opcode.size();
955 content_size += self.minor_opcode.size();
956 content_size += with_pad4(self.name.len() + 2 + 0 - 0);
957 content_size
958 }
959}
960#[derive(Clone, Debug, Eq, PartialEq)]
961pub struct FontSet {
962 pub name: String,
963}
964impl XimRead for FontSet {
965 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
966 Ok(Self {
967 name: {
968 let inner = {
969 let len = u16::read(reader)?;
970 String::from_utf8(reader.consume(len as usize)?.to_vec())?
971 };
972 reader.pad4()?;
973 inner
974 },
975 })
976 }
977}
978impl XimWrite for FontSet {
979 fn write(&self, writer: &mut Writer) {
980 (self.name.len() as u16).write(writer);
981 writer.write(self.name.as_bytes());
982 writer.write_pad4();
983 }
984 fn size(&self) -> usize {
985 let mut content_size = 0;
986 content_size += with_pad4(self.name.len() + 2 + 0 - 0);
987 content_size
988 }
989}
990#[derive(Clone, Debug, Eq, PartialEq)]
991pub struct Point {
992 pub x: i16,
993 pub y: i16,
994}
995impl XimRead for Point {
996 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
997 Ok(Self {
998 x: i16::read(reader)?,
999 y: i16::read(reader)?,
1000 })
1001 }
1002}
1003impl XimWrite for Point {
1004 fn write(&self, writer: &mut Writer) {
1005 self.x.write(writer);
1006 self.y.write(writer);
1007 }
1008 fn size(&self) -> usize {
1009 let mut content_size = 0;
1010 content_size += self.x.size();
1011 content_size += self.y.size();
1012 content_size
1013 }
1014}
1015#[derive(Clone, Debug, Eq, PartialEq)]
1016pub struct Rectangle {
1017 pub x: i16,
1018 pub y: i16,
1019 pub width: u16,
1020 pub height: u16,
1021}
1022impl XimRead for Rectangle {
1023 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1024 Ok(Self {
1025 x: i16::read(reader)?,
1026 y: i16::read(reader)?,
1027 width: u16::read(reader)?,
1028 height: u16::read(reader)?,
1029 })
1030 }
1031}
1032impl XimWrite for Rectangle {
1033 fn write(&self, writer: &mut Writer) {
1034 self.x.write(writer);
1035 self.y.write(writer);
1036 self.width.write(writer);
1037 self.height.write(writer);
1038 }
1039 fn size(&self) -> usize {
1040 let mut content_size = 0;
1041 content_size += self.x.size();
1042 content_size += self.y.size();
1043 content_size += self.width.size();
1044 content_size += self.height.size();
1045 content_size
1046 }
1047}
1048#[derive(Clone, Debug, Eq, PartialEq)]
1049pub struct StatusTextContent {
1050 pub status: PreeditDrawStatus,
1051 pub status_string: String,
1052 pub feedbacks: Vec<Feedback>,
1053}
1054impl XimRead for StatusTextContent {
1055 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1056 Ok(Self {
1057 status: PreeditDrawStatus::read(reader)?,
1058 status_string: {
1059 let inner = {
1060 let len = u16::read(reader)?;
1061 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1062 };
1063 reader.pad4()?;
1064 inner
1065 },
1066 feedbacks: {
1067 let mut out = Vec::new();
1068 let len = u16::read(reader)? as usize;
1069 let end = reader.cursor() - len;
1070 u16::read(reader)?;
1071 while reader.cursor() > end {
1072 out.push(Feedback::read(reader)?);
1073 }
1074 out
1075 },
1076 })
1077 }
1078}
1079impl XimWrite for StatusTextContent {
1080 fn write(&self, writer: &mut Writer) {
1081 self.status.write(writer);
1082 (self.status_string.len() as u16).write(writer);
1083 writer.write(self.status_string.as_bytes());
1084 writer.write_pad4();
1085 ((self.feedbacks.iter().map(|e| e.size()).sum::<usize>() + 2 + 2 - 2 - 2) as u16)
1086 .write(writer);
1087 0u16.write(writer);
1088 for elem in self.feedbacks.iter() {
1089 elem.write(writer);
1090 }
1091 }
1092 fn size(&self) -> usize {
1093 let mut content_size = 0;
1094 content_size += self.status.size();
1095 content_size += with_pad4(self.status_string.len() + 2 + 0 - 0);
1096 content_size += self.feedbacks.iter().map(|e| e.size()).sum::<usize>() + 2 + 2;
1097 content_size
1098 }
1099}
1100#[derive(Clone, Debug, Eq, PartialEq)]
1101pub struct TriggerKey {
1102 pub keysym: u32,
1103 pub modifier: u32,
1104 pub modifier_mask: u32,
1105}
1106impl XimRead for TriggerKey {
1107 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1108 Ok(Self {
1109 keysym: u32::read(reader)?,
1110 modifier: u32::read(reader)?,
1111 modifier_mask: u32::read(reader)?,
1112 })
1113 }
1114}
1115impl XimWrite for TriggerKey {
1116 fn write(&self, writer: &mut Writer) {
1117 self.keysym.write(writer);
1118 self.modifier.write(writer);
1119 self.modifier_mask.write(writer);
1120 }
1121 fn size(&self) -> usize {
1122 let mut content_size = 0;
1123 content_size += self.keysym.size();
1124 content_size += self.modifier.size();
1125 content_size += self.modifier_mask.size();
1126 content_size
1127 }
1128}
1129#[derive(Clone, Debug, Eq, PartialEq)]
1130pub struct XEvent {
1131 pub response_type: u8,
1132 pub detail: u8,
1133 pub sequence: u16,
1134 pub time: u32,
1135 pub root: u32,
1136 pub event: u32,
1137 pub child: u32,
1138 pub root_x: i16,
1139 pub root_y: i16,
1140 pub event_x: i16,
1141 pub event_y: i16,
1142 pub state: u16,
1143 pub same_screen: bool,
1144}
1145impl XimRead for XEvent {
1146 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1147 Ok(Self {
1148 response_type: u8::read(reader)?,
1149 detail: u8::read(reader)?,
1150 sequence: u16::read(reader)?,
1151 time: u32::read(reader)?,
1152 root: u32::read(reader)?,
1153 event: u32::read(reader)?,
1154 child: u32::read(reader)?,
1155 root_x: i16::read(reader)?,
1156 root_y: i16::read(reader)?,
1157 event_x: i16::read(reader)?,
1158 event_y: i16::read(reader)?,
1159 state: u16::read(reader)?,
1160 same_screen: {
1161 let inner = bool::read(reader)?;
1162 reader.consume(1)?;
1163 inner
1164 },
1165 })
1166 }
1167}
1168impl XimWrite for XEvent {
1169 fn write(&self, writer: &mut Writer) {
1170 self.response_type.write(writer);
1171 self.detail.write(writer);
1172 self.sequence.write(writer);
1173 self.time.write(writer);
1174 self.root.write(writer);
1175 self.event.write(writer);
1176 self.child.write(writer);
1177 self.root_x.write(writer);
1178 self.root_y.write(writer);
1179 self.event_x.write(writer);
1180 self.event_y.write(writer);
1181 self.state.write(writer);
1182 self.same_screen.write(writer);
1183 writer.write(&[0u8; 1]);
1184 }
1185 fn size(&self) -> usize {
1186 let mut content_size = 0;
1187 content_size += self.response_type.size();
1188 content_size += self.detail.size();
1189 content_size += self.sequence.size();
1190 content_size += self.time.size();
1191 content_size += self.root.size();
1192 content_size += self.event.size();
1193 content_size += self.child.size();
1194 content_size += self.root_x.size();
1195 content_size += self.root_y.size();
1196 content_size += self.event_x.size();
1197 content_size += self.event_y.size();
1198 content_size += self.state.size();
1199 content_size += self.same_screen.size() + 1;
1200 content_size
1201 }
1202}
1203#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)]
1204pub enum AttributeName {
1205 Area,
1206 AreaNeeded,
1207 Background,
1208 BackgroundPixmap,
1209 ClientWindow,
1210 ColorMap,
1211 Cursor,
1212 DestroyCallback,
1213 FilterEvents,
1214 FocusWindow,
1215 FontSet,
1216 Foreground,
1217 GeometryCallback,
1218 HotKey,
1219 HotKeyState,
1220 InputStyle,
1221 LineSpace,
1222 NestedList,
1223 PreeditAttributes,
1224 PreeditCaretCallback,
1225 PreeditDoneCallback,
1226 PreeditDrawCallback,
1227 PreeditStartCallback,
1228 PreeditState,
1229 PreeditStateNotifyCallback,
1230 QueryICValuesList,
1231 QueryIMValuesList,
1232 QueryInputStyle,
1233 R6PreeditCallback,
1234 ResetState,
1235 ResourceClass,
1236 ResourceName,
1237 SeparatorofNestedList,
1238 SpotLocation,
1239 StatusAttributes,
1240 StatusDoneCallback,
1241 StatusDrawCallback,
1242 StatusStartCallback,
1243 StdColorMap,
1244 StringConversion,
1245 StringConversionCallback,
1246 VisiblePosition,
1247}
1248impl AttributeName {
1249 pub fn name(self) -> &'static str {
1250 match self {
1251 Self::Area => "area",
1252 Self::AreaNeeded => "areaNeeded",
1253 Self::Background => "background",
1254 Self::BackgroundPixmap => "backgroundPixmap",
1255 Self::ClientWindow => "clientWindow",
1256 Self::ColorMap => "colorMap",
1257 Self::Cursor => "cursor",
1258 Self::DestroyCallback => "destroyCallback",
1259 Self::FilterEvents => "filterEvents",
1260 Self::FocusWindow => "focusWindow",
1261 Self::FontSet => "fontSet",
1262 Self::Foreground => "foreground",
1263 Self::GeometryCallback => "geometryCallback",
1264 Self::HotKey => "hotKey",
1265 Self::HotKeyState => "hotKeyState",
1266 Self::InputStyle => "inputStyle",
1267 Self::LineSpace => "lineSpace",
1268 Self::NestedList => "XNVaNestedList",
1269 Self::PreeditAttributes => "preeditAttributes",
1270 Self::PreeditCaretCallback => "preeditCaretCallback",
1271 Self::PreeditDoneCallback => "preeditDoneCallback",
1272 Self::PreeditDrawCallback => "preeditDrawCallback",
1273 Self::PreeditStartCallback => "preeditStartCallback",
1274 Self::PreeditState => "preeditState",
1275 Self::PreeditStateNotifyCallback => "preeditStateNotifyCallback",
1276 Self::QueryICValuesList => "queryICValuesList",
1277 Self::QueryIMValuesList => "queryIMValuesList",
1278 Self::QueryInputStyle => "queryInputStyle",
1279 Self::R6PreeditCallback => "r6PreeditCallback",
1280 Self::ResetState => "resetState",
1281 Self::ResourceClass => "resourceClass",
1282 Self::ResourceName => "resourceName",
1283 Self::SeparatorofNestedList => "separatorofNestedList",
1284 Self::SpotLocation => "spotLocation",
1285 Self::StatusAttributes => "statusAttributes",
1286 Self::StatusDoneCallback => "statusDoneCallback",
1287 Self::StatusDrawCallback => "statusDrawCallback",
1288 Self::StatusStartCallback => "statusStartCallback",
1289 Self::StdColorMap => "stdColorMap",
1290 Self::StringConversion => "stringConversion",
1291 Self::StringConversionCallback => "stringConversionCallback",
1292 Self::VisiblePosition => "visiblePosition",
1293 }
1294 }
1295}
1296impl XimRead for AttributeName {
1297 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1298 let len = u16::read(reader)?;
1299 match reader.consume(len as usize)? {
1300 b"area" => Ok(Self::Area),
1301 b"areaNeeded" => Ok(Self::AreaNeeded),
1302 b"background" => Ok(Self::Background),
1303 b"backgroundPixmap" => Ok(Self::BackgroundPixmap),
1304 b"clientWindow" => Ok(Self::ClientWindow),
1305 b"colorMap" => Ok(Self::ColorMap),
1306 b"cursor" => Ok(Self::Cursor),
1307 b"destroyCallback" => Ok(Self::DestroyCallback),
1308 b"filterEvents" => Ok(Self::FilterEvents),
1309 b"focusWindow" => Ok(Self::FocusWindow),
1310 b"fontSet" => Ok(Self::FontSet),
1311 b"foreground" => Ok(Self::Foreground),
1312 b"geometryCallback" => Ok(Self::GeometryCallback),
1313 b"hotKey" => Ok(Self::HotKey),
1314 b"hotKeyState" => Ok(Self::HotKeyState),
1315 b"inputStyle" => Ok(Self::InputStyle),
1316 b"lineSpace" => Ok(Self::LineSpace),
1317 b"XNVaNestedList" => Ok(Self::NestedList),
1318 b"preeditAttributes" => Ok(Self::PreeditAttributes),
1319 b"preeditCaretCallback" => Ok(Self::PreeditCaretCallback),
1320 b"preeditDoneCallback" => Ok(Self::PreeditDoneCallback),
1321 b"preeditDrawCallback" => Ok(Self::PreeditDrawCallback),
1322 b"preeditStartCallback" => Ok(Self::PreeditStartCallback),
1323 b"preeditState" => Ok(Self::PreeditState),
1324 b"preeditStateNotifyCallback" => Ok(Self::PreeditStateNotifyCallback),
1325 b"queryICValuesList" => Ok(Self::QueryICValuesList),
1326 b"queryIMValuesList" => Ok(Self::QueryIMValuesList),
1327 b"queryInputStyle" => Ok(Self::QueryInputStyle),
1328 b"r6PreeditCallback" => Ok(Self::R6PreeditCallback),
1329 b"resetState" => Ok(Self::ResetState),
1330 b"resourceClass" => Ok(Self::ResourceClass),
1331 b"resourceName" => Ok(Self::ResourceName),
1332 b"separatorofNestedList" => Ok(Self::SeparatorofNestedList),
1333 b"spotLocation" => Ok(Self::SpotLocation),
1334 b"statusAttributes" => Ok(Self::StatusAttributes),
1335 b"statusDoneCallback" => Ok(Self::StatusDoneCallback),
1336 b"statusDrawCallback" => Ok(Self::StatusDrawCallback),
1337 b"statusStartCallback" => Ok(Self::StatusStartCallback),
1338 b"stdColorMap" => Ok(Self::StdColorMap),
1339 b"stringConversion" => Ok(Self::StringConversion),
1340 b"stringConversionCallback" => Ok(Self::StringConversionCallback),
1341 b"visiblePosition" => Ok(Self::VisiblePosition),
1342 bytes => Err(reader.invalid_data(
1343 "AttributeName",
1344 core::str::from_utf8(bytes).unwrap_or("NOT_UTF8"),
1345 )),
1346 }
1347 }
1348}
1349impl XimWrite for AttributeName {
1350 fn write(&self, writer: &mut Writer) {
1351 let name = self.name();
1352 (name.len() as u16).write(writer);
1353 writer.write(name.as_bytes());
1354 }
1355 fn size(&self) -> usize {
1356 self.name().len() + 2
1357 }
1358}
1359#[derive(Debug, Clone, Eq, PartialEq)]
1360pub enum Request {
1361 AuthNext {},
1362 AuthNg {},
1363 AuthReply {},
1364 AuthRequired {},
1365 AuthSetup {},
1366 Close {
1367 input_method_id: u16,
1368 },
1369 CloseReply {
1370 input_method_id: u16,
1371 },
1372 Commit {
1373 input_method_id: u16,
1374 input_context_id: u16,
1375 data: CommitData,
1376 },
1377 Connect {
1378 endian: Endian,
1379 client_major_protocol_version: u16,
1380 client_minor_protocol_version: u16,
1381 client_auth_protocol_names: Vec<String>,
1382 },
1383 ConnectReply {
1384 server_major_protocol_version: u16,
1385 server_minor_protocol_version: u16,
1386 },
1387 CreateIc {
1388 input_method_id: u16,
1389 ic_attributes: Vec<Attribute>,
1390 },
1391 CreateIcReply {
1392 input_method_id: u16,
1393 input_context_id: u16,
1394 },
1395 DestroyIc {
1396 input_method_id: u16,
1397 input_context_id: u16,
1398 },
1399 DestroyIcReply {
1400 input_method_id: u16,
1401 input_context_id: u16,
1402 },
1403 Disconnect {},
1404 DisconnectReply {},
1405 EncodingNegotiation {
1406 input_method_id: u16,
1407 encodings: Vec<String>,
1408 encoding_infos: Vec<String>,
1409 },
1410 EncodingNegotiationReply {
1411 input_method_id: u16,
1412 category: u16,
1413 index: i16,
1414 },
1415 Error {
1416 input_method_id: u16,
1417 input_context_id: u16,
1418 flag: ErrorFlag,
1419 code: ErrorCode,
1420 detail: String,
1421 },
1422 ForwardEvent {
1423 input_method_id: u16,
1424 input_context_id: u16,
1425 flag: ForwardEventFlag,
1426 serial_number: u16,
1427 xev: XEvent,
1428 },
1429 Geometry {
1430 input_method_id: u16,
1431 input_context_id: u16,
1432 },
1433 GetIcValues {
1434 input_method_id: u16,
1435 input_context_id: u16,
1436 ic_attributes: Vec<u16>,
1437 },
1438 GetIcValuesReply {
1439 input_method_id: u16,
1440 input_context_id: u16,
1441 ic_attributes: Vec<Attribute>,
1442 },
1443 GetImValues {
1444 input_method_id: u16,
1445 im_attributes: Vec<u16>,
1446 },
1447 GetImValuesReply {
1448 input_method_id: u16,
1449 im_attributes: Vec<Attribute>,
1450 },
1451 Open {
1452 locale: String,
1453 },
1454 OpenReply {
1455 input_method_id: u16,
1456 im_attrs: Vec<Attr>,
1457 ic_attrs: Vec<Attr>,
1458 },
1459 PreeditCaret {
1460 input_method_id: u16,
1461 input_context_id: u16,
1462 position: i32,
1463 direction: CaretDirection,
1464 style: CaretStyle,
1465 },
1466 PreeditCaretReply {
1467 input_method_id: u16,
1468 input_context_id: u16,
1469 position: i32,
1470 },
1471 PreeditDone {
1472 input_method_id: u16,
1473 input_context_id: u16,
1474 },
1475 PreeditDraw {
1476 input_method_id: u16,
1477 input_context_id: u16,
1478 caret: i32,
1479 chg_first: i32,
1480 chg_length: i32,
1481 status: PreeditDrawStatus,
1482 preedit_string: Vec<u8>,
1483 feedbacks: Vec<Feedback>,
1484 },
1485 PreeditStart {
1486 input_method_id: u16,
1487 input_context_id: u16,
1488 },
1489 PreeditStartReply {
1490 input_method_id: u16,
1491 input_context_id: u16,
1492 return_value: i32,
1493 },
1494 PreeditState {
1495 input_method_id: u16,
1496 input_context_id: u16,
1497 state: PreeditStateFlag,
1498 },
1499 QueryExtension {
1500 input_method_id: u16,
1501 extensions: Vec<String>,
1502 },
1503 QueryExtensionReply {
1504 input_method_id: u16,
1505 extensions: Vec<Extension>,
1506 },
1507 RegisterTriggerKeys {
1508 input_method_id: u16,
1509 on_keys: Vec<TriggerKey>,
1510 off_keys: Vec<TriggerKey>,
1511 },
1512 ResetIc {
1513 input_method_id: u16,
1514 input_context_id: u16,
1515 },
1516 ResetIcReply {
1517 input_method_id: u16,
1518 input_context_id: u16,
1519 preedit_string: Vec<u8>,
1520 },
1521 SetEventMask {
1522 input_method_id: u16,
1523 input_context_id: u16,
1524 forward_event_mask: u32,
1525 synchronous_event_mask: u32,
1526 },
1527 SetIcFocus {
1528 input_method_id: u16,
1529 input_context_id: u16,
1530 },
1531 SetIcValues {
1532 input_method_id: u16,
1533 input_context_id: u16,
1534 ic_attributes: Vec<Attribute>,
1535 },
1536 SetIcValuesReply {
1537 input_method_id: u16,
1538 input_context_id: u16,
1539 },
1540 SetImValues {
1541 input_method_id: u16,
1542 attributes: Vec<Attribute>,
1543 },
1544 SetImValuesReply {
1545 input_method_id: u16,
1546 },
1547 StatusDone {
1548 input_method_id: u16,
1549 input_context_id: u16,
1550 },
1551 StatusDraw {
1552 input_method_id: u16,
1553 input_context_id: u16,
1554 content: StatusContent,
1555 },
1556 StatusStart {
1557 input_method_id: u16,
1558 input_context_id: u16,
1559 },
1560 StrConversion {},
1561 StrConversionReply {},
1562 Sync {
1563 input_method_id: u16,
1564 input_context_id: u16,
1565 },
1566 SyncReply {
1567 input_method_id: u16,
1568 input_context_id: u16,
1569 },
1570 TriggerNotify {
1571 input_method_id: u16,
1572 input_context_id: u16,
1573 flag: TriggerNotifyFlag,
1574 index: u32,
1575 event_mask: u32,
1576 },
1577 TriggerNotifyReply {
1578 input_method_id: u16,
1579 input_context_id: u16,
1580 },
1581 UnsetIcFocus {
1582 input_method_id: u16,
1583 input_context_id: u16,
1584 },
1585}
1586impl Request {
1587 pub fn name(&self) -> &'static str {
1588 match self {
1589 Request::AuthNext { .. } => "AuthNext",
1590 Request::AuthNg { .. } => "AuthNg",
1591 Request::AuthReply { .. } => "AuthReply",
1592 Request::AuthRequired { .. } => "AuthRequired",
1593 Request::AuthSetup { .. } => "AuthSetup",
1594 Request::Close { .. } => "Close",
1595 Request::CloseReply { .. } => "CloseReply",
1596 Request::Commit { .. } => "Commit",
1597 Request::Connect { .. } => "Connect",
1598 Request::ConnectReply { .. } => "ConnectReply",
1599 Request::CreateIc { .. } => "CreateIc",
1600 Request::CreateIcReply { .. } => "CreateIcReply",
1601 Request::DestroyIc { .. } => "DestroyIc",
1602 Request::DestroyIcReply { .. } => "DestroyIcReply",
1603 Request::Disconnect { .. } => "Disconnect",
1604 Request::DisconnectReply { .. } => "DisconnectReply",
1605 Request::EncodingNegotiation { .. } => "EncodingNegotiation",
1606 Request::EncodingNegotiationReply { .. } => "EncodingNegotiationReply",
1607 Request::Error { .. } => "Error",
1608 Request::ForwardEvent { .. } => "ForwardEvent",
1609 Request::Geometry { .. } => "Geometry",
1610 Request::GetIcValues { .. } => "GetIcValues",
1611 Request::GetIcValuesReply { .. } => "GetIcValuesReply",
1612 Request::GetImValues { .. } => "GetImValues",
1613 Request::GetImValuesReply { .. } => "GetImValuesReply",
1614 Request::Open { .. } => "Open",
1615 Request::OpenReply { .. } => "OpenReply",
1616 Request::PreeditCaret { .. } => "PreeditCaret",
1617 Request::PreeditCaretReply { .. } => "PreeditCaretReply",
1618 Request::PreeditDone { .. } => "PreeditDone",
1619 Request::PreeditDraw { .. } => "PreeditDraw",
1620 Request::PreeditStart { .. } => "PreeditStart",
1621 Request::PreeditStartReply { .. } => "PreeditStartReply",
1622 Request::PreeditState { .. } => "PreeditState",
1623 Request::QueryExtension { .. } => "QueryExtension",
1624 Request::QueryExtensionReply { .. } => "QueryExtensionReply",
1625 Request::RegisterTriggerKeys { .. } => "RegisterTriggerKeys",
1626 Request::ResetIc { .. } => "ResetIc",
1627 Request::ResetIcReply { .. } => "ResetIcReply",
1628 Request::SetEventMask { .. } => "SetEventMask",
1629 Request::SetIcFocus { .. } => "SetIcFocus",
1630 Request::SetIcValues { .. } => "SetIcValues",
1631 Request::SetIcValuesReply { .. } => "SetIcValuesReply",
1632 Request::SetImValues { .. } => "SetImValues",
1633 Request::SetImValuesReply { .. } => "SetImValuesReply",
1634 Request::StatusDone { .. } => "StatusDone",
1635 Request::StatusDraw { .. } => "StatusDraw",
1636 Request::StatusStart { .. } => "StatusStart",
1637 Request::StrConversion { .. } => "StrConversion",
1638 Request::StrConversionReply { .. } => "StrConversionReply",
1639 Request::Sync { .. } => "Sync",
1640 Request::SyncReply { .. } => "SyncReply",
1641 Request::TriggerNotify { .. } => "TriggerNotify",
1642 Request::TriggerNotifyReply { .. } => "TriggerNotifyReply",
1643 Request::UnsetIcFocus { .. } => "UnsetIcFocus",
1644 }
1645 }
1646}
1647impl XimRead for Request {
1648 fn read(reader: &mut Reader) -> Result<Self, ReadError> {
1649 let major_opcode = reader.u8()?;
1650 let minor_opcode = reader.u8()?;
1651 let _length = reader.u16()?;
1652 match (major_opcode, minor_opcode) {
1653 (12, _) => Ok(Request::AuthNext {}),
1654 (14, _) => Ok(Request::AuthNg {}),
1655 (11, _) => Ok(Request::AuthReply {}),
1656 (10, _) => Ok(Request::AuthRequired {}),
1657 (13, _) => Ok(Request::AuthSetup {}),
1658 (32, _) => Ok(Request::Close {
1659 input_method_id: {
1660 let inner = u16::read(reader)?;
1661 reader.consume(2)?;
1662 inner
1663 },
1664 }),
1665 (33, _) => Ok(Request::CloseReply {
1666 input_method_id: {
1667 let inner = u16::read(reader)?;
1668 reader.consume(2)?;
1669 inner
1670 },
1671 }),
1672 (63, _) => Ok(Request::Commit {
1673 input_method_id: u16::read(reader)?,
1674 input_context_id: u16::read(reader)?,
1675 data: CommitData::read(reader)?,
1676 }),
1677 (1, _) => Ok(Request::Connect {
1678 endian: {
1679 let inner = Endian::read(reader)?;
1680 reader.consume(1)?;
1681 inner
1682 },
1683 client_major_protocol_version: u16::read(reader)?,
1684 client_minor_protocol_version: u16::read(reader)?,
1685 client_auth_protocol_names: {
1686 let mut out = Vec::new();
1687 let len = u16::read(reader)? as usize;
1688 let end = reader.cursor() - len;
1689 while reader.cursor() > end {
1690 out.push({
1691 let inner = {
1692 let len = u16::read(reader)?;
1693 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1694 };
1695 reader.pad4()?;
1696 inner
1697 });
1698 }
1699 out
1700 },
1701 }),
1702 (2, _) => Ok(Request::ConnectReply {
1703 server_major_protocol_version: u16::read(reader)?,
1704 server_minor_protocol_version: u16::read(reader)?,
1705 }),
1706 (50, _) => Ok(Request::CreateIc {
1707 input_method_id: u16::read(reader)?,
1708 ic_attributes: {
1709 let mut out = Vec::new();
1710 let len = u16::read(reader)? as usize;
1711 let end = reader.cursor() - len;
1712 while reader.cursor() > end {
1713 out.push(Attribute::read(reader)?);
1714 }
1715 out
1716 },
1717 }),
1718 (51, _) => Ok(Request::CreateIcReply {
1719 input_method_id: u16::read(reader)?,
1720 input_context_id: u16::read(reader)?,
1721 }),
1722 (52, _) => Ok(Request::DestroyIc {
1723 input_method_id: u16::read(reader)?,
1724 input_context_id: u16::read(reader)?,
1725 }),
1726 (53, _) => Ok(Request::DestroyIcReply {
1727 input_method_id: u16::read(reader)?,
1728 input_context_id: u16::read(reader)?,
1729 }),
1730 (3, _) => Ok(Request::Disconnect {}),
1731 (4, _) => Ok(Request::DisconnectReply {}),
1732 (38, _) => Ok(Request::EncodingNegotiation {
1733 input_method_id: u16::read(reader)?,
1734 encodings: {
1735 let inner = {
1736 let mut out = Vec::new();
1737 let len = u16::read(reader)? as usize;
1738 let end = reader.cursor() - len;
1739 while reader.cursor() > end {
1740 out.push({
1741 let len = u8::read(reader)?;
1742 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1743 });
1744 }
1745 out
1746 };
1747 reader.pad4()?;
1748 inner
1749 },
1750 encoding_infos: {
1751 let mut out = Vec::new();
1752 let len = u16::read(reader)? as usize;
1753 let end = reader.cursor() - len;
1754 u16::read(reader)?;
1755 while reader.cursor() > end {
1756 out.push({
1757 let inner = {
1758 let len = u16::read(reader)?;
1759 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1760 };
1761 reader.pad4()?;
1762 inner
1763 });
1764 }
1765 out
1766 },
1767 }),
1768 (39, _) => Ok(Request::EncodingNegotiationReply {
1769 input_method_id: u16::read(reader)?,
1770 category: u16::read(reader)?,
1771 index: {
1772 let inner = i16::read(reader)?;
1773 reader.consume(2)?;
1774 inner
1775 },
1776 }),
1777 (20, _) => Ok(Request::Error {
1778 input_method_id: u16::read(reader)?,
1779 input_context_id: u16::read(reader)?,
1780 flag: ErrorFlag::read(reader)?,
1781 code: ErrorCode::read(reader)?,
1782 detail: {
1783 let inner = {
1784 let len = u16::read(reader)?;
1785 reader.consume(2)?;
1786 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1787 };
1788 reader.pad4()?;
1789 inner
1790 },
1791 }),
1792 (60, _) => Ok(Request::ForwardEvent {
1793 input_method_id: u16::read(reader)?,
1794 input_context_id: u16::read(reader)?,
1795 flag: ForwardEventFlag::read(reader)?,
1796 serial_number: u16::read(reader)?,
1797 xev: XEvent::read(reader)?,
1798 }),
1799 (70, _) => Ok(Request::Geometry {
1800 input_method_id: u16::read(reader)?,
1801 input_context_id: u16::read(reader)?,
1802 }),
1803 (56, _) => Ok(Request::GetIcValues {
1804 input_method_id: u16::read(reader)?,
1805 input_context_id: u16::read(reader)?,
1806 ic_attributes: {
1807 let inner = {
1808 let mut out = Vec::new();
1809 let len = u16::read(reader)? as usize;
1810 let end = reader.cursor() - len;
1811 while reader.cursor() > end {
1812 out.push(u16::read(reader)?);
1813 }
1814 out
1815 };
1816 reader.pad4()?;
1817 inner
1818 },
1819 }),
1820 (57, _) => Ok(Request::GetIcValuesReply {
1821 input_method_id: u16::read(reader)?,
1822 input_context_id: u16::read(reader)?,
1823 ic_attributes: {
1824 let mut out = Vec::new();
1825 let len = u16::read(reader)? as usize;
1826 let end = reader.cursor() - len;
1827 u16::read(reader)?;
1828 while reader.cursor() > end {
1829 out.push(Attribute::read(reader)?);
1830 }
1831 out
1832 },
1833 }),
1834 (44, _) => Ok(Request::GetImValues {
1835 input_method_id: u16::read(reader)?,
1836 im_attributes: {
1837 let inner = {
1838 let mut out = Vec::new();
1839 let len = u16::read(reader)? as usize;
1840 let end = reader.cursor() - len;
1841 while reader.cursor() > end {
1842 out.push(u16::read(reader)?);
1843 }
1844 out
1845 };
1846 reader.pad4()?;
1847 inner
1848 },
1849 }),
1850 (45, _) => Ok(Request::GetImValuesReply {
1851 input_method_id: u16::read(reader)?,
1852 im_attributes: {
1853 let mut out = Vec::new();
1854 let len = u16::read(reader)? as usize;
1855 let end = reader.cursor() - len;
1856 while reader.cursor() > end {
1857 out.push(Attribute::read(reader)?);
1858 }
1859 out
1860 },
1861 }),
1862 (30, _) => Ok(Request::Open {
1863 locale: {
1864 let inner = {
1865 let len = u8::read(reader)?;
1866 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1867 };
1868 reader.pad4()?;
1869 inner
1870 },
1871 }),
1872 (31, _) => Ok(Request::OpenReply {
1873 input_method_id: u16::read(reader)?,
1874 im_attrs: {
1875 let mut out = Vec::new();
1876 let len = u16::read(reader)? as usize;
1877 let end = reader.cursor() - len;
1878 while reader.cursor() > end {
1879 out.push(Attr::read(reader)?);
1880 }
1881 out
1882 },
1883 ic_attrs: {
1884 let mut out = Vec::new();
1885 let len = u16::read(reader)? as usize;
1886 let end = reader.cursor() - len;
1887 u16::read(reader)?;
1888 while reader.cursor() > end {
1889 out.push(Attr::read(reader)?);
1890 }
1891 out
1892 },
1893 }),
1894 (76, _) => Ok(Request::PreeditCaret {
1895 input_method_id: u16::read(reader)?,
1896 input_context_id: u16::read(reader)?,
1897 position: i32::read(reader)?,
1898 direction: CaretDirection::read(reader)?,
1899 style: CaretStyle::read(reader)?,
1900 }),
1901 (77, _) => Ok(Request::PreeditCaretReply {
1902 input_method_id: u16::read(reader)?,
1903 input_context_id: u16::read(reader)?,
1904 position: i32::read(reader)?,
1905 }),
1906 (78, _) => Ok(Request::PreeditDone {
1907 input_method_id: u16::read(reader)?,
1908 input_context_id: u16::read(reader)?,
1909 }),
1910 (75, _) => Ok(Request::PreeditDraw {
1911 input_method_id: u16::read(reader)?,
1912 input_context_id: u16::read(reader)?,
1913 caret: i32::read(reader)?,
1914 chg_first: i32::read(reader)?,
1915 chg_length: i32::read(reader)?,
1916 status: PreeditDrawStatus::read(reader)?,
1917 preedit_string: {
1918 let inner = {
1919 let len = u16::read(reader)?;
1920 reader.consume(len as usize)?.to_vec()
1921 };
1922 reader.pad4()?;
1923 inner
1924 },
1925 feedbacks: {
1926 let mut out = Vec::new();
1927 let len = u16::read(reader)? as usize;
1928 let end = reader.cursor() - len;
1929 u16::read(reader)?;
1930 while reader.cursor() > end {
1931 out.push(Feedback::read(reader)?);
1932 }
1933 out
1934 },
1935 }),
1936 (73, _) => Ok(Request::PreeditStart {
1937 input_method_id: u16::read(reader)?,
1938 input_context_id: u16::read(reader)?,
1939 }),
1940 (74, _) => Ok(Request::PreeditStartReply {
1941 input_method_id: u16::read(reader)?,
1942 input_context_id: u16::read(reader)?,
1943 return_value: i32::read(reader)?,
1944 }),
1945 (82, _) => Ok(Request::PreeditState {
1946 input_method_id: u16::read(reader)?,
1947 input_context_id: u16::read(reader)?,
1948 state: PreeditStateFlag::read(reader)?,
1949 }),
1950 (40, _) => Ok(Request::QueryExtension {
1951 input_method_id: u16::read(reader)?,
1952 extensions: {
1953 let inner = {
1954 let mut out = Vec::new();
1955 let len = u16::read(reader)? as usize;
1956 let end = reader.cursor() - len;
1957 while reader.cursor() > end {
1958 out.push({
1959 let len = u8::read(reader)?;
1960 String::from_utf8(reader.consume(len as usize)?.to_vec())?
1961 });
1962 }
1963 out
1964 };
1965 reader.pad4()?;
1966 inner
1967 },
1968 }),
1969 (41, _) => Ok(Request::QueryExtensionReply {
1970 input_method_id: u16::read(reader)?,
1971 extensions: {
1972 let mut out = Vec::new();
1973 let len = u16::read(reader)? as usize;
1974 let end = reader.cursor() - len;
1975 while reader.cursor() > end {
1976 out.push(Extension::read(reader)?);
1977 }
1978 out
1979 },
1980 }),
1981 (34, _) => Ok(Request::RegisterTriggerKeys {
1982 input_method_id: {
1983 let inner = u16::read(reader)?;
1984 reader.consume(2)?;
1985 inner
1986 },
1987 on_keys: {
1988 let mut out = Vec::new();
1989 let len = u32::read(reader)? as usize;
1990 let end = reader.cursor() - len;
1991 while reader.cursor() > end {
1992 out.push(TriggerKey::read(reader)?);
1993 }
1994 out
1995 },
1996 off_keys: {
1997 let mut out = Vec::new();
1998 let len = u32::read(reader)? as usize;
1999 let end = reader.cursor() - len;
2000 while reader.cursor() > end {
2001 out.push(TriggerKey::read(reader)?);
2002 }
2003 out
2004 },
2005 }),
2006 (64, _) => Ok(Request::ResetIc {
2007 input_method_id: u16::read(reader)?,
2008 input_context_id: u16::read(reader)?,
2009 }),
2010 (65, _) => Ok(Request::ResetIcReply {
2011 input_method_id: u16::read(reader)?,
2012 input_context_id: u16::read(reader)?,
2013 preedit_string: {
2014 let inner = {
2015 let len = u16::read(reader)?;
2016 reader.consume(len as usize)?.to_vec()
2017 };
2018 reader.pad4()?;
2019 inner
2020 },
2021 }),
2022 (37, _) => Ok(Request::SetEventMask {
2023 input_method_id: u16::read(reader)?,
2024 input_context_id: u16::read(reader)?,
2025 forward_event_mask: u32::read(reader)?,
2026 synchronous_event_mask: u32::read(reader)?,
2027 }),
2028 (58, _) => Ok(Request::SetIcFocus {
2029 input_method_id: u16::read(reader)?,
2030 input_context_id: u16::read(reader)?,
2031 }),
2032 (54, _) => Ok(Request::SetIcValues {
2033 input_method_id: u16::read(reader)?,
2034 input_context_id: u16::read(reader)?,
2035 ic_attributes: {
2036 let mut out = Vec::new();
2037 let len = u16::read(reader)? as usize;
2038 let end = reader.cursor() - len;
2039 u16::read(reader)?;
2040 while reader.cursor() > end {
2041 out.push(Attribute::read(reader)?);
2042 }
2043 out
2044 },
2045 }),
2046 (55, _) => Ok(Request::SetIcValuesReply {
2047 input_method_id: u16::read(reader)?,
2048 input_context_id: u16::read(reader)?,
2049 }),
2050 (42, _) => Ok(Request::SetImValues {
2051 input_method_id: u16::read(reader)?,
2052 attributes: {
2053 let mut out = Vec::new();
2054 let len = u16::read(reader)? as usize;
2055 let end = reader.cursor() - len;
2056 while reader.cursor() > end {
2057 out.push(Attribute::read(reader)?);
2058 }
2059 out
2060 },
2061 }),
2062 (43, _) => Ok(Request::SetImValuesReply {
2063 input_method_id: {
2064 let inner = u16::read(reader)?;
2065 reader.consume(2)?;
2066 inner
2067 },
2068 }),
2069 (81, _) => Ok(Request::StatusDone {
2070 input_method_id: u16::read(reader)?,
2071 input_context_id: u16::read(reader)?,
2072 }),
2073 (80, _) => Ok(Request::StatusDraw {
2074 input_method_id: u16::read(reader)?,
2075 input_context_id: u16::read(reader)?,
2076 content: StatusContent::read(reader)?,
2077 }),
2078 (79, _) => Ok(Request::StatusStart {
2079 input_method_id: u16::read(reader)?,
2080 input_context_id: u16::read(reader)?,
2081 }),
2082 (71, _) => Ok(Request::StrConversion {}),
2083 (72, _) => Ok(Request::StrConversionReply {}),
2084 (61, _) => Ok(Request::Sync {
2085 input_method_id: u16::read(reader)?,
2086 input_context_id: u16::read(reader)?,
2087 }),
2088 (62, _) => Ok(Request::SyncReply {
2089 input_method_id: u16::read(reader)?,
2090 input_context_id: u16::read(reader)?,
2091 }),
2092 (35, _) => Ok(Request::TriggerNotify {
2093 input_method_id: u16::read(reader)?,
2094 input_context_id: u16::read(reader)?,
2095 flag: TriggerNotifyFlag::read(reader)?,
2096 index: u32::read(reader)?,
2097 event_mask: u32::read(reader)?,
2098 }),
2099 (36, _) => Ok(Request::TriggerNotifyReply {
2100 input_method_id: u16::read(reader)?,
2101 input_context_id: u16::read(reader)?,
2102 }),
2103 (59, _) => Ok(Request::UnsetIcFocus {
2104 input_method_id: u16::read(reader)?,
2105 input_context_id: u16::read(reader)?,
2106 }),
2107 _ => Err(reader.invalid_data(
2108 "Opcode",
2109 alloc::format!("({}, {})", major_opcode, minor_opcode),
2110 )),
2111 }
2112 }
2113}
2114impl XimWrite for Request {
2115 fn write(&self, writer: &mut Writer) {
2116 match self {
2117 Request::AuthNext {} => {
2118 12u8.write(writer);
2119 0u8.write(writer);
2120 (((self.size() - 4) / 4) as u16).write(writer);
2121 }
2122 Request::AuthNg {} => {
2123 14u8.write(writer);
2124 0u8.write(writer);
2125 (((self.size() - 4) / 4) as u16).write(writer);
2126 }
2127 Request::AuthReply {} => {
2128 11u8.write(writer);
2129 0u8.write(writer);
2130 (((self.size() - 4) / 4) as u16).write(writer);
2131 }
2132 Request::AuthRequired {} => {
2133 10u8.write(writer);
2134 0u8.write(writer);
2135 (((self.size() - 4) / 4) as u16).write(writer);
2136 }
2137 Request::AuthSetup {} => {
2138 13u8.write(writer);
2139 0u8.write(writer);
2140 (((self.size() - 4) / 4) as u16).write(writer);
2141 }
2142 Request::Close { input_method_id } => {
2143 32u8.write(writer);
2144 0u8.write(writer);
2145 (((self.size() - 4) / 4) as u16).write(writer);
2146 input_method_id.write(writer);
2147 writer.write(&[0u8; 2]);
2148 }
2149 Request::CloseReply { input_method_id } => {
2150 33u8.write(writer);
2151 0u8.write(writer);
2152 (((self.size() - 4) / 4) as u16).write(writer);
2153 input_method_id.write(writer);
2154 writer.write(&[0u8; 2]);
2155 }
2156 Request::Commit {
2157 input_method_id,
2158 input_context_id,
2159 data,
2160 } => {
2161 63u8.write(writer);
2162 0u8.write(writer);
2163 (((self.size() - 4) / 4) as u16).write(writer);
2164 input_method_id.write(writer);
2165 input_context_id.write(writer);
2166 data.write(writer);
2167 }
2168 Request::Connect {
2169 endian,
2170 client_major_protocol_version,
2171 client_minor_protocol_version,
2172 client_auth_protocol_names,
2173 } => {
2174 1u8.write(writer);
2175 0u8.write(writer);
2176 (((self.size() - 4) / 4) as u16).write(writer);
2177 endian.write(writer);
2178 writer.write(&[0u8; 1]);
2179 client_major_protocol_version.write(writer);
2180 client_minor_protocol_version.write(writer);
2181 ((client_auth_protocol_names
2182 .iter()
2183 .map(|e| with_pad4(e.len() + 2 + 0 - 0))
2184 .sum::<usize>()
2185 + 0
2186 + 2
2187 - 2
2188 - 0) as u16)
2189 .write(writer);
2190 for elem in client_auth_protocol_names.iter() {
2191 (elem.len() as u16).write(writer);
2192 writer.write(elem.as_bytes());
2193 writer.write_pad4();
2194 }
2195 }
2196 Request::ConnectReply {
2197 server_major_protocol_version,
2198 server_minor_protocol_version,
2199 } => {
2200 2u8.write(writer);
2201 0u8.write(writer);
2202 (((self.size() - 4) / 4) as u16).write(writer);
2203 server_major_protocol_version.write(writer);
2204 server_minor_protocol_version.write(writer);
2205 }
2206 Request::CreateIc {
2207 input_method_id,
2208 ic_attributes,
2209 } => {
2210 50u8.write(writer);
2211 0u8.write(writer);
2212 (((self.size() - 4) / 4) as u16).write(writer);
2213 input_method_id.write(writer);
2214 ((ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2215 .write(writer);
2216 for elem in ic_attributes.iter() {
2217 elem.write(writer);
2218 }
2219 }
2220 Request::CreateIcReply {
2221 input_method_id,
2222 input_context_id,
2223 } => {
2224 51u8.write(writer);
2225 0u8.write(writer);
2226 (((self.size() - 4) / 4) as u16).write(writer);
2227 input_method_id.write(writer);
2228 input_context_id.write(writer);
2229 }
2230 Request::DestroyIc {
2231 input_method_id,
2232 input_context_id,
2233 } => {
2234 52u8.write(writer);
2235 0u8.write(writer);
2236 (((self.size() - 4) / 4) as u16).write(writer);
2237 input_method_id.write(writer);
2238 input_context_id.write(writer);
2239 }
2240 Request::DestroyIcReply {
2241 input_method_id,
2242 input_context_id,
2243 } => {
2244 53u8.write(writer);
2245 0u8.write(writer);
2246 (((self.size() - 4) / 4) as u16).write(writer);
2247 input_method_id.write(writer);
2248 input_context_id.write(writer);
2249 }
2250 Request::Disconnect {} => {
2251 3u8.write(writer);
2252 0u8.write(writer);
2253 (((self.size() - 4) / 4) as u16).write(writer);
2254 }
2255 Request::DisconnectReply {} => {
2256 4u8.write(writer);
2257 0u8.write(writer);
2258 (((self.size() - 4) / 4) as u16).write(writer);
2259 }
2260 Request::EncodingNegotiation {
2261 input_method_id,
2262 encodings,
2263 encoding_infos,
2264 } => {
2265 38u8.write(writer);
2266 0u8.write(writer);
2267 (((self.size() - 4) / 4) as u16).write(writer);
2268 input_method_id.write(writer);
2269 ((encodings.iter().map(|e| e.len() + 1 + 0).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2270 .write(writer);
2271 for elem in encodings.iter() {
2272 (elem.len() as u8).write(writer);
2273 writer.write(elem.as_bytes());
2274 }
2275 writer.write_pad4();
2276 ((encoding_infos
2277 .iter()
2278 .map(|e| with_pad4(e.len() + 2 + 0 - 0))
2279 .sum::<usize>()
2280 + 2
2281 + 2
2282 - 2
2283 - 2) as u16)
2284 .write(writer);
2285 0u16.write(writer);
2286 for elem in encoding_infos.iter() {
2287 (elem.len() as u16).write(writer);
2288 writer.write(elem.as_bytes());
2289 writer.write_pad4();
2290 }
2291 }
2292 Request::EncodingNegotiationReply {
2293 input_method_id,
2294 category,
2295 index,
2296 } => {
2297 39u8.write(writer);
2298 0u8.write(writer);
2299 (((self.size() - 4) / 4) as u16).write(writer);
2300 input_method_id.write(writer);
2301 category.write(writer);
2302 index.write(writer);
2303 writer.write(&[0u8; 2]);
2304 }
2305 Request::Error {
2306 input_method_id,
2307 input_context_id,
2308 flag,
2309 code,
2310 detail,
2311 } => {
2312 20u8.write(writer);
2313 0u8.write(writer);
2314 (((self.size() - 4) / 4) as u16).write(writer);
2315 input_method_id.write(writer);
2316 input_context_id.write(writer);
2317 flag.write(writer);
2318 code.write(writer);
2319 (detail.len() as u16).write(writer);
2320 writer.write(&[0u8; 2]);
2321 writer.write(detail.as_bytes());
2322 writer.write_pad4();
2323 }
2324 Request::ForwardEvent {
2325 input_method_id,
2326 input_context_id,
2327 flag,
2328 serial_number,
2329 xev,
2330 } => {
2331 60u8.write(writer);
2332 0u8.write(writer);
2333 (((self.size() - 4) / 4) as u16).write(writer);
2334 input_method_id.write(writer);
2335 input_context_id.write(writer);
2336 flag.write(writer);
2337 serial_number.write(writer);
2338 xev.write(writer);
2339 }
2340 Request::Geometry {
2341 input_method_id,
2342 input_context_id,
2343 } => {
2344 70u8.write(writer);
2345 0u8.write(writer);
2346 (((self.size() - 4) / 4) as u16).write(writer);
2347 input_method_id.write(writer);
2348 input_context_id.write(writer);
2349 }
2350 Request::GetIcValues {
2351 input_method_id,
2352 input_context_id,
2353 ic_attributes,
2354 } => {
2355 56u8.write(writer);
2356 0u8.write(writer);
2357 (((self.size() - 4) / 4) as u16).write(writer);
2358 input_method_id.write(writer);
2359 input_context_id.write(writer);
2360 ((ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2361 .write(writer);
2362 for elem in ic_attributes.iter() {
2363 elem.write(writer);
2364 }
2365 writer.write_pad4();
2366 }
2367 Request::GetIcValuesReply {
2368 input_method_id,
2369 input_context_id,
2370 ic_attributes,
2371 } => {
2372 57u8.write(writer);
2373 0u8.write(writer);
2374 (((self.size() - 4) / 4) as u16).write(writer);
2375 input_method_id.write(writer);
2376 input_context_id.write(writer);
2377 ((ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 2 + 2 - 2 - 2) as u16)
2378 .write(writer);
2379 0u16.write(writer);
2380 for elem in ic_attributes.iter() {
2381 elem.write(writer);
2382 }
2383 }
2384 Request::GetImValues {
2385 input_method_id,
2386 im_attributes,
2387 } => {
2388 44u8.write(writer);
2389 0u8.write(writer);
2390 (((self.size() - 4) / 4) as u16).write(writer);
2391 input_method_id.write(writer);
2392 ((im_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2393 .write(writer);
2394 for elem in im_attributes.iter() {
2395 elem.write(writer);
2396 }
2397 writer.write_pad4();
2398 }
2399 Request::GetImValuesReply {
2400 input_method_id,
2401 im_attributes,
2402 } => {
2403 45u8.write(writer);
2404 0u8.write(writer);
2405 (((self.size() - 4) / 4) as u16).write(writer);
2406 input_method_id.write(writer);
2407 ((im_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2408 .write(writer);
2409 for elem in im_attributes.iter() {
2410 elem.write(writer);
2411 }
2412 }
2413 Request::Open { locale } => {
2414 30u8.write(writer);
2415 0u8.write(writer);
2416 (((self.size() - 4) / 4) as u16).write(writer);
2417 (locale.len() as u8).write(writer);
2418 writer.write(locale.as_bytes());
2419 writer.write_pad4();
2420 }
2421 Request::OpenReply {
2422 input_method_id,
2423 im_attrs,
2424 ic_attrs,
2425 } => {
2426 31u8.write(writer);
2427 0u8.write(writer);
2428 (((self.size() - 4) / 4) as u16).write(writer);
2429 input_method_id.write(writer);
2430 ((im_attrs.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2431 .write(writer);
2432 for elem in im_attrs.iter() {
2433 elem.write(writer);
2434 }
2435 ((ic_attrs.iter().map(|e| e.size()).sum::<usize>() + 2 + 2 - 2 - 2) as u16)
2436 .write(writer);
2437 0u16.write(writer);
2438 for elem in ic_attrs.iter() {
2439 elem.write(writer);
2440 }
2441 }
2442 Request::PreeditCaret {
2443 input_method_id,
2444 input_context_id,
2445 position,
2446 direction,
2447 style,
2448 } => {
2449 76u8.write(writer);
2450 0u8.write(writer);
2451 (((self.size() - 4) / 4) as u16).write(writer);
2452 input_method_id.write(writer);
2453 input_context_id.write(writer);
2454 position.write(writer);
2455 direction.write(writer);
2456 style.write(writer);
2457 }
2458 Request::PreeditCaretReply {
2459 input_method_id,
2460 input_context_id,
2461 position,
2462 } => {
2463 77u8.write(writer);
2464 0u8.write(writer);
2465 (((self.size() - 4) / 4) as u16).write(writer);
2466 input_method_id.write(writer);
2467 input_context_id.write(writer);
2468 position.write(writer);
2469 }
2470 Request::PreeditDone {
2471 input_method_id,
2472 input_context_id,
2473 } => {
2474 78u8.write(writer);
2475 0u8.write(writer);
2476 (((self.size() - 4) / 4) as u16).write(writer);
2477 input_method_id.write(writer);
2478 input_context_id.write(writer);
2479 }
2480 Request::PreeditDraw {
2481 input_method_id,
2482 input_context_id,
2483 caret,
2484 chg_first,
2485 chg_length,
2486 status,
2487 preedit_string,
2488 feedbacks,
2489 } => {
2490 75u8.write(writer);
2491 0u8.write(writer);
2492 (((self.size() - 4) / 4) as u16).write(writer);
2493 input_method_id.write(writer);
2494 input_context_id.write(writer);
2495 caret.write(writer);
2496 chg_first.write(writer);
2497 chg_length.write(writer);
2498 status.write(writer);
2499 (preedit_string.len() as u16).write(writer);
2500 writer.write(&preedit_string);
2501 writer.write_pad4();
2502 ((feedbacks.iter().map(|e| e.size()).sum::<usize>() + 2 + 2 - 2 - 2) as u16)
2503 .write(writer);
2504 0u16.write(writer);
2505 for elem in feedbacks.iter() {
2506 elem.write(writer);
2507 }
2508 }
2509 Request::PreeditStart {
2510 input_method_id,
2511 input_context_id,
2512 } => {
2513 73u8.write(writer);
2514 0u8.write(writer);
2515 (((self.size() - 4) / 4) as u16).write(writer);
2516 input_method_id.write(writer);
2517 input_context_id.write(writer);
2518 }
2519 Request::PreeditStartReply {
2520 input_method_id,
2521 input_context_id,
2522 return_value,
2523 } => {
2524 74u8.write(writer);
2525 0u8.write(writer);
2526 (((self.size() - 4) / 4) as u16).write(writer);
2527 input_method_id.write(writer);
2528 input_context_id.write(writer);
2529 return_value.write(writer);
2530 }
2531 Request::PreeditState {
2532 input_method_id,
2533 input_context_id,
2534 state,
2535 } => {
2536 82u8.write(writer);
2537 0u8.write(writer);
2538 (((self.size() - 4) / 4) as u16).write(writer);
2539 input_method_id.write(writer);
2540 input_context_id.write(writer);
2541 state.write(writer);
2542 }
2543 Request::QueryExtension {
2544 input_method_id,
2545 extensions,
2546 } => {
2547 40u8.write(writer);
2548 0u8.write(writer);
2549 (((self.size() - 4) / 4) as u16).write(writer);
2550 input_method_id.write(writer);
2551 ((extensions.iter().map(|e| e.len() + 1 + 0).sum::<usize>() + 0 + 2 - 2 - 0)
2552 as u16)
2553 .write(writer);
2554 for elem in extensions.iter() {
2555 (elem.len() as u8).write(writer);
2556 writer.write(elem.as_bytes());
2557 }
2558 writer.write_pad4();
2559 }
2560 Request::QueryExtensionReply {
2561 input_method_id,
2562 extensions,
2563 } => {
2564 41u8.write(writer);
2565 0u8.write(writer);
2566 (((self.size() - 4) / 4) as u16).write(writer);
2567 input_method_id.write(writer);
2568 ((extensions.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2569 .write(writer);
2570 for elem in extensions.iter() {
2571 elem.write(writer);
2572 }
2573 }
2574 Request::RegisterTriggerKeys {
2575 input_method_id,
2576 on_keys,
2577 off_keys,
2578 } => {
2579 34u8.write(writer);
2580 0u8.write(writer);
2581 (((self.size() - 4) / 4) as u16).write(writer);
2582 input_method_id.write(writer);
2583 writer.write(&[0u8; 2]);
2584 ((on_keys.iter().map(|e| e.size()).sum::<usize>() + 0 + 4 - 4 - 0) as u32)
2585 .write(writer);
2586 for elem in on_keys.iter() {
2587 elem.write(writer);
2588 }
2589 ((off_keys.iter().map(|e| e.size()).sum::<usize>() + 0 + 4 - 4 - 0) as u32)
2590 .write(writer);
2591 for elem in off_keys.iter() {
2592 elem.write(writer);
2593 }
2594 }
2595 Request::ResetIc {
2596 input_method_id,
2597 input_context_id,
2598 } => {
2599 64u8.write(writer);
2600 0u8.write(writer);
2601 (((self.size() - 4) / 4) as u16).write(writer);
2602 input_method_id.write(writer);
2603 input_context_id.write(writer);
2604 }
2605 Request::ResetIcReply {
2606 input_method_id,
2607 input_context_id,
2608 preedit_string,
2609 } => {
2610 65u8.write(writer);
2611 0u8.write(writer);
2612 (((self.size() - 4) / 4) as u16).write(writer);
2613 input_method_id.write(writer);
2614 input_context_id.write(writer);
2615 (preedit_string.len() as u16).write(writer);
2616 writer.write(&preedit_string);
2617 writer.write_pad4();
2618 }
2619 Request::SetEventMask {
2620 input_method_id,
2621 input_context_id,
2622 forward_event_mask,
2623 synchronous_event_mask,
2624 } => {
2625 37u8.write(writer);
2626 0u8.write(writer);
2627 (((self.size() - 4) / 4) as u16).write(writer);
2628 input_method_id.write(writer);
2629 input_context_id.write(writer);
2630 forward_event_mask.write(writer);
2631 synchronous_event_mask.write(writer);
2632 }
2633 Request::SetIcFocus {
2634 input_method_id,
2635 input_context_id,
2636 } => {
2637 58u8.write(writer);
2638 0u8.write(writer);
2639 (((self.size() - 4) / 4) as u16).write(writer);
2640 input_method_id.write(writer);
2641 input_context_id.write(writer);
2642 }
2643 Request::SetIcValues {
2644 input_method_id,
2645 input_context_id,
2646 ic_attributes,
2647 } => {
2648 54u8.write(writer);
2649 0u8.write(writer);
2650 (((self.size() - 4) / 4) as u16).write(writer);
2651 input_method_id.write(writer);
2652 input_context_id.write(writer);
2653 ((ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 2 + 2 - 2 - 2) as u16)
2654 .write(writer);
2655 0u16.write(writer);
2656 for elem in ic_attributes.iter() {
2657 elem.write(writer);
2658 }
2659 }
2660 Request::SetIcValuesReply {
2661 input_method_id,
2662 input_context_id,
2663 } => {
2664 55u8.write(writer);
2665 0u8.write(writer);
2666 (((self.size() - 4) / 4) as u16).write(writer);
2667 input_method_id.write(writer);
2668 input_context_id.write(writer);
2669 }
2670 Request::SetImValues {
2671 input_method_id,
2672 attributes,
2673 } => {
2674 42u8.write(writer);
2675 0u8.write(writer);
2676 (((self.size() - 4) / 4) as u16).write(writer);
2677 input_method_id.write(writer);
2678 ((attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2 - 0) as u16)
2679 .write(writer);
2680 for elem in attributes.iter() {
2681 elem.write(writer);
2682 }
2683 }
2684 Request::SetImValuesReply { input_method_id } => {
2685 43u8.write(writer);
2686 0u8.write(writer);
2687 (((self.size() - 4) / 4) as u16).write(writer);
2688 input_method_id.write(writer);
2689 writer.write(&[0u8; 2]);
2690 }
2691 Request::StatusDone {
2692 input_method_id,
2693 input_context_id,
2694 } => {
2695 81u8.write(writer);
2696 0u8.write(writer);
2697 (((self.size() - 4) / 4) as u16).write(writer);
2698 input_method_id.write(writer);
2699 input_context_id.write(writer);
2700 }
2701 Request::StatusDraw {
2702 input_method_id,
2703 input_context_id,
2704 content,
2705 } => {
2706 80u8.write(writer);
2707 0u8.write(writer);
2708 (((self.size() - 4) / 4) as u16).write(writer);
2709 input_method_id.write(writer);
2710 input_context_id.write(writer);
2711 content.write(writer);
2712 }
2713 Request::StatusStart {
2714 input_method_id,
2715 input_context_id,
2716 } => {
2717 79u8.write(writer);
2718 0u8.write(writer);
2719 (((self.size() - 4) / 4) as u16).write(writer);
2720 input_method_id.write(writer);
2721 input_context_id.write(writer);
2722 }
2723 Request::StrConversion {} => {
2724 71u8.write(writer);
2725 0u8.write(writer);
2726 (((self.size() - 4) / 4) as u16).write(writer);
2727 }
2728 Request::StrConversionReply {} => {
2729 72u8.write(writer);
2730 0u8.write(writer);
2731 (((self.size() - 4) / 4) as u16).write(writer);
2732 }
2733 Request::Sync {
2734 input_method_id,
2735 input_context_id,
2736 } => {
2737 61u8.write(writer);
2738 0u8.write(writer);
2739 (((self.size() - 4) / 4) as u16).write(writer);
2740 input_method_id.write(writer);
2741 input_context_id.write(writer);
2742 }
2743 Request::SyncReply {
2744 input_method_id,
2745 input_context_id,
2746 } => {
2747 62u8.write(writer);
2748 0u8.write(writer);
2749 (((self.size() - 4) / 4) as u16).write(writer);
2750 input_method_id.write(writer);
2751 input_context_id.write(writer);
2752 }
2753 Request::TriggerNotify {
2754 input_method_id,
2755 input_context_id,
2756 flag,
2757 index,
2758 event_mask,
2759 } => {
2760 35u8.write(writer);
2761 0u8.write(writer);
2762 (((self.size() - 4) / 4) as u16).write(writer);
2763 input_method_id.write(writer);
2764 input_context_id.write(writer);
2765 flag.write(writer);
2766 index.write(writer);
2767 event_mask.write(writer);
2768 }
2769 Request::TriggerNotifyReply {
2770 input_method_id,
2771 input_context_id,
2772 } => {
2773 36u8.write(writer);
2774 0u8.write(writer);
2775 (((self.size() - 4) / 4) as u16).write(writer);
2776 input_method_id.write(writer);
2777 input_context_id.write(writer);
2778 }
2779 Request::UnsetIcFocus {
2780 input_method_id,
2781 input_context_id,
2782 } => {
2783 59u8.write(writer);
2784 0u8.write(writer);
2785 (((self.size() - 4) / 4) as u16).write(writer);
2786 input_method_id.write(writer);
2787 input_context_id.write(writer);
2788 }
2789 }
2790 }
2791 fn size(&self) -> usize {
2792 let mut content_size = 0;
2793 match self {
2794 Request::AuthNext {} => {}
2795 Request::AuthNg {} => {}
2796 Request::AuthReply {} => {}
2797 Request::AuthRequired {} => {}
2798 Request::AuthSetup {} => {}
2799 Request::Close { input_method_id } => {
2800 content_size += input_method_id.size() + 2;
2801 }
2802 Request::CloseReply { input_method_id } => {
2803 content_size += input_method_id.size() + 2;
2804 }
2805 Request::Commit {
2806 input_method_id,
2807 input_context_id,
2808 data,
2809 } => {
2810 content_size += input_method_id.size();
2811 content_size += input_context_id.size();
2812 content_size += data.size();
2813 }
2814 Request::Connect {
2815 endian,
2816 client_major_protocol_version,
2817 client_minor_protocol_version,
2818 client_auth_protocol_names,
2819 } => {
2820 content_size += endian.size() + 1;
2821 content_size += client_major_protocol_version.size();
2822 content_size += client_minor_protocol_version.size();
2823 content_size += client_auth_protocol_names
2824 .iter()
2825 .map(|e| with_pad4(e.len() + 2 + 0 - 0))
2826 .sum::<usize>()
2827 + 0
2828 + 2;
2829 }
2830 Request::ConnectReply {
2831 server_major_protocol_version,
2832 server_minor_protocol_version,
2833 } => {
2834 content_size += server_major_protocol_version.size();
2835 content_size += server_minor_protocol_version.size();
2836 }
2837 Request::CreateIc {
2838 input_method_id,
2839 ic_attributes,
2840 } => {
2841 content_size += input_method_id.size();
2842 content_size += ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2;
2843 }
2844 Request::CreateIcReply {
2845 input_method_id,
2846 input_context_id,
2847 } => {
2848 content_size += input_method_id.size();
2849 content_size += input_context_id.size();
2850 }
2851 Request::DestroyIc {
2852 input_method_id,
2853 input_context_id,
2854 } => {
2855 content_size += input_method_id.size();
2856 content_size += input_context_id.size();
2857 }
2858 Request::DestroyIcReply {
2859 input_method_id,
2860 input_context_id,
2861 } => {
2862 content_size += input_method_id.size();
2863 content_size += input_context_id.size();
2864 }
2865 Request::Disconnect {} => {}
2866 Request::DisconnectReply {} => {}
2867 Request::EncodingNegotiation {
2868 input_method_id,
2869 encodings,
2870 encoding_infos,
2871 } => {
2872 content_size += input_method_id.size();
2873 content_size +=
2874 with_pad4(encodings.iter().map(|e| e.len() + 1 + 0).sum::<usize>() + 0 + 2 - 2)
2875 + 2;
2876 content_size += encoding_infos
2877 .iter()
2878 .map(|e| with_pad4(e.len() + 2 + 0 - 0))
2879 .sum::<usize>()
2880 + 2
2881 + 2;
2882 }
2883 Request::EncodingNegotiationReply {
2884 input_method_id,
2885 category,
2886 index,
2887 } => {
2888 content_size += input_method_id.size();
2889 content_size += category.size();
2890 content_size += index.size() + 2;
2891 }
2892 Request::Error {
2893 input_method_id,
2894 input_context_id,
2895 flag,
2896 code,
2897 detail,
2898 } => {
2899 content_size += input_method_id.size();
2900 content_size += input_context_id.size();
2901 content_size += flag.size();
2902 content_size += code.size();
2903 content_size += with_pad4(detail.len() + 2 + 2 - 0);
2904 }
2905 Request::ForwardEvent {
2906 input_method_id,
2907 input_context_id,
2908 flag,
2909 serial_number,
2910 xev,
2911 } => {
2912 content_size += input_method_id.size();
2913 content_size += input_context_id.size();
2914 content_size += flag.size();
2915 content_size += serial_number.size();
2916 content_size += xev.size();
2917 }
2918 Request::Geometry {
2919 input_method_id,
2920 input_context_id,
2921 } => {
2922 content_size += input_method_id.size();
2923 content_size += input_context_id.size();
2924 }
2925 Request::GetIcValues {
2926 input_method_id,
2927 input_context_id,
2928 ic_attributes,
2929 } => {
2930 content_size += input_method_id.size();
2931 content_size += input_context_id.size();
2932 content_size +=
2933 with_pad4(ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 0);
2934 }
2935 Request::GetIcValuesReply {
2936 input_method_id,
2937 input_context_id,
2938 ic_attributes,
2939 } => {
2940 content_size += input_method_id.size();
2941 content_size += input_context_id.size();
2942 content_size += ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 2 + 2;
2943 }
2944 Request::GetImValues {
2945 input_method_id,
2946 im_attributes,
2947 } => {
2948 content_size += input_method_id.size();
2949 content_size +=
2950 with_pad4(im_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2 - 2)
2951 + 2;
2952 }
2953 Request::GetImValuesReply {
2954 input_method_id,
2955 im_attributes,
2956 } => {
2957 content_size += input_method_id.size();
2958 content_size += im_attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2;
2959 }
2960 Request::Open { locale } => {
2961 content_size += with_pad4(locale.len() + 1 + 0 - 0);
2962 }
2963 Request::OpenReply {
2964 input_method_id,
2965 im_attrs,
2966 ic_attrs,
2967 } => {
2968 content_size += input_method_id.size();
2969 content_size += im_attrs.iter().map(|e| e.size()).sum::<usize>() + 0 + 2;
2970 content_size += ic_attrs.iter().map(|e| e.size()).sum::<usize>() + 2 + 2;
2971 }
2972 Request::PreeditCaret {
2973 input_method_id,
2974 input_context_id,
2975 position,
2976 direction,
2977 style,
2978 } => {
2979 content_size += input_method_id.size();
2980 content_size += input_context_id.size();
2981 content_size += position.size();
2982 content_size += direction.size();
2983 content_size += style.size();
2984 }
2985 Request::PreeditCaretReply {
2986 input_method_id,
2987 input_context_id,
2988 position,
2989 } => {
2990 content_size += input_method_id.size();
2991 content_size += input_context_id.size();
2992 content_size += position.size();
2993 }
2994 Request::PreeditDone {
2995 input_method_id,
2996 input_context_id,
2997 } => {
2998 content_size += input_method_id.size();
2999 content_size += input_context_id.size();
3000 }
3001 Request::PreeditDraw {
3002 input_method_id,
3003 input_context_id,
3004 caret,
3005 chg_first,
3006 chg_length,
3007 status,
3008 preedit_string,
3009 feedbacks,
3010 } => {
3011 content_size += input_method_id.size();
3012 content_size += input_context_id.size();
3013 content_size += caret.size();
3014 content_size += chg_first.size();
3015 content_size += chg_length.size();
3016 content_size += status.size();
3017 content_size += with_pad4(preedit_string.len() + 2 - 0);
3018 content_size += feedbacks.iter().map(|e| e.size()).sum::<usize>() + 2 + 2;
3019 }
3020 Request::PreeditStart {
3021 input_method_id,
3022 input_context_id,
3023 } => {
3024 content_size += input_method_id.size();
3025 content_size += input_context_id.size();
3026 }
3027 Request::PreeditStartReply {
3028 input_method_id,
3029 input_context_id,
3030 return_value,
3031 } => {
3032 content_size += input_method_id.size();
3033 content_size += input_context_id.size();
3034 content_size += return_value.size();
3035 }
3036 Request::PreeditState {
3037 input_method_id,
3038 input_context_id,
3039 state,
3040 } => {
3041 content_size += input_method_id.size();
3042 content_size += input_context_id.size();
3043 content_size += state.size();
3044 }
3045 Request::QueryExtension {
3046 input_method_id,
3047 extensions,
3048 } => {
3049 content_size += input_method_id.size();
3050 content_size += with_pad4(
3051 extensions.iter().map(|e| e.len() + 1 + 0).sum::<usize>() + 0 + 2 - 0,
3052 );
3053 }
3054 Request::QueryExtensionReply {
3055 input_method_id,
3056 extensions,
3057 } => {
3058 content_size += input_method_id.size();
3059 content_size += extensions.iter().map(|e| e.size()).sum::<usize>() + 0 + 2;
3060 }
3061 Request::RegisterTriggerKeys {
3062 input_method_id,
3063 on_keys,
3064 off_keys,
3065 } => {
3066 content_size += input_method_id.size() + 2;
3067 content_size += on_keys.iter().map(|e| e.size()).sum::<usize>() + 0 + 4;
3068 content_size += off_keys.iter().map(|e| e.size()).sum::<usize>() + 0 + 4;
3069 }
3070 Request::ResetIc {
3071 input_method_id,
3072 input_context_id,
3073 } => {
3074 content_size += input_method_id.size();
3075 content_size += input_context_id.size();
3076 }
3077 Request::ResetIcReply {
3078 input_method_id,
3079 input_context_id,
3080 preedit_string,
3081 } => {
3082 content_size += input_method_id.size();
3083 content_size += input_context_id.size();
3084 content_size += with_pad4(preedit_string.len() + 2 - 0);
3085 }
3086 Request::SetEventMask {
3087 input_method_id,
3088 input_context_id,
3089 forward_event_mask,
3090 synchronous_event_mask,
3091 } => {
3092 content_size += input_method_id.size();
3093 content_size += input_context_id.size();
3094 content_size += forward_event_mask.size();
3095 content_size += synchronous_event_mask.size();
3096 }
3097 Request::SetIcFocus {
3098 input_method_id,
3099 input_context_id,
3100 } => {
3101 content_size += input_method_id.size();
3102 content_size += input_context_id.size();
3103 }
3104 Request::SetIcValues {
3105 input_method_id,
3106 input_context_id,
3107 ic_attributes,
3108 } => {
3109 content_size += input_method_id.size();
3110 content_size += input_context_id.size();
3111 content_size += ic_attributes.iter().map(|e| e.size()).sum::<usize>() + 2 + 2;
3112 }
3113 Request::SetIcValuesReply {
3114 input_method_id,
3115 input_context_id,
3116 } => {
3117 content_size += input_method_id.size();
3118 content_size += input_context_id.size();
3119 }
3120 Request::SetImValues {
3121 input_method_id,
3122 attributes,
3123 } => {
3124 content_size += input_method_id.size();
3125 content_size += attributes.iter().map(|e| e.size()).sum::<usize>() + 0 + 2;
3126 }
3127 Request::SetImValuesReply { input_method_id } => {
3128 content_size += input_method_id.size() + 2;
3129 }
3130 Request::StatusDone {
3131 input_method_id,
3132 input_context_id,
3133 } => {
3134 content_size += input_method_id.size();
3135 content_size += input_context_id.size();
3136 }
3137 Request::StatusDraw {
3138 input_method_id,
3139 input_context_id,
3140 content,
3141 } => {
3142 content_size += input_method_id.size();
3143 content_size += input_context_id.size();
3144 content_size += content.size();
3145 }
3146 Request::StatusStart {
3147 input_method_id,
3148 input_context_id,
3149 } => {
3150 content_size += input_method_id.size();
3151 content_size += input_context_id.size();
3152 }
3153 Request::StrConversion {} => {}
3154 Request::StrConversionReply {} => {}
3155 Request::Sync {
3156 input_method_id,
3157 input_context_id,
3158 } => {
3159 content_size += input_method_id.size();
3160 content_size += input_context_id.size();
3161 }
3162 Request::SyncReply {
3163 input_method_id,
3164 input_context_id,
3165 } => {
3166 content_size += input_method_id.size();
3167 content_size += input_context_id.size();
3168 }
3169 Request::TriggerNotify {
3170 input_method_id,
3171 input_context_id,
3172 flag,
3173 index,
3174 event_mask,
3175 } => {
3176 content_size += input_method_id.size();
3177 content_size += input_context_id.size();
3178 content_size += flag.size();
3179 content_size += index.size();
3180 content_size += event_mask.size();
3181 }
3182 Request::TriggerNotifyReply {
3183 input_method_id,
3184 input_context_id,
3185 } => {
3186 content_size += input_method_id.size();
3187 content_size += input_context_id.size();
3188 }
3189 Request::UnsetIcFocus {
3190 input_method_id,
3191 input_context_id,
3192 } => {
3193 content_size += input_method_id.size();
3194 content_size += input_context_id.size();
3195 }
3196 }
3197 content_size + 4
3198 }
3199}