コード例 #1
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
            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);
                }
            }
コード例 #2
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
            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
                });
            }
コード例 #3
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
            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);
            }
コード例 #4
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
            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);
            }
コード例 #5
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
 internal Channel(NaiveMultiplexing channels, int id)
 {
     Parent = channels;
     Id     = id;
     State  = StateEnum.Open;
 }
コード例 #6
0
ファイル: NaiveMultiplexing.cs プロジェクト: smeoow/Naive
 public static int getSendChIdLen(NaiveMultiplexing m) => m.sendChannelIdLength;
コード例 #7
0
ファイル: RrChannels.cs プロジェクト: smeoow/Naive
 public RrChannels(NaiveMultiplexing baseChannels)
 {
     BaseChannels = baseChannels;
 }
コード例 #8
0
 public NaiveMChannels(NaiveMultiplexing channels) : base(channels)
 {
     this.OnLocalChannelCreated  += TryApplyPerChannelEncryption;
     this.OnRemoteChannelCreated += TryApplyPerChannelEncryption;
 }