Example #1
0
        public byte[] GetBytes()
        {
            byte[] data = new byte[ContentLength + 2 + 1];

            byte[] headerBytes = Base64Encoding.EncodeuUInt32(Id);
            data[0] = headerBytes[0];
            data[1] = headerBytes[1];

            for (int i = 0; i < ContentLength; i++)
            {
                data[i + 2] = _content[i];
            }

            data[data.Length - 1] = 1;

            return(data);
        }
Example #2
0
        public IInternalOutgoingMessage Compile()
        {
            InitCheck();

            _compiledContent = new byte[ContentLength + 2 + 1];

            byte[] headerBytes = Base64Encoding.EncodeuUInt32(Id);
            _compiledContent[0] = headerBytes[0];
            _compiledContent[1] = headerBytes[1];

            for (int i = 0; i < ContentLength; i++)
            {
                _compiledContent[i + 2] = _content[i];
            }

            _compiledContent[_compiledContent.Length - 1] = 1;

            return(this);
        }
Example #3
0
        public override IncomingMessage ParseMessage(byte[] data)
        {
            try
            {
                byte[] headerBytes = new [] { data[0], data[1] };
                int    headerId    = Base64Encoding.DecodeInt32(headerBytes);

                byte[] contentBytes = new byte[data.Length - 2];
                for (int i = 0; i < data.Length - 2; i++)
                {
                    contentBytes[i] = data[i + 2];
                }

                return(new ClassicIncomingMessage(headerId, contentBytes));
            }
            catch (Exception e)
            {
                throw new FormatException(CoreManager.ServerCore.StringLocale.GetString("CORE:ERROR_NETWORK_INVALID_DATA"), e);
            }
        }
Example #4
0
 public override int ParseLength(byte[] data)
 {
     return(Base64Encoding.DecodeInt32(data));
 }