示例#1
0
        public static List <Byte[]> WriteRichtext(Richtext richtext)
        {
            if (richtext.Snippets.Count > 1)
            {
                if (!richtext.Snippets.TrueForAll(s =>
                                                  s.Type == MessageType.Normal || s.Type == MessageType.At || s.Type == MessageType.Emoji ||
                                                  s.Type == MessageType.Picture))
                {
                    throw new NotSupportedException("富文本中包含多个非聊天代码");
                }
            }

            // TODO: 富文本支持
            var ret = new List <Byte[]>();
            var bw  = new BinaryWriter(new MemoryStream());

            foreach (TextSnippet snippet in richtext.Snippets)
            {
                List <Byte[]> list = WriteSnippet(snippet, (Int32)bw.BaseStream.Position);
                for (var i = 0; i < list.Count; i++)
                {
                    bw.Write(list[i]);
                    // 除最后一个以外别的都开新的包
                    //   如果有多个,那前几个一定是太长了被分段了,所以开新的包
                    //   如果只有一个/是最后一个,那就不开
                    if (i == list.Count - 1)
                    {
                        break;
                    }

                    var arr_t = new Byte[bw.BaseStream.Length];
                    bw.BaseStream.Read(arr_t);
                    ret.Add(arr_t);
                    bw = new BinaryWriter(new MemoryStream());
                }
            }

            var arr = new Byte[bw.BaseStream.Length];

            bw.BaseStream.Read(arr);
            ret.Add(arr);
            return(ret);
        }
示例#2
0
 public static Richtext ReadRichtext(this BinaryReader br)
 {
     // TODO: 解析富文本
     // 目前进度: 仅读取第一部分
     return(Richtext.Parse(br.ReadBytes(br.BeReadChar())));
 }