0

I have a static function in my class ExMessage. The purpose of this function is to split a byte array payload into smaller chunks and call it constructor for each chunk.Does Take() return successive bytes of size MAX_PAYLOAD_SIZE. I tried and it doesn't seem to work.

public static List<ExMessage> CreateMessages(byte[] payload, int sequence_number)
{
    if (payload.Length > MAX_PAYLOAD_SIZE)
    {
        byte[] chunks = payload.Take(MAX_PAYLOAD_SIZE).ToArray();

        var Message = new ExMessage(chunks, 1, 1);
        List<ExMessage> arr = new List<ExMessage>();
        arr.Insert(0,Message);
        return arr;
    }
}
liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • 1
    `I tried and it doesn't seem to work.` What do you mean by `not working`? Do you get unexpected result? an exception? – L.B Dec 21 '16 at 21:01
  • you should use `Batch` instead. how ever that's in MoreLinq library. get it from github – M.kazem Akhgary Dec 21 '16 at 21:01
  • I agree this is a duplicate, but wanted to point out there are other ways to do this apart from using a 3rd party tool - search on http://stackoverflow.com/search?q=%5Bc%23%5D+split+array – Aaron Thomas Dec 21 '16 at 21:19
  • Also check out Buffer.BlockCopy, which may assist with this - great performance with standard libraray. – Aaron Thomas Dec 21 '16 at 21:20

0 Answers0