public byte[] ToBytes() { byte[] commandTextBytes = CommandUtils.GetBytes(CommandText); byte[] createdBytes = CommandUtils.GetBytes(Created); byte[] methodNameBytes = CommandUtils.GetBytes(MethodName); byte[] classNameBytes = CommandUtils.GetBytes(ClassName); byte[] methodBodyBytes = CommandUtils.GetBytes(MethodBody); byte[] stackTraceBytes = CommandUtils.GetBytes(StackTrace); CommandTextLenght = commandTextBytes.Length; CreatedLenght = createdBytes.Length; MethodNameLenght = methodNameBytes.Length; ClassNameLenght = classNameBytes.Length; MethodBodyLenght = methodBodyBytes.Length; StackTraceLenght = stackTraceBytes.Length; int messageLenght = sizeof(int) * 7 + sizeof(long) + CommandTextLenght + CreatedLenght + MethodNameLenght + ClassNameLenght + MethodBodyLenght + StackTraceLenght; var messageData = new byte[messageLenght]; using (var stream = new MemoryStream(messageData)) { var writer = new BinaryWriter(stream); writer.Write(CommandTextLenght); writer.Write(commandTextBytes); writer.Write(ResultRowsCount); writer.Write(QueryMiliseconds); writer.Write(CreatedLenght); writer.Write(createdBytes); writer.Write(MethodNameLenght); writer.Write(methodNameBytes); writer.Write(ClassNameLenght); writer.Write(classNameBytes); writer.Write(MethodBodyLenght); writer.Write(methodBodyBytes); writer.Write(StackTraceLenght); writer.Write(stackTraceBytes); return(messageData); } }
public byte[] ToBytes() { int messageLength = sizeof(StatusCode) + sizeof(ServerResponseType) + sizeof(int) + MessageLength; var messageData = new byte[messageLength]; using (var stream = new MemoryStream(messageData)) { var writer = new BinaryWriter(stream); writer.Write((int)statusCode); writer.Write((int)responseType); writer.Write(MessageLength); writer.Write(CommandUtils.GetBytes(Message)); return(messageData); } }