public static void writeChId(NaiveMultiplexing m, BytesView bv, int id, ref int cur) { int idLen = m.sendChannelIdLength; if (idLen == 1) { var i = id == ReservedId ? (sbyte.MinValue) : (sbyte)id; bv[cur++] = (byte)i; } else if (idLen == 2) { var i = id == ReservedId ? (short.MinValue) : (short)id; bv[cur++] = (byte)(i >> 8); bv[cur++] = (byte)(i); } else if (idLen == 4) { for (int i = 4 - 1; i >= 0; i--) { bv[cur++] = (byte)(id >> (i * 8)); } } else { string message = $"BUG?: unexpected recvChannelIdLength ({m.recvChannelIdLength})"; Logging.error($"{m}: " + message); throw new Exception(message); } }
public static Frame unpack(NaiveMultiplexing m, BytesView bv) { var cur = 0; int id = getChId(m, bv, ref cur); bv.SubSelf(cur); return(new Frame { Id = id, Data = bv }); }
public BytesView pack(NaiveMultiplexing m, BytesView headerBv = null) { Debug.Assert(Id <= m.currentMaxId, $"Id > currentMaxId ({m})"); if (headerBv == null) { headerBv = new BytesView(new byte[getSendChIdLen(m)]); } var cur = 0; writeChId(m, headerBv, Id, ref cur); headerBv.len = cur; headerBv.nextNode = Data; return(headerBv); }
public static int getChId(NaiveMultiplexing m, BytesView bv, ref int cur) { int id = 0; int idLen = m.recvChannelIdLength; if (idLen == 1) { id = (sbyte)bv[cur++]; if (id == sbyte.MinValue) { id = ReservedId; } } else if (idLen == 2) { id = (short)(bv[cur++] << 8 | bv[cur++]); if (id == short.MinValue) { id = ReservedId; } } else if (idLen == 4) { for (int i = 4 - 1; i >= 0; i--) { id |= (bv[cur++] << (i * 8)); } } else { string message = $"BUG?: unexpected recvChannelIdLength ({idLen})"; Logging.error($"{m}: " + message); throw new Exception(message); } return(id); }
internal Channel(NaiveMultiplexing channels, int id) { Parent = channels; Id = id; State = StateEnum.Open; }
public static int getSendChIdLen(NaiveMultiplexing m) => m.sendChannelIdLength;
public RrChannels(NaiveMultiplexing baseChannels) { BaseChannels = baseChannels; }
public NaiveMChannels(NaiveMultiplexing channels) : base(channels) { this.OnLocalChannelCreated += TryApplyPerChannelEncryption; this.OnRemoteChannelCreated += TryApplyPerChannelEncryption; }