예제 #1
0
        /// <summary>
        /// Serialize into binary stream.
        /// </summary>
        public void Serialize(BinWriter bw)
        {
            // Write number of runs
            short length = (short)runs.Count;

            bw.WriteShort(length);
            // Write each run; polymorphism here through byte flags
            foreach (TextRun tr in runs)
            {
                bool isZho = (tr is TextRunZho);
                // "1" in flags indicates Chinese run
                byte flags = 0;
                if (isZho)
                {
                    flags |= 1;
                }
                bw.WriteByte(flags);
                // Write run itself
                if (isZho)
                {
                    (tr as TextRunZho).Serialize(bw);
                }
                else
                {
                    (tr as TextRunLatin).Serialize(bw);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Serialize to binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     bw.WriteArray(pinyin, (ps, bwr) => ps.Serialize(bwr));
     bw.WriteString(ChSimpl);
     bw.WriteString(ChTrad);
     bw.WriteUShort(Freq);
     bw.WriteInt(StableId);
     bw.WriteByte((byte)Status);
     bw.WriteArray(senses);
     bw.WriteArray(hanziPinyinMap, (x, bwr) => bwr.WriteShort(x));
     if (zhoEmbeds == null)
     {
         bw.WriteShort(0);
     }
     else
     {
         bw.WriteShort((short)zhoEmbeds.Length);
         for (int i = 0; i != zhoEmbeds.Length; ++i)
         {
             zhoEmbeds[i].Serialize(bw);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Serialize into binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     bw.WriteChar(Radical);
     bw.WriteChar(Phon);
     bw.WriteChar(Seman);
     bw.WriteString(Decomp);
     if (Strokes.Count > short.MaxValue)
     {
         throw new Exception("Strokes too long for serialization.");
     }
     bw.WriteShort((short)Strokes.Count);
     foreach (var os in Strokes)
     {
         os.Serialize(bw);
     }
 }
예제 #4
0
 /// <summary>
 /// Serialize into binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     string[] svgParts = SVG.Split(' ');
     if (svgParts.Length > short.MaxValue)
     {
         throw new Exception("SVG too long for serialization.");
     }
     bw.WriteShort((short)svgParts.Length);
     foreach (string sp in svgParts)
     {
         if (string.IsNullOrEmpty(sp))
         {
             throw new Exception("Empty string inside split SVG.");
         }
         float val;
         if (float.TryParse(sp, out val))
         {
             short sVal = (short)(val * 10);
             if (sVal > 16384)
             {
                 throw new Exception("Value in SVG path too large for serialization.");
             }
             bw.WriteShort(sVal);
         }
         else
         {
             if (sp.Length != 1)
             {
                 throw new Exception("Invalid SVG.");
             }
             int ival = (int)sp[0];
             if (ival > byte.MaxValue)
             {
                 throw new Exception("Invalid character in SVG.");
             }
             ival += 16384;
             bw.WriteShort((short)ival);
         }
     }
     if (Median.Count > short.MaxValue)
     {
         throw new Exception("Median too long for serialization.");
     }
     bw.WriteShort((short)Median.Count);
     foreach (var x in Median)
     {
         bw.WriteShort(x.Item1);
         bw.WriteShort(x.Item2);
     }
 }
예제 #5
0
 public void Serialize(BinWriter bw)
 {
     bw.WriteString(ZhSurf);
     bw.WriteString(TrgSurf);
     bw.WriteShort((short)ZhTokMap.Length);
     foreach (var ip in ZhTokMap)
     {
         bw.WriteShort(ip.A);
         bw.WriteShort(ip.B);
     }
     bw.WriteShort((short)TrgTokMap.Length);
     foreach (var ip in TrgTokMap)
     {
         bw.WriteShort(ip.A);
         bw.WriteShort(ip.B);
     }
     bw.WriteShort((short)ZhToTrgAlign.Length);
     foreach (var alm in ZhToTrgAlign)
     {
         bw.WriteShort(alm.Ix1);
         bw.WriteShort(alm.Ix2);
         bw.WriteDouble(alm.Score);
     }
     bw.WriteShort((short)TrgToZhAlign.Length);
     foreach (var alm in TrgToZhAlign)
     {
         bw.WriteShort(alm.Ix1);
         bw.WriteShort(alm.Ix2);
         bw.WriteDouble(alm.Score);
     }
 }