示例#1
0
        /// <summary>
        /// 一个完整的Packet包的长度
        /// </summary>
        /// <param name="receive_buffer"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public static int ReadBufferSize(byte[] receive_buffer, ref int position)
        {
            int buffer_size = NetConverter.BytesToInt(receive_buffer, position);

            position += NetworkConst.HEAD_SIZE;
            return(buffer_size);
        }
示例#2
0
        public static int WriteBuffer(int msg_id, byte[] data, byte[] buffer_size)
        {
            byte[] msg_id_bytes  = WriteMsgId(msg_id);
            byte[] pb_data_bytes = WriteBufferLength(data.Length);


            byte[] packet_length = NetConverter.IntToBytes(msg_id_bytes.Length + pb_data_bytes.Length + data.Length);

            int index = 0;

            Copy(packet_length, buffer_size, ref index);
            Copy(msg_id_bytes, buffer_size, ref index);
            Copy(pb_data_bytes, buffer_size, ref index);
            Copy(data, buffer_size, ref index);
            return(index);
        }