예제 #1
0
        public static void ReadFiles()
        {
            //中文字
            var resourceData = File.ReadAllBytes(@"E:\Code\GitCode\Tools\Tools\PinYinConverter\TEst\files\CharDictionary");

            //using (BinaryReader binaryReader = new BinaryReader((Stream)new MemoryStream(resourceData)))
            //{
            //  var res=  CharDictionary.Deserialize(binaryReader);
            //}

            // resourceData = File.ReadAllBytes(@"E:\Code\GitCode\Tools\Tools\PinYinConverter\TEst\files\HomophoneDictionary");
            //using (BinaryReader binaryReader = new BinaryReader((Stream)new MemoryStream(resourceData)))
            //{
            //    var res = HomophoneDictionary.Deserialize(binaryReader);
            //}
            resourceData = File.ReadAllBytes(@"E:\Code\GitCode\Tools\Tools\PinYinConverter\TEst\files\PinyinDictionary");
            using (BinaryReader binaryReader = new BinaryReader((Stream) new MemoryStream(resourceData)))
            {
                var res = PinyinDictionary.Deserialize(binaryReader);
            }
        }
예제 #2
0
        internal static PinyinDictionary Deserialize(BinaryReader binaryReader)
        {//文件18个字节后的为正常可解析部分【按7个长度依次类推】  binaryReader.ReadBytes(18);
            PinyinDictionary pinyinDictionary = new PinyinDictionary();

            //var gg=  binaryReader.ReadBytes(14);
            pinyinDictionary.Length = binaryReader.ReadInt16();
            pinyinDictionary.Count  = binaryReader.ReadInt16();
            pinyinDictionary.Offset = binaryReader.ReadInt16();
            binaryReader.ReadBytes(8);
            pinyinDictionary.PinyinUnitTable = new List <PinyinUnit>();

            StringBuilder sb = new StringBuilder();

            for (int index = 0; index < (int)pinyinDictionary.Count; ++index)
            {
                pinyinDictionary.PinyinUnitTable.Add(PinyinUnit.Deserialize(binaryReader, sb));
            }
            int num = (int)binaryReader.ReadInt16();

            File.WriteAllText("PinyinDictionary.txt", sb.ToString(), Encoding.UTF8);
            return(pinyinDictionary);
        }