public void GetBytesValidFormat() { List<ProducerRequest> requests = new List<ProducerRequest> { new ProducerRequest("topic a", 0, new List<Message> { new Message(new byte[10]) }), new ProducerRequest("topic a", 0, new List<Message> { new Message(new byte[10]) }), new ProducerRequest("topic b", 0, new List<Message> { new Message(new byte[10]) }), new ProducerRequest("topic c", 0, new List<Message> { new Message(new byte[10]) }) }; MultiProducerRequest request = new MultiProducerRequest(requests); // format = len(request) + requesttype + requestcount + requestpackage // total byte count = 4 + (2 + 2 + 144) byte[] bytes = request.GetBytes(); Assert.IsNotNull(bytes); Assert.AreEqual(152, bytes.Length); // first 4 bytes = the length of the request Assert.AreEqual(148, BitConverter.ToInt32(BitWorks.ReverseBytes(bytes.Take(4).ToArray<byte>()), 0)); // next 2 bytes = the RequestType which in this case should be Produce Assert.AreEqual((short)RequestType.MultiProduce, BitConverter.ToInt16(BitWorks.ReverseBytes(bytes.Skip(4).Take(2).ToArray<byte>()), 0)); // next 2 bytes = the number of messages Assert.AreEqual((short)4, BitConverter.ToInt16(BitWorks.ReverseBytes(bytes.Skip(6).Take(2).ToArray<byte>()), 0)); }
/// <summary> /// Writes a multi-producer request to the server. /// </summary> /// <remarks> /// Write timeout is defaulted to infitite. /// </remarks> /// <param name="request">The <see cref="MultiProducerRequest"/> to send to the server.</param> public void Write(MultiProducerRequest request) { Write(request.GetBytes()); }