public PackedFrame Pack(SignalMap map) { var sigs = signals.Select(s => new { signal = s, id = map.BySignal(s.type, s.name) }).Where(s => s.id != 0).OrderBy(s => s.id).ToArray(); VarInt lastid = UInt32.MaxValue; VarInt first_in_segment = UInt32.MaxValue; VarInt sigs_in_segment = 0u; List <VarInt> segment_data = new List <VarInt>(); IEnumerable <VarInt> payload_data = Enumerable.Empty <VarInt>(); foreach (var item in sigs) { if (item.id == lastid + 1) { // just add the value and increment both counters sigs_in_segment++; segment_data.Add(item.signal.count); } else { if (lastid != UInt32.MaxValue) { // write out first in segment, count, data[] payload_data = payload_data.Concat(new[] { first_in_segment, sigs_in_segment }).Concat(segment_data); } // reset counters... first_in_segment = item.id; sigs_in_segment = 1; segment_data = new List <VarInt>(); segment_data.Add(item.signal.count); } lastid = item.id; } //last segment... payload_data = payload_data.Concat(new[] { first_in_segment, sigs_in_segment }).Concat(segment_data); return(new PackedFrame(dstid, srcid, payload_data.ToArray(), map)); }
async void ReceiveTask() { while (rconAlive) { await Task.Delay(20); var packets = new ArraySegment <byte>(await rcon.SendCommandAsync(Encoding.UTF8.GetBytes("/RoutingTXBuff\0"))); VarInt size; while (packets.Count() > 2) { (size, packets) = VarInt.Take(packets); var packet = new ArraySegment <byte>(packets.Array, packets.Offset, size); var packetframe = new PackedFrame(packet, Map).Unpack(); packetframe.origin = this; OnReceive?.Invoke(packetframe); packets = new ArraySegment <byte>(packets.Array, packets.Offset + size, packets.Count - size); } } }
public bool CanRoute(VarInt dst) { return(dst == ID); }
public bool CanRoute(VarInt dst) { return(rconAlive && dst == ID); }
internal UnpackedFrame(VarInt dst, VarInt src, IEnumerable <CircuitFrameValue> sigs) { dstid = dst; srcid = src; signals = sigs.ToArray(); }