Esempio n. 1
0
        public void Pack(T packet, ref byte[] buffer, ref int offset, int extraBytes = 0)
        {
            byte[] message = Encoding.GetBytes(Pack(packet));

            BufferBits.Prepare(ref buffer, offset, message.Length + extraBytes);
            BufferBits.SetBytes(message, buffer, ref offset);
        }
Esempio n. 2
0
        public override void Pack(ref byte[] buffer, ref int offset)
        {
            _builder.Pack(this, ref buffer, ref offset, ContentLength);

            if (ContentLength > 0)
            {
                BufferBits.SetBytes(Content.ToArray(), buffer, ref offset);
            }
        }
Esempio n. 3
0
        public void Pack(ref byte[] buffer, ref int offset)
        {
            BufferBits.Prepare(ref buffer, offset, GetByteLength());

            var bitOffset = 0;

            BufferBits.SetByte(CsrcCount, buffer, offset, ref bitOffset, 4);
            BufferBits.SetBool(HasExtension, buffer, offset, ref bitOffset);
            BufferBits.SetBool(HasPadding, buffer, offset, ref bitOffset);
            BufferBits.SetByte(Version, buffer, ref offset, ref bitOffset, 2);

            bitOffset = 0;
            BufferBits.SetByte(PayloadType, buffer, offset, ref bitOffset, 7);
            BufferBits.SetBool(Marker, buffer, ref offset, ref bitOffset);

            BufferBits.SetUInt16(SequenceNumber, buffer, ref offset);
            BufferBits.SetUInt32(TimeStamp, buffer, ref offset);
            BufferBits.SetUInt32(Ssrc, buffer, ref offset);
            foreach (var csrc in CsrcList.Take(CsrcCount))
            {
                BufferBits.SetUInt32(csrc, buffer, ref offset);
            }

            if (HasExtension)
            {
                Extension.Pack(ref buffer, ref offset);
            }

            if (Payload.Count > 0)
            {
                BufferBits.SetBytes(Payload.ToArray(), buffer, ref offset);
            }

            if (HasPadding && PaddingCount > 0)
            {
                offset += PaddingCount - 1;
                BufferBits.SetByte(PaddingCount, buffer, ref offset);
            }
        }