facet_format_msgpack/
parser.rs1use crate::error::{MsgPackError, codes};
7use facet_format::{FieldEvidence, FormatParser, ParseEvent, ProbeStream};
8
9pub struct MsgPackParser<'de> {
13 #[cfg_attr(not(feature = "jit"), allow(dead_code))]
14 input: &'de [u8],
15 pos: usize,
16}
17
18impl<'de> MsgPackParser<'de> {
19 pub fn new(input: &'de [u8]) -> Self {
21 Self { input, pos: 0 }
22 }
23
24 fn unsupported_error(&self) -> MsgPackError {
26 MsgPackError {
27 code: codes::UNSUPPORTED,
28 pos: self.pos,
29 message: "MsgPackParser is Tier-2 JIT only - FormatParser methods are not supported"
30 .to_string(),
31 }
32 }
33}
34
35pub struct MsgPackProbe;
39
40impl<'de> ProbeStream<'de> for MsgPackProbe {
41 type Error = MsgPackError;
42
43 fn next(&mut self) -> Result<Option<FieldEvidence<'de>>, Self::Error> {
44 Err(MsgPackError {
45 code: codes::UNSUPPORTED,
46 pos: 0,
47 message: "MsgPackParser is Tier-2 JIT only - ProbeStream methods are not supported"
48 .to_string(),
49 })
50 }
51}
52
53impl<'de> FormatParser<'de> for MsgPackParser<'de> {
54 type Error = MsgPackError;
55 type Probe<'a>
56 = MsgPackProbe
57 where
58 Self: 'a;
59
60 fn next_event(&mut self) -> Result<Option<ParseEvent<'de>>, Self::Error> {
61 Err(self.unsupported_error())
62 }
63
64 fn peek_event(&mut self) -> Result<Option<ParseEvent<'de>>, Self::Error> {
65 Err(self.unsupported_error())
66 }
67
68 fn skip_value(&mut self) -> Result<(), Self::Error> {
69 Err(self.unsupported_error())
70 }
71
72 fn begin_probe(&mut self) -> Result<Self::Probe<'_>, Self::Error> {
73 Err(self.unsupported_error())
74 }
75}
76
77#[cfg(feature = "jit")]
78impl<'de> facet_format::FormatJitParser<'de> for MsgPackParser<'de> {
79 type FormatJit = crate::jit::MsgPackJitFormat;
80
81 fn jit_input(&self) -> &'de [u8] {
82 self.input
83 }
84
85 fn jit_pos(&self) -> Option<usize> {
86 Some(self.pos)
89 }
90
91 fn jit_set_pos(&mut self, pos: usize) {
92 self.pos = pos;
93 }
94
95 fn jit_format(&self) -> Self::FormatJit {
96 crate::jit::MsgPackJitFormat
97 }
98
99 fn jit_error(&self, _input: &'de [u8], error_pos: usize, error_code: i32) -> Self::Error {
100 MsgPackError::from_code(error_code, error_pos)
101 }
102}