コード例 #1
0
        public override byte[] ToArray()
        {
            TotalLength = Length;
            for (int i = 0; i < NumberOfInterfaces; i++)
            {
                TotalLength += InterfaceDescriptor[i].Length;
                for (int j = 0; j < InterfaceDescriptor[i].NumberOfEndpoints; j++)
                {
                    TotalLength += InterfaceDescriptor[i].EndpointDescriptor[j].Length;
                }
            }

            var arr    = new byte[TotalLength];
            var offset = Length;

            arr[0x0] = Length;
            arr[0x1] = (byte)Type;
            arr[0x2] = TotalLength.LoByte();
            arr[0x3] = TotalLength.HiByte();
            arr[0x4] = NumberOfInterfaces;
            arr[0x5] = ConfigurationValue;
            arr[0x6] = ConfigurationIndex;
            arr[0x7] = Attributes;
            arr[0x8] = MaxPower;

            for (int i = 0; i < NumberOfInterfaces; i++)
            {
                InterfaceDescriptor[i].ToArray().CopyTo(arr, offset);
                offset += InterfaceDescriptor[i].Length;
                for (int j = 0; j < InterfaceDescriptor[i].NumberOfEndpoints; j++)
                {
                    InterfaceDescriptor[i].EndpointDescriptor[j].ToArray().CopyTo(arr, offset);
                    offset += InterfaceDescriptor[i].EndpointDescriptor[j].Length;
                }
            }
            return(arr);
        }