Esempio n. 1
0
        void PopAndSetLengthImpl(SizePlaceholder sp, int len)
        {
            switch (sp.Length)
            {
            case 1:
                Buffer.SetBytesInMiddle(Globs.HostToNet((byte)len), sp.StartPos);
                return;

            case 2:
                Buffer.SetBytesInMiddle(Globs.HostToNet((ushort)len), sp.StartPos);
                return;

            case 4:
                Buffer.SetBytesInMiddle(Globs.HostToNet((uint)len), sp.StartPos);
                return;

            case 8:
                Buffer.SetBytesInMiddle(Globs.HostToNet((ulong)len), sp.StartPos);
                return;

            default:
                Globs.Throw <ArgumentException>("PopAndSetLengthImpl: Invalid length " + sp.Length);
                Buffer.SetBytesInMiddle(Globs.HostToNet((ulong)len), sp.StartPos);
                return;
            }
        }
Esempio n. 2
0
        public void PopAndSetLength()
        {
            SizePlaceholder sp  = SizesToFillIn.Pop();
            int             len = Buffer.GetSize() - sp.StartPos - sp.Length;

            PopAndSetLengthImpl(sp, len);
        }
Esempio n. 3
0
        public void PushLength(int numBytes)
        {
            var sp = new SizePlaceholder(Buffer.GetSize(), numBytes);

            SizesToFillIn.Push(sp);
            switch (numBytes)
            {
            case 1:
                ToNet((byte)0xFF);
                return;

            case 2:
                ToNet((ushort)0xFFFF);
                return;

            // ReSharper disable once RedundantCast
            case 4:
                ToNet((uint)0xFFFFFFFF);
                return;

            case 8:
                ToNet((ulong)0xFFFFFFFFFFFFFFFF);
                return;

            default:
                Globs.Throw <ArgumentException>("PushLength: Invalid length " + numBytes);
                ToNet((ulong)0xFFFFFFFFFFFFFFFF);
                return;
            }
        }
Esempio n. 4
0
        public void PopAndSetLengthToTotalLength()
        {
            SizePlaceholder sp  = SizesToFillIn.Pop();
            int             len = Buffer.GetSize();

            switch (sp.Length)
            {
            case 1: Buffer.SetBytesInMiddle(Globs.HostToNet((byte)len), sp.StartPos); return;

            case 2: Buffer.SetBytesInMiddle(Globs.HostToNet((ushort)len), sp.StartPos); return;

            case 4: Buffer.SetBytesInMiddle(Globs.HostToNet((uint)len), sp.StartPos); return;

            default: throw new Exception("Invalid length");
            }
        }
Esempio n. 5
0
        public void PushLength(int numBytes)
        {
            var sp = new SizePlaceholder(Buffer.GetSize(), numBytes);

            SizesToFillIn.Push(sp);
            switch (numBytes)
            {
            case 1: ToNet((byte)0xFF); return;

            case 2: ToNet((ushort)0xFFFF); return;

            // ReSharper disable once RedundantCast
            case 4: ToNet((uint)0xFFFFFFFF); return;

            default: throw new Exception("Invalid length");
            }
        }