Пример #1
0
        /// <inheritdoc/>
        public override void Encode(IoSession session, Object message, IProtocolEncoderOutput output)
        {
            if (!message.GetType().IsSerializable)
            {
                throw new System.Runtime.Serialization.SerializationException(message.GetType() + " is not serializable.");
            }

            IoBuffer buf = IoBuffer.Allocate(64);

            buf.AutoExpand = true;
            buf.PutInt32(0);
            buf.PutObject(message);

            Int32 objectSize = buf.Position - 4;

            if (objectSize > _maxObjectSize)
            {
                throw new ArgumentException(String.Format("The encoded object is too big: {0} (> {1})",
                                                          objectSize, _maxObjectSize), "message");
            }

            buf.PutInt32(0, objectSize);
            buf.Flip();
            output.Write(buf);
        }