/// <summary> /// Encodes a collection of messages into one byte[]. Encoded in order of list. /// </summary> /// <param name="messages">The collection of messages to encode together.</param> /// <returns>Encoded byte[] representing the collection of messages.</returns> public static byte[] EncodeMessageSet(IEnumerable<Message> messages) { using (var stream = new KafkaMessagePacker()) { foreach (var message in messages) { stream.Pack(InitialMessageOffset) .Pack(EncodeMessage(message)); } return stream.PayloadNoLength(); } }
public void ReadShouldNotLoseDataFromStreamOverMultipleReads() { using (var server = new FakeTcpServer(FakeServerPort)) using (var test = new KafkaTcpSocket(new DefaultTraceLog(), _fakeServerUrl)) { const int firstMessage = 99; const string secondMessage = "testmessage"; var payload = new KafkaMessagePacker() .Pack(firstMessage) .Pack(secondMessage, StringPrefixEncoding.None); //send the combined payload server.SendDataAsync(payload.PayloadNoLength()); var firstResponse = test.ReadAsync(4).Result.ToInt32(); Assert.That(firstResponse, Is.EqualTo(firstMessage)); var secondResponse = Encoding.ASCII.GetString(test.ReadAsync(secondMessage.Length).Result); Assert.That(secondResponse, Is.EqualTo(secondMessage)); } }