MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / decode

Method decode

canvas/src/decoding.rs:106–143  ·  view source on GitHub ↗

Decodes a single character and returns the new state of the decoder

(mut self, chr: char)

Source from the content-addressed store, hash-verified

104 /// Decodes a single character and returns the new state of the decoder
105 ///
106 fn decode(mut self, chr: char) -> Result<DecodeString, DecoderError> {
107 // Decode or fetch the length of the string
108 let length = match self.length {
109 PartialResult::MatchMore(so_far) => {
110 self.length = CanvasDecoder::decode_compact_id(chr, so_far)?;
111
112 if let &PartialResult::FullMatch(0) = &self.length {
113 self.string_encoding = PartialResult::FullMatch(String::new());
114 }
115 return Ok(self);
116 }
117
118 PartialResult::FullMatch(length) => {
119 self.length = PartialResult::FullMatch(length);
120 length as usize
121 }
122 };
123
124 // Try to decode the rest of the string
125 match self.string_encoding {
126 PartialResult::FullMatch(string) => {
127 // Nothing to do
128 self.string_encoding = PartialResult::FullMatch(string);
129 }
130
131 PartialResult::MatchMore(mut string) => {
132 string.push(chr);
133
134 if string.len() >= length {
135 self.string_encoding = PartialResult::FullMatch(string);
136 } else {
137 self.string_encoding = PartialResult::MatchMore(string);
138 }
139 }
140 }
141
142 Ok(self)
143 }
144}
145
146impl DecodeBytes {

Callers 8

decode_font_draw_textMethod · 0.80
decode_font_data_ttfMethod · 0.80
decode_font_op_layoutMethod · 0.80
decode_font_op_glyphsMethod · 0.80
decode_drawingFunction · 0.80
decode_drawing_streamFunction · 0.80
load_textureMethod · 0.80

Calls 15

GlyphIdClass · 0.85
decode_spriteFunction · 0.85
decode_moveFunction · 0.85
decode_lineFunction · 0.85
decode_bezier_curveFunction · 0.85
decode_line_widthFunction · 0.85
decode_line_width_pixelsFunction · 0.85
decode_winding_ruleFunction · 0.85
decode_dash_lengthFunction · 0.85
decode_dash_offsetFunction · 0.85
decode_clear_canvasFunction · 0.85
decode_blend_modeFunction · 0.85

Tested by

no test coverage detected