コード例 #1
0
        public int Serialize(IMessage member_value, ref MemoryStream out_stream)
        {
            int count = 0;

            // 是必填字段, 或者选填字段有值
            if (is_required || has_value)
            {
                // 先解析字符串内容,并得到内容的实际长度
                MemoryStream temp = new MemoryStream();
                int          len  = member_value.Serialize(ref temp);

                if (0 < len)
                {
                    // 写key:m_member_id << 3 | 2(嵌套结构对应类型);
                    uint type = member_id << 3 | 2;
                    count += ProtoReadWrite.Variant(type, ref out_stream);

                    // 写长度len
                    count += ProtoReadWrite.Variant(len, ref out_stream);

                    // 写实际内容
                    temp.WriteTo(out_stream);
                    count += (int)temp.Length;
                }
            }

            return(count);
        }
コード例 #2
0
        public int Serialize(uint member_value, ref MemoryStream out_stream)
        {
            int count = 0;

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

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

            return(count);
        }