private byte[] MessageContentSerializer() { byte[] token = Encoding.UTF8.GetBytes(Token); byte[] content = Encoding.UTF8.GetBytes(Content); ushort contentLength = (ushort)content.Length; return(Server.Combine(token, new byte[] { (byte)(contentLength & 65280), (byte)(contentLength & 255) }, content)); }
private byte[] LoginSerializer() { byte[] username = Encoding.UTF8.GetBytes(Username); ushort usernameLength = (ushort)username.Length; byte[] password = Encoding.UTF8.GetBytes(Password); ushort passwordLength = (ushort)password.Length; return(Server.Combine(new byte[] { (byte)(usernameLength & 65280), (byte)(usernameLength & 255) }, username, new byte[] { (byte)(passwordLength & 65280), (byte)(passwordLength & 255) }, password)); }
new public byte[] Serialize() { byte[] baseBytes = base.Serialize(); baseBytes = Server.Combine(baseBytes, GetBytes((UInt32)RequestIds.Length)); foreach (var req in RequestIds) { baseBytes = Server.Combine(baseBytes, GetBytes(req)); } return(baseBytes); }
private byte[] SerializeMessage(Message message) { byte[] messageId = new byte[] { (byte)(message.Id & 4278190080), (byte)(message.Id & 16711680), (byte)(message.Id & 65280), (byte)(message.Id & 255) }; byte[] content = Encoding.UTF8.GetBytes(message.Content); byte[] contentLength = new byte[] { (byte)(content.Length & 65280), (byte)(content.Length & 255) }; byte[] username = Encoding.UTF8.GetBytes(message.Author.Username); byte[] usernameLength = new byte[] { (byte)(username.Length & 65280), (byte)(username.Length & 255) }; byte[] date = BitConverter.GetBytes(message.CreationTime.Ticks); return(Server.Combine(messageId, usernameLength, username, contentLength, content, date)); }
private byte[] SerializeMessages() { byte[] toreturn = new byte[2] { (byte)(_messages.Length & 65280), (byte)(_messages.Length & 255) }; foreach (var message in _messages) { var serialized = SerializeMessage(message); toreturn = Server.Combine(toreturn, new byte[] { (byte)(serialized.Length & 65280), (byte)(serialized.Length & 255) }, serialized); } return(toreturn); }
public virtual byte[] Serialize() { byte[] baseBytes = new byte[] { (byte)MessageType }; if (MessageType == MessageTypes.Login) { baseBytes = Server.Combine(baseBytes, LoginSerializer()); } else if (MessageType == MessageTypes.SendMesssage) { baseBytes = Server.Combine(baseBytes, MessageContentSerializer()); } return(baseBytes); }
new public byte[] Serialize() { return(Server.Combine(base.Serialize(), Encoding.ASCII.GetBytes(Token))); }
public override byte[] Serialize() { return(Server.Combine(base.Serialize(), LoginSerializer())); }
new public byte[] Serialize() { return(Server.Combine(base.Serialize(), SerializeMessages())); }
new public byte[] Serialize() { byte[] ahh = base.Serialize(); return(Server.Combine(ahh, new byte[] { (byte)(Id & 4278190080), (byte)(Id & 16711680), (byte)(Id & 65280), (byte)(Id & 255) })); }