/// <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); } } }
/// <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); } } }
/// <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); } }
/// <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); } } }
/// <summary> /// Serializes pinyin syllable into binary stream. /// </summary> public void Serialize(BinWriter bw) { bw.WriteString(Text); bw.WriteByte((byte)(Tone + 1)); }