1use encoding::all::{
30 GB18030, GBK, ISO_2022_JP, ISO_8859_1, ISO_8859_2, ISO_8859_3, ISO_8859_4, ISO_8859_5,
31 ISO_8859_6, ISO_8859_7, ISO_8859_8, UTF_8, WINDOWS_31J, WINDOWS_874, WINDOWS_949,
32};
33use encoding::{DecoderTrap, EncoderTrap, Encoding, RawDecoder, StringWriter};
34use snafu::{Backtrace, Snafu};
35use std::borrow::Cow;
36use std::fmt::Debug;
37
38#[derive(Debug, Snafu)]
40#[non_exhaustive]
41pub enum EncodeTextError {
42 #[snafu(display("{}", message))]
46 EncodeCustom {
47 message: Cow<'static, str>,
49 backtrace: Backtrace,
51 },
52}
53
54#[derive(Debug, Snafu)]
56#[non_exhaustive]
57pub enum DecodeTextError {
58 #[snafu(display("{}", message))]
62 DecodeCustom {
63 message: Cow<'static, str>,
65 backtrace: Backtrace,
67 },
68}
69
70type EncodeResult<T> = Result<T, EncodeTextError>;
71type DecodeResult<T> = Result<T, DecodeTextError>;
72
73pub trait TextCodec {
76 fn name(&self) -> Cow<'static, str>;
84
85 fn decode(&self, text: &[u8]) -> DecodeResult<String>;
89
90 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>>;
94}
95
96impl<T: ?Sized> TextCodec for Box<T>
97where
98 T: TextCodec,
99{
100 fn name(&self) -> Cow<'static, str> {
101 self.as_ref().name()
102 }
103
104 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
105 self.as_ref().decode(text)
106 }
107
108 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
109 self.as_ref().encode(text)
110 }
111}
112
113impl<T: ?Sized> TextCodec for &'_ T
114where
115 T: TextCodec,
116{
117 fn name(&self) -> Cow<'static, str> {
118 (**self).name()
119 }
120
121 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
122 (**self).decode(text)
123 }
124
125 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
126 (**self).encode(text)
127 }
128}
129
130#[derive(Debug, Default, Clone, PartialEq)]
147pub struct SpecificCharacterSet(CharsetImpl);
148
149impl SpecificCharacterSet {
150 pub const ISO_IR_6: SpecificCharacterSet = SpecificCharacterSet(CharsetImpl::Default);
152
153 pub const ISO_IR_100: SpecificCharacterSet = SpecificCharacterSet(CharsetImpl::IsoIr100);
155
156 pub const ISO_IR_192: SpecificCharacterSet = SpecificCharacterSet(CharsetImpl::IsoIr192);
158
159 pub fn from_code(code: &str) -> Option<Self> {
173 CharsetImpl::from_code(code).map(SpecificCharacterSet)
174 }
175
176 pub fn from_codes<S: AsRef<str>>(codes: &[S]) -> Option<Self> {
190 match codes {
191 [] => None,
192 [code] => Self::from_code(code.as_ref()).or_else(|| {
193 code.as_ref()
194 .trim()
195 .is_empty()
196 .then(SpecificCharacterSet::default)
197 }),
198 codes => crate::iso2022::Iso2022::from_codes(codes)
199 .map(|charset| SpecificCharacterSet(CharsetImpl::Iso2022(charset))),
200 }
201 }
202}
203
204impl TextCodec for SpecificCharacterSet {
205 fn name(&self) -> Cow<'static, str> {
206 self.0.name()
207 }
208
209 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
210 self.0.decode(text)
211 }
212
213 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
214 self.0.encode(text)
215 }
216}
217
218#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)]
220#[non_exhaustive]
221enum CharsetImpl {
222 #[default]
224 Default,
225 IsoIr13,
227 IsoIr87,
229 IsoIr100,
232 IsoIr101,
235 IsoIr109,
238 IsoIr110,
241 IsoIr126,
243 IsoIr127,
245 IsoIr138,
247 IsoIr144,
249 IsoIr149,
251 IsoIr166,
253 IsoIr192,
255 Gb18030,
257 Gbk,
259 Iso2022(crate::iso2022::Iso2022),
261 }
263
264impl CharsetImpl {
265 pub fn from_code(uid: &str) -> Option<Self> {
270 use self::CharsetImpl::*;
271 match uid.trim_end() {
272 "Default" | "ISO_IR_6" | "ISO_IR 6" | "ISO 2022 IR 6" => Some(Default),
273 "ISO_IR_13" | "ISO_IR 13" | "ISO 2022 IR 13" => Some(IsoIr13),
274 "ISO_IR_87" | "ISO_IR 87" | "ISO 2022 IR 87" => Some(IsoIr87),
275 "ISO_IR_100" | "ISO_IR 100" | "ISO 2022 IR 100" => Some(IsoIr100),
276 "ISO_IR_101" | "ISO_IR 101" | "ISO 2022 IR 101" => Some(IsoIr101),
277 "ISO_IR_109" | "ISO_IR 109" | "ISO 2022 IR 109" => Some(IsoIr109),
278 "ISO_IR_110" | "ISO_IR 110" | "ISO 2022 IR 110" => Some(IsoIr110),
279 "ISO_IR_126" | "ISO_IR 126" | "ISO 2022 IR 126" => Some(IsoIr126),
280 "ISO_IR_127" | "ISO_IR 127" | "ISO 2022 IR 127" => Some(IsoIr127),
281 "ISO_IR_138" | "ISO_IR 138" | "ISO 2022 IR 138" => Some(IsoIr138),
282 "ISO_IR_144" | "ISO_IR 144" | "ISO 2022 IR 144" => Some(IsoIr144),
283 "ISO_IR_149" | "ISO_IR 149" | "ISO 2022 IR 149" => Some(IsoIr149),
284 "ISO_IR_166" | "ISO_IR 166" | "ISO 2022 IR 166" => Some(IsoIr166),
285 "ISO_IR_192" | "ISO_IR 192" => Some(IsoIr192),
286 "GB18030" => Some(Gb18030),
287 "GBK" | "GB2312" | "ISO 2022 IR 58" => Some(Gbk),
288 _ => None,
289 }
290 }
291}
292
293impl TextCodec for CharsetImpl {
294 fn name(&self) -> Cow<'static, str> {
295 if let CharsetImpl::Iso2022(charset) = self {
296 return Cow::Owned(charset.name());
297 }
298 Cow::Borrowed(match self {
299 CharsetImpl::Iso2022(_) => unreachable!(),
300 CharsetImpl::Default => "ISO_IR 6",
301 CharsetImpl::IsoIr13 => "ISO_IR 13",
302 CharsetImpl::IsoIr87 => "ISO_IR 87",
303 CharsetImpl::IsoIr100 => "ISO_IR 100",
304 CharsetImpl::IsoIr101 => "ISO_IR 101",
305 CharsetImpl::IsoIr109 => "ISO_IR 109",
306 CharsetImpl::IsoIr110 => "ISO_IR 110",
307 CharsetImpl::IsoIr126 => "ISO_IR 126",
308 CharsetImpl::IsoIr127 => "ISO_IR 127",
309 CharsetImpl::IsoIr138 => "ISO_IR 138",
310 CharsetImpl::IsoIr144 => "ISO_IR 144",
311 CharsetImpl::IsoIr149 => "ISO_IR 149",
312 CharsetImpl::IsoIr166 => "ISO_IR 166",
313 CharsetImpl::IsoIr192 => "ISO_IR 192",
314 CharsetImpl::Gb18030 => "GB18030",
315 CharsetImpl::Gbk => "GBK",
316 })
317 }
318
319 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
320 match self {
321 CharsetImpl::Default => DefaultCharacterSetCodec.decode(text),
322 CharsetImpl::IsoIr13 => IsoIr13CharacterSetCodec.decode(text),
323 CharsetImpl::IsoIr87 => IsoIr87CharacterSetCodec.decode(text),
324 CharsetImpl::IsoIr100 => IsoIr100CharacterSetCodec.decode(text),
325 CharsetImpl::IsoIr101 => IsoIr101CharacterSetCodec.decode(text),
326 CharsetImpl::IsoIr109 => IsoIr109CharacterSetCodec.decode(text),
327 CharsetImpl::IsoIr110 => IsoIr110CharacterSetCodec.decode(text),
328 CharsetImpl::IsoIr126 => IsoIr126CharacterSetCodec.decode(text),
329 CharsetImpl::IsoIr127 => IsoIr127CharacterSetCodec.decode(text),
330 CharsetImpl::IsoIr138 => IsoIr138CharacterSetCodec.decode(text),
331 CharsetImpl::IsoIr144 => IsoIr144CharacterSetCodec.decode(text),
332 CharsetImpl::IsoIr149 => IsoIr149CharacterSetCodec.decode(text),
333 CharsetImpl::IsoIr166 => IsoIr166CharacterSetCodec.decode(text),
334 CharsetImpl::IsoIr192 => Utf8CharacterSetCodec.decode(text),
335 CharsetImpl::Gb18030 => Gb18030CharacterSetCodec.decode(text),
336 CharsetImpl::Gbk => GBKCharacterSetCodec.decode(text),
337 CharsetImpl::Iso2022(charset) => Ok(charset.decode(text)),
338 }
339 }
340
341 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
342 match self {
343 CharsetImpl::Default => DefaultCharacterSetCodec.encode(text),
344 CharsetImpl::IsoIr13 => IsoIr13CharacterSetCodec.encode(text),
345 CharsetImpl::IsoIr87 => IsoIr87CharacterSetCodec.encode(text),
346 CharsetImpl::IsoIr100 => IsoIr100CharacterSetCodec.encode(text),
347 CharsetImpl::IsoIr101 => IsoIr101CharacterSetCodec.encode(text),
348 CharsetImpl::IsoIr109 => IsoIr109CharacterSetCodec.encode(text),
349 CharsetImpl::IsoIr110 => IsoIr110CharacterSetCodec.encode(text),
350 CharsetImpl::IsoIr126 => IsoIr126CharacterSetCodec.encode(text),
351 CharsetImpl::IsoIr127 => IsoIr127CharacterSetCodec.encode(text),
352 CharsetImpl::IsoIr138 => IsoIr138CharacterSetCodec.encode(text),
353 CharsetImpl::IsoIr144 => IsoIr144CharacterSetCodec.encode(text),
354 CharsetImpl::IsoIr149 => IsoIr149CharacterSetCodec.encode(text),
355 CharsetImpl::IsoIr166 => IsoIr166CharacterSetCodec.encode(text),
356 CharsetImpl::IsoIr192 => Utf8CharacterSetCodec.encode(text),
357 CharsetImpl::Gb18030 => Gb18030CharacterSetCodec.encode(text),
358 CharsetImpl::Gbk => GBKCharacterSetCodec.encode(text),
359 CharsetImpl::Iso2022(charset) => charset
360 .encode(text)
361 .map_err(|message| EncodeCustomSnafu { message }.build()),
362 }
363 }
364}
365
366fn decode_text_trap(
367 _decoder: &mut dyn RawDecoder,
368 input: &[u8],
369 output: &mut dyn StringWriter,
370) -> bool {
371 let c = input[0];
372 let o0 = c & 7;
373 let o1 = (c & 56) >> 3;
374 let o2 = (c & 192) >> 6;
375 output.write_char('\\');
376 output.write_char((o2 + b'0') as char);
377 output.write_char((o1 + b'0') as char);
378 output.write_char((o0 + b'0') as char);
379 true
380}
381
382macro_rules! decl_character_set {
384 ($typ: ident, $term: literal, $val: expr) => {
385 #[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
386 #[doc = "Data type for the "]
387 #[doc = $term]
388 #[doc = "character set encoding."]
389 pub struct $typ;
390
391 impl TextCodec for $typ {
392 fn name(&self) -> Cow<'static, str> {
393 Cow::Borrowed($term)
394 }
395
396 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
397 $val.decode(text, DecoderTrap::Call(decode_text_trap))
398 .map_err(|message| DecodeCustomSnafu { message }.build())
399 }
400
401 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
402 $val.encode(text, EncoderTrap::Strict)
403 .map_err(|message| EncodeCustomSnafu { message }.build())
404 }
405 }
406 };
407}
408
409#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
411pub struct DefaultCharacterSetCodec;
412
413impl TextCodec for DefaultCharacterSetCodec {
414 fn name(&self) -> Cow<'static, str> {
415 Cow::Borrowed("ISO_IR 6")
416 }
417
418 fn decode(&self, text: &[u8]) -> DecodeResult<String> {
419 ISO_8859_1
422 .decode(text, DecoderTrap::Call(decode_text_trap))
423 .map_err(|message| DecodeCustomSnafu { message }.build())
424 }
425
426 fn encode(&self, text: &str) -> EncodeResult<Vec<u8>> {
427 ISO_8859_1
428 .encode(text, EncoderTrap::Strict)
429 .map_err(|message| EncodeCustomSnafu { message }.build())
430 }
431}
432
433decl_character_set!(IsoIr13CharacterSetCodec, "ISO_IR 13", WINDOWS_31J);
434decl_character_set!(IsoIr87CharacterSetCodec, "ISO_IR 87", ISO_2022_JP);
435decl_character_set!(IsoIr100CharacterSetCodec, "ISO_IR 100", ISO_8859_1);
436decl_character_set!(IsoIr101CharacterSetCodec, "ISO_IR 101", ISO_8859_2);
437decl_character_set!(IsoIr109CharacterSetCodec, "ISO_IR 109", ISO_8859_3);
438decl_character_set!(IsoIr110CharacterSetCodec, "ISO_IR 110", ISO_8859_4);
439decl_character_set!(IsoIr126CharacterSetCodec, "ISO_IR 126", ISO_8859_7);
440decl_character_set!(IsoIr127CharacterSetCodec, "ISO_IR 127", ISO_8859_6);
441decl_character_set!(IsoIr138CharacterSetCodec, "ISO_IR 138", ISO_8859_8);
442decl_character_set!(IsoIr144CharacterSetCodec, "ISO_IR 144", ISO_8859_5);
443decl_character_set!(IsoIr149CharacterSetCodec, "ISO_IR 149", WINDOWS_949);
444decl_character_set!(IsoIr166CharacterSetCodec, "ISO_IR 166", WINDOWS_874);
445decl_character_set!(Utf8CharacterSetCodec, "ISO_IR 192", UTF_8);
446decl_character_set!(Gb18030CharacterSetCodec, "GB18030", GB18030);
447decl_character_set!(GBKCharacterSetCodec, "GBK", GBK);
448
449#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
451pub enum TextValidationOutcome {
452 Ok,
454 BadCharacters,
456 NotOk,
458}
459
460pub fn validate_iso_8859(text: &[u8]) -> TextValidationOutcome {
462 if ISO_8859_1.decode(text, DecoderTrap::Strict).is_err() {
463 match ISO_8859_1.decode(text, DecoderTrap::Call(decode_text_trap)) {
464 Ok(_) => TextValidationOutcome::BadCharacters,
465 Err(_) => TextValidationOutcome::NotOk,
466 }
467 } else {
468 TextValidationOutcome::Ok
469 }
470}
471
472pub fn validate_da(text: &[u8]) -> TextValidationOutcome {
475 if text.iter().cloned().all(|c| c.is_ascii_digit()) {
476 TextValidationOutcome::Ok
477 } else {
478 TextValidationOutcome::NotOk
479 }
480}
481
482pub fn validate_tm(text: &[u8]) -> TextValidationOutcome {
485 if text.iter().cloned().all(|c| match c {
486 b'\\' | b'.' | b'-' | b' ' => true,
487 c => c.is_ascii_digit(),
488 }) {
489 TextValidationOutcome::Ok
490 } else {
491 TextValidationOutcome::NotOk
492 }
493}
494
495pub fn validate_dt(text: &[u8]) -> TextValidationOutcome {
498 if text.iter().cloned().all(|c| match c {
499 b'.' | b'-' | b'+' | b' ' | b'\\' => true,
500 c => c.is_ascii_digit(),
501 }) {
502 TextValidationOutcome::Ok
503 } else {
504 TextValidationOutcome::NotOk
505 }
506}
507
508pub fn validate_cs(text: &[u8]) -> TextValidationOutcome {
511 if text.iter().cloned().all(|c| match c {
512 b' ' | b'_' => true,
513 c => c.is_ascii_digit() || c.is_ascii_uppercase(),
514 }) {
515 TextValidationOutcome::Ok
516 } else {
517 TextValidationOutcome::NotOk
518 }
519}
520
521#[cfg(test)]
522mod tests {
523 use super::*;
524
525 fn test_codec<T>(codec: T, string: &str, bytes: &[u8])
526 where
527 T: TextCodec,
528 {
529 assert_eq!(codec.encode(string).expect("encoding"), bytes);
530 assert_eq!(codec.decode(bytes).expect("decoding"), string);
531 }
532
533 #[test]
534 fn iso_ir_6_baseline() {
535 let codec = SpecificCharacterSet::default();
536 test_codec(codec, "Smith^John", b"Smith^John");
537 }
538
539 #[test]
540 fn iso_ir_13_baseline() {
541 let codec = SpecificCharacterSet(CharsetImpl::IsoIr13);
542 test_codec(codec, "ヤマダ^タロウ", b"\xd4\xcf\xc0\xde^\xc0\xdb\xb3");
543 }
544
545 #[test]
546 fn iso_ir_87_baseline() {
547 let codec = SpecificCharacterSet(CharsetImpl::IsoIr87);
548 test_codec(&codec, "山田^太郎", b"\x1b$B;3ED\x1b(B^\x1b$BB@O:");
549 test_codec(&codec, "やまだ^たろう", b"\x1b$B$d$^$@\x1b(B^\x1b$B$?$m$&");
550 }
551
552 #[test]
553 fn iso_ir_192_baseline() {
554 let codec = SpecificCharacterSet::ISO_IR_192;
555 test_codec(&codec, "Simões^John", "Simões^John".as_bytes());
556 test_codec(codec, "Иванков^Андрей", "Иванков^Андрей".as_bytes());
557 }
558
559 #[test]
560 fn iso_ir_100_baseline() {
561 let codec = SpecificCharacterSet(CharsetImpl::IsoIr100);
562 test_codec(&codec, "Simões^João", b"Sim\xF5es^Jo\xE3o");
563 test_codec(codec, "Günther^Hans", b"G\xfcnther^Hans");
564 }
565
566 #[test]
567 fn iso_ir_101_baseline() {
568 let codec = SpecificCharacterSet(CharsetImpl::IsoIr101);
569 test_codec(codec, "Günther^Hans", b"G\xfcnther^Hans");
570 }
571
572 #[test]
573 fn iso_ir_110_baseline() {
574 let codec = SpecificCharacterSet(CharsetImpl::IsoIr110);
575 test_codec(codec, "ĄĸŖĨϧŠĒĢŦŽĀÁÂÃÄÅÆĮČÉ^ĘËĖÍÎĪĐŅŌĶÔÕÖרŲÚÛÜŨŪß", b"\xA1\xA2\xA3\xA5\xA6\xA7\xA9\xAA\xAB\xAC\xAE\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9^\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF");
576 }
577
578 #[test]
579 fn iso_ir_126_baseline() {
580 let codec = SpecificCharacterSet(CharsetImpl::IsoIr126);
581 test_codec(codec, "Διονυσιος", b"\xC4\xE9\xEF\xED\xF5\xF3\xE9\xEF\xF2");
582 }
583
584 #[test]
585 fn iso_ir_127_baseline() {
586 let codec = SpecificCharacterSet(CharsetImpl::IsoIr127);
587 test_codec(
588 codec,
589 "قباني^لنزار",
590 b"\xE2\xC8\xC7\xE6\xEA^\xE4\xE6\xD2\xC7\xD1",
591 );
592 }
593
594 #[test]
595 fn iso_ir_138_baseline() {
596 let codec = SpecificCharacterSet(CharsetImpl::IsoIr138);
597 test_codec(
598 &codec,
599 "מקור השם עברית",
600 b"\xEE\xF7\xE5\xF8\x20\xE4\xF9\xED\x20\xF2\xE1\xF8\xE9\xFA",
601 );
602 test_codec(
603 codec,
604 "שרון^דבורה",
605 b"\xF9\xF8\xE5\xEF^\xE3\xE1\xE5\xF8\xE4",
606 );
607 }
608
609 #[test]
610 fn iso_ir_144_baseline() {
611 let codec = SpecificCharacterSet(CharsetImpl::IsoIr144);
612 test_codec(
613 &codec,
614 "Иванков^Андрей",
615 b"\xb8\xd2\xd0\xdd\xda\xde\xd2^\xb0\xdd\xd4\xe0\xd5\xd9",
616 );
617 test_codec(
618 &codec,
619 "Гол. мозг стандарт",
620 b"\xB3\xDE\xDB.\x20\xDC\xDE\xD7\xD3\x20\xE1\xE2\xD0\xDD\xD4\xD0\xE0\xE2",
621 );
622 test_codec(&codec, "мозг 2мм", b"\xDC\xDE\xD7\xD3\x202\xDC\xDC");
623 }
624
625 #[test]
626 fn iso_ir_149_baseline() {
627 let codec = SpecificCharacterSet(CharsetImpl::IsoIr149);
628 test_codec(&codec, "김희중", b"\xB1\xE8\xC8\xF1\xC1\xDF");
629 test_codec(
630 codec,
631 "Hong^Gildong=洪^吉洞=홍^길동",
632 b"Hong^Gildong=\xFB\xF3^\xD1\xCE\xD4\xD7=\xC8\xAB^\xB1\xE6\xB5\xBF",
633 );
634 }
635
636 #[test]
637 fn iso_ir_166_baseline() {
638 let codec = SpecificCharacterSet(CharsetImpl::IsoIr166);
639 test_codec(&codec, "ประเทศไทย", b"\xBB\xC3\xD0\xE0\xB7\xC8\xE4\xB7\xC2");
640 test_codec(codec, "รหัสสำหรับอักขระไทยที่ใช้กับคอมพิวเตอร์", b"\xC3\xCB\xD1\xCA\xCA\xD3\xCB\xC3\xD1\xBA\xCD\xD1\xA1\xA2\xC3\xD0\xE4\xB7\xC2\xB7\xD5\xE8\xE3\xAA\xE9\xA1\xD1\xBA\xA4\xCD\xC1\xBE\xD4\xC7\xE0\xB5\xCD\xC3\xEC");
641 }
642
643 #[test]
644 fn gb_18030_baseline() {
645 let codec = SpecificCharacterSet(CharsetImpl::Gb18030);
646 test_codec(
647 &codec,
648 "Wang^XiaoDong=王^小东",
649 b"Wang^XiaoDong=\xCD\xF5^\xD0\xA1\xB6\xAB",
650 );
651 }
652 #[test]
653 fn gb_gbk_baseline() {
654 let codec = SpecificCharacterSet(CharsetImpl::Gbk);
655
656 let iso2022_ir58_bytes = vec![
657 0xB0, 0xB2, 0xBB, 0xD5, 0xD0, 0xC7, 0xC1, 0xE9, 0xD0, 0xC5, 0xCF, 0xA2, 0xBF, 0xC6,
658 0xBC, 0xBC, 0xD3, 0xD0, 0xCF, 0xDE, 0xB9, 0xAB, 0xCB, 0xBE,
659 ];
660 let rw = codec.decode(&iso2022_ir58_bytes).expect("decoding");
661
662 assert_eq!(rw, "安徽星灵信息科技有限公司");
663
664 let gb2312_bytes = vec![
665 0xCA, 0xB9, 0xC6, 0xE4, 0xD3, 0xEB, 0xD4, 0xAD, 0xCA, 0xBC, 0xB2, 0xD6, 0xBF, 0xE2,
666 0xB1, 0xA3, 0xB3, 0xD6, 0xD2, 0xBB, 0xD6, 0xC2,
667 ];
668 let rw2 = codec.decode(&gb2312_bytes).expect("decoding");
669
670 assert_eq!(rw2, "使其与原始仓库保持一致");
671 }
672}