Esempio n. 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);
                }
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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.WriteArray(senses);
     bw.WriteArray(hanziPinyinMap, (x, bwr) => bwr.WriteShort(x));
 }
Esempio n. 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);
     }
 }
Esempio n. 5
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);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Serialize into binary stream.
        /// </summary>
        public void Serialize(BinWriter bw)
        {
            // Write flags
            byte flags = 0;

            if (Simp != null)
            {
                flags |= 1;
            }
            if (Trad != Simp)
            {
                flags |= 2;
            }
            if (Pinyin != null)
            {
                flags |= 4;
            }
            bw.WriteByte(flags);
            // Write simplified
            if (Simp != null)
            {
                bw.WriteString(Simp);
            }
            // Write traditional, if different
            if (Trad != Simp)
            {
                bw.WriteString(Trad);
            }
            // Write pinyin, if present
            if (Pinyin != null)
            {
                if (Pinyin.Length > byte.MaxValue)
                {
                    throw new Exception("Pinyin syllable count exceeds maximum byte value: " + Pinyin.Length.ToString());
                }
                byte pinyinCount = (byte)Pinyin.Length;
                bw.WriteByte(pinyinCount);
                foreach (PinyinSyllable py in Pinyin)
                {
                    py.Serialize(bw);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Serialize to binary.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     if (CanBeSimp)
     {
         bw.WriteByte(1);
     }
     else
     {
         bw.WriteByte(0);
     }
     bw.WriteByte((byte)TradVariants.Length);
     foreach (char c in TradVariants)
     {
         bw.WriteChar(c);
     }
     bw.WriteByte((byte)Pinyin.Length);
     foreach (PinyinSyllable syll in Pinyin)
     {
         syll.Serialize(bw);
     }
 }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Serialize into binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     bw.WriteString(Text);
 }
Esempio n. 10
0
 /// <summary>
 /// Serializes pinyin syllable into binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     bw.WriteString(Text);
     bw.WriteByte((byte)(Tone + 1));
 }
Esempio n. 11
0
 /// <summary>
 /// Serialize into binary stream.
 /// </summary>
 public void Serialize(BinWriter bw)
 {
     Domain.Serialize(bw);
     Equiv.Serialize(bw);
     Note.Serialize(bw);
 }
Esempio n. 12
0
 public void Serialize(BinWriter bw)
 {
     bw.WriteULong(Val);
 }