moto_hses_proto/encoding.rs
1//! Text encoding utilities for HSES protocol
2
3use encoding_rs::{Encoding, SHIFT_JIS, UTF_8};
4
5/// Supported text encodings for HSES protocol
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum TextEncoding {
8 /// UTF-8 encoding (default)
9 Utf8,
10 /// `Shift_JIS` encoding (common for Japanese)
11 ShiftJis,
12}
13
14impl Default for TextEncoding {
15 fn default() -> Self {
16 Self::Utf8
17 }
18}
19
20impl TextEncoding {
21 /// Get the corresponding `encoding_rs::Encoding`
22 #[must_use]
23 pub fn to_encoding(&self) -> &'static Encoding {
24 match self {
25 Self::Utf8 => UTF_8,
26 Self::ShiftJis => SHIFT_JIS,
27 }
28 }
29}