コード例 #1
0
        /// <summary>
        /// Serialize a IBinarySerializable object.
        /// </summary>
        /// <param name="buffer">The buffer where to serialize the data.</param>
        /// <param name="start">The start index in the buffer where to serialize the data.</param>
        /// <param name="value">The object to serialize.</param>
        /// <returns>The number of serialized bytes.</returns>
        public uint ToBytes(ref Buffer buffer, uint start, IBinarySerializable value)
        {
            uint written;

            CheckSerializationParameters(buffer, start);

            if (value != null)
            {
                Type type = value.GetType();

                CheckDefaultConstructor(type);

                written = ToBytes(ref buffer, start, type);

                written += value.ToBytes(this, ref buffer, start + written);
            }
            else
            {
                written = ToBytes(ref buffer, start, (Type)null);
            }

            return(written);
        }