Example #1
0
 /// <summary>
 /// Encodes a message object to byte[]
 /// </summary>
 /// <param name="message">Message data to encode.</param>
 /// <returns>Encoded byte[] representation of the message object.</returns>
 /// <remarks>
 /// Format:
 /// Crc (Int32), MagicByte (Byte), Attribute (Byte), Key (Byte[]), Value (Byte[])
 /// </remarks>
 public static byte[] EncodeMessage(Message message)
 {
     using (var stream = new KafkaMessagePacker())
     {
         return(stream.Pack(message.MagicNumber)
                .Pack(message.Attribute)
                .Pack(message.Key)
                .Pack(message.Value)
                .CrcPayload());
     }
 }
Example #2
0
        /// <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());
            }
        }