Exemplo n.º 1
0
        public static byte[] ToBytes(this IBytesConvertable bc)
        {
            if (!bc.BytesCount.HasValue)
            {
                throw new Exception("Can't calculate byte size");
            }
            var bytes = new byte[bc.BytesCount.Value];

            bc.ToBytes(bytes);
            return(bytes);
        }
Exemplo n.º 2
0
        public int Send(IBytesConvertable msg)
        {
            //return socket.Send(msg.ToBytes());

            if (msg.BytesCount.HasValue)
            {
                if (tempSendBuffer.Length < msg.BytesCount)
                {
                    tempSendBuffer = new byte[msg.BytesCount.Value];
                }

                int dataSize = msg.ToBytes(tempSendBuffer);
                return(Send(tempSendBuffer, dataSize));
            }
            else
            {
                return(Send(msg.ToBytes()));
            }
        }