/// <summary>
        /// Marshals this struct to managed byte array.
        /// </summary>
        /// <returns>Marshalled managed byte array.</returns>
        public byte[] ToBytes()
        {
            // This field MUST be set to CBY_CAPS (0xCBC0).
            blockType = blockType_Value.CBY_CAPS;
            // This field MUST be set to 0x0008.
            blockLen = 0x0008;
            numCapsets = (ushort)capsetsData.Length;

            // Convert each TS_RFX_CAPSET in capsetsData field to a byte array
            // and calculate total block length.
            byte[][] capsetsBytes = new byte[numCapsets][];
            uint totalBlockLen = blockLen;
            for (int i = 0; i < numCapsets; i++)
            {
                capsetsBytes[i] = capsetsData[i].ToBytes();
                totalBlockLen += (uint)capsetsBytes[i].Length;
            }

            // Marshal all bytes into a single buffer.
            byte[] buf = new byte[totalBlockLen];
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream(buf)))
            {
                writer.Write(TypeMarshal.ToBytes<ushort>((ushort)blockType));
                writer.Write(TypeMarshal.ToBytes<uint>(blockLen));
                writer.Write(TypeMarshal.ToBytes<ushort>(numCapsets));
                foreach (byte[] capset in capsetsBytes)
                {
                    writer.Write(capset);
                }
            }

            return buf;
        }
        /// <summary>
        /// Marshals this struct to managed byte array.
        /// </summary>
        /// <returns>Marshalled managed byte array.</returns>
        public byte[] ToBytes()
        {
            // This field MUST be set to CBY_CAPSET (0xCBC1).
            blockType = blockType_Value.CBY_CAPSET;
            // This field MUST be set to 0x01.
            codecId = 1;
            // This field MUST be set to CLY_CAPSET (0xCFC0).
            capsetType = 0xCFC0;
            numIcaps   = (ushort)(icapsData.Length);
            icapLen    = (ushort)(icapsData[0].ToBytes().Length);
            // blockType, blockLen, codecId, capsetType, numIcaps and icapLen
            // fields take 13 bytes, the icapsData field takes icapLen*numIcaps bytes.
            blockLen = (uint)(13 + icapLen * numIcaps);

            byte[] buf = new byte[blockLen];
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream(buf)))
            {
                writer.Write(TypeMarshal.ToBytes <ushort>((ushort)blockType));
                writer.Write(TypeMarshal.ToBytes <uint>(blockLen));
                writer.Write(TypeMarshal.ToBytes <byte>(codecId));
                writer.Write(TypeMarshal.ToBytes <ushort>(capsetType));
                writer.Write(TypeMarshal.ToBytes <ushort>(numIcaps));
                writer.Write(TypeMarshal.ToBytes <ushort>(icapLen));
                foreach (TS_RFX_ICAP icap in icapsData)
                {
                    writer.Write(icap.ToBytes());
                }
            }

            return(buf);
        }
        /// <summary>
        /// Marshals this struct to managed byte array.
        /// </summary>
        /// <returns>Marshalled managed byte array.</returns>
        public byte[] ToBytes()
        {
            // This field MUST be set to CBY_CAPSET (0xCBC1).
            blockType = blockType_Value.CBY_CAPSET;
            // This field MUST be set to 0x01.
            codecId = 1;
            // This field MUST be set to CLY_CAPSET (0xCFC0).
            capsetType = 0xCFC0;
            numIcaps = (ushort)(icapsData.Length);
            icapLen = (ushort)(icapsData[0].ToBytes().Length);
            // blockType, blockLen, codecId, capsetType, numIcaps and icapLen
            // fields take 13 bytes, the icapsData field takes icapLen*numIcaps bytes.
            blockLen = (uint)(13 + icapLen * numIcaps);

            byte[] buf = new byte[blockLen];
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream(buf)))
            {
                writer.Write(TypeMarshal.ToBytes<ushort>((ushort)blockType));
                writer.Write(TypeMarshal.ToBytes<uint>(blockLen));
                writer.Write(TypeMarshal.ToBytes<byte>(codecId));
                writer.Write(TypeMarshal.ToBytes<ushort>(capsetType));
                writer.Write(TypeMarshal.ToBytes<ushort>(numIcaps));
                writer.Write(TypeMarshal.ToBytes<ushort>(icapLen));
                foreach (TS_RFX_ICAP icap in icapsData)
                {
                    writer.Write(icap.ToBytes());
                }
            }

            return buf;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Marshals this struct to managed byte array.
        /// </summary>
        /// <returns>Marshalled managed byte array.</returns>
        public byte[] ToBytes()
        {
            // This field MUST be set to CBY_CAPS (0xCBC0).
            blockType = blockType_Value.CBY_CAPS;
            // This field MUST be set to 0x0008.
            blockLen   = 0x0008;
            numCapsets = (ushort)capsetsData.Length;

            // Convert each TS_RFX_CAPSET in capsetsData field to a byte array
            // and calculate total block length.
            byte[][] capsetsBytes  = new byte[numCapsets][];
            uint     totalBlockLen = blockLen;

            for (int i = 0; i < numCapsets; i++)
            {
                capsetsBytes[i] = capsetsData[i].ToBytes();
                totalBlockLen  += (uint)capsetsBytes[i].Length;
            }

            // Marshal all bytes into a single buffer.
            byte[] buf = new byte[totalBlockLen];
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream(buf)))
            {
                writer.Write(TypeMarshal.ToBytes <ushort>((ushort)blockType));
                writer.Write(TypeMarshal.ToBytes <uint>(blockLen));
                writer.Write(TypeMarshal.ToBytes <ushort>(numCapsets));
                foreach (byte[] capset in capsetsBytes)
                {
                    writer.Write(capset);
                }
            }

            return(buf);
        }