Ejemplo n.º 1
0
        public MessageBlock(MessageBlockType type, int parameter, DataBlock body)
            : this()
        {
            Type      = type;
            Parameter = parameter;

            if (body != null)
            {
                Body = body;
            }

            CreateHead();
        }
Ejemplo n.º 2
0
 public MessageBlock(MessageBlockType type, int parameter)
     : this(type, parameter, null)
 {
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 创建一个特定类型的MessageBlok
 /// </summary>
 /// <param name="type"></param>
 public MessageBlock(MessageBlockType type)
     : this(type, 0, null)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// �����ݵõ�һ����Ϣ
        /// </summary>
        /// <param name="data">������Ϣ������</param>
        /// <param name="getHeadData">�Ƿ�õ�ͷ��Ϣ</param>
        public void FromBytes(byte[] data, bool getHeadData, int maxBodyLength)
        {
            int index = 0;
            int length = (int)MyConvert.ToUInt32(data, index);
            bodyLength = length - HeadLength;
            if (bodyLength > maxBodyLength)
            {
                throw new NetException(string.Format("message is too large {0}/{1}", bodyLength, maxBodyLength));
            }

            index += 4;
            Type = (MessageBlockType)MyConvert.ToUInt32(data, index);
            index += 4;
            Parameter = (int)MyConvert.ToUInt32(data, index);
            if (!getHeadData && length > HeadLength)
            {
                index += 4;
                body = new DataBlock(length - HeadLength);
                Array.Copy(data, index, body.Buffer, body.WriteIndex, body.WritableLength);
                body.WriteIndex += body.WritableLength;
            }
            else if (BodyLength >= 0)
            {
                body = new DataBlock(length - HeadLength);
            }
            else
            {
                throw new NetException("Bad message block head data.");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBlock"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="body">The body.</param>
        public MessageBlock(MessageBlockType type, int parameter, DataBlock body)
            : this()
        {
            Type = type;
            Parameter = parameter;

            if (body != null)
                Body = body;

            CreateHead();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parameter">The parameter.</param>
 public MessageBlock(MessageBlockType type, int parameter)
     : this(type, parameter, null)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// ����һ���ض����͵�MessageBlok
 /// </summary>
 /// <param name="type"></param>
 public MessageBlock(MessageBlockType type)
     : this(type, 0, null)
 {
 }