private Dictionary<int, (bool, byte[])>? InitializePackets() { Dictionary<int, (bool, byte[])>? packets = new(); try { string text = File.ReadAllText("hamlet.txt"); byte[] tempbuffer = Encoding.ASCII.GetBytes(text); int amountOfPackets = (int)Math.Ceiling((double)tempbuffer.Length / (double)ChunkSize); for (int i = 0; i < amountOfPackets; i++) { int startIndex = i * ChunkSize; int length = Math.Min(ChunkSize, tempbuffer.Length - startIndex); byte[] chunk = new byte[length]; Buffer.BlockCopy(tempbuffer, startIndex, chunk, 0, length); packets[i] = (i == amountOfPackets - 1, chunk); // Mark last packet } return packets; } catch (Exception e) { Console.WriteLine(e.Message); HandleErrors(e); } return null!; }
{"content": "abc"}{"content": "def"}
{"content": "abc"}{"content": "cba"}