Example #1
0
        public int ParseFrom(ref uint member_value, ref MemoryStream int_stream)
        {
            int count = 0;

            // 读key
            uint type = 0;

            count += ProtoReadWrite.DeVariant(ref type, ref int_stream);

            // key中的字段序号匹配,否则恢复int_stream并跳过
            uint temp_member_id = type >> 3;

            if (temp_member_id == member_id)
            {
                // 读value
                count += ProtoReadWrite.DeVariant(ref member_value, ref int_stream);

                // 标记有值
                has_value = true;
            }
            else
            {
                // 恢复流的当前位置
                long curr_stream_len = int_stream.Position;
                int_stream.Seek(curr_stream_len - count, SeekOrigin.Begin);

                count = 0;
            }

            return(count);
        }
Example #2
0
        public int ParseFrom(IMessage member_value, ref MemoryStream int_stream)
        {
            int count = 0;

            // 读key
            uint type = 0;

            count += ProtoReadWrite.DeVariant(ref type, ref int_stream);

            // key中的字段序号匹配,否则恢复int_stream并跳过
            uint temp_member_id = type >> 3;

            if (temp_member_id == member_id)
            {
                // 读长度len
                int len = 0;
                count += ProtoReadWrite.DeVariant(ref len, ref int_stream);

                if (0 < len)
                {
                    // 读内容
                    MemoryStream temp_stream = new MemoryStream();
                    temp_stream.Write(int_stream.GetBuffer(), (int)int_stream.Position, len);
                    temp_stream.Seek(0, SeekOrigin.Begin);

                    count += member_value.ParseFrom(ref temp_stream);

                    int_stream.Seek(len, SeekOrigin.Current);

                    // 标记有值
                    has_value = true;
                }
            }
            else
            {
                // 恢复流的当前位置
                long curr_stream_len = int_stream.Position;
                int_stream.Seek(curr_stream_len - count, SeekOrigin.Begin);

                count = 0;
            }

            return(count);
        }