Esempio n. 1
0
        public int Serialize(long member_value, ref MemoryStream out_stream)
        {
            int count = 0;

            // 是必填字段, 或者选填字段有值
            if (is_required || has_value)
            {
                // 写key:m_member_id << 3 | 0(long对应类型);
                uint type = member_id << 3 | 0;
                count += ProtoReadWrite.Variant(type, ref out_stream);

                // 写value
                count += ProtoReadWrite.Variant(member_value, ref out_stream);
            }

            return(count);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public int ParseFrom(ref string 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)
                {
                    // 读内容
                    count += ProtoReadWrite.DeCode(ref member_value, ref int_stream, len);

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

                count = 0;
            }

            return(count);
        }