internal static void EncodePayload(Packet[] packets, IEncodeCallback callback)
        {
            if (packets.Length == 0)
            {
                callback.Call(new byte[0]);
                return;
            }

            var results = new List <byte[]>(packets.Length);
            var encodePayloadCallback = new EncodePayloadCallback(results);

            foreach (var packet in packets)
            {
                packet.Encode(encodePayloadCallback, true);
            }

            callback.Call(Buffer.Concat(results.ToArray()));//new byte[results.Count][]
        }
        internal static void EncodePayload(Packet[] packets, IEncodeCallback callback)
        {
            if (packets.Length == 0)
            {
                callback.Call(new byte[0]);
                return;
            }

            var results = new List<byte[]>(packets.Length);
            var encodePayloadCallback = new EncodePayloadCallback(results);
            foreach (var packet in packets)
            {
                packet.Encode(encodePayloadCallback, true);
            }

            callback.Call(Buffer.Concat(results.ToArray()));//new byte[results.Count][]
        }