Decodes a single character and returns the new state of the decoder
(mut self, chr: char)
| 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 | |
| 146 | impl DecodeBytes { |
no test coverage detected