The TS_ORDER_CAPABILITYSET structure advertises support for primary drawing order-related capabilities and is based on the capability set specified in [T128] section 8.2.5 (for more information about primary drawing orders, see [MS-RDPEGDI] section ). This capability is sent by both client and server.
file:///C:/ts_dev/TestSuites/MS-RDPBCGR/TestSuite/Src/TD/latest_XMLS_16may/RDPBCGR/ _rfc_ms-rdpbcgr2_1_6_1_3.xml
 /// <summary>
 /// 2.2.7.1.3
 /// </summary>
 /// <param name="order"></param>
 public void VerifyStructure(TS_ORDER_CAPABILITYSET order)
 {
     site.CaptureRequirementIfAreEqual<capabilitySetType_Values>(capabilitySetType_Values.CAPSTYPE_ORDER, order.capabilitySetType, 1137,
         @"In TS_ORDER_CAPABILITYSET structure, the capabilitySetType field MUST be set to CAPSTYPE_ORDER (3).");
     bool isR1141Satisfied = order.terminalDescriptor[0] == 0 &&
         order.terminalDescriptor[1] == 0 &&
         order.terminalDescriptor[2] == 0 &&
         order.terminalDescriptor[3] == 0 &&
         order.terminalDescriptor[4] == 0 &&
         order.terminalDescriptor[5] == 0 &&
         order.terminalDescriptor[6] == 0 &&
         order.terminalDescriptor[7] == 0 &&
         order.terminalDescriptor[8] == 0 &&
         order.terminalDescriptor[9] == 0 &&
         order.terminalDescriptor[10] == 0 &&
         order.terminalDescriptor[11] == 0 &&
         order.terminalDescriptor[12] == 0 &&
         order.terminalDescriptor[13] == 0 &&
         order.terminalDescriptor[14] == 0 &&
         order.terminalDescriptor[15] == 0;
     site.CaptureRequirementIfIsTrue(isR1141Satisfied, 1141,
         @"In TS_ORDER_CAPABILITYSET structure, the terminalDescriptor field is ignored during capability "
         + @"negotiation and SHOULD be set to all zeroes.");
     site.CaptureRequirementIfAreEqual<ushort>(1, order.maximumOrderLevel, 1152,
         @"In TS_ORDER_CAPABILITYSET structure, the maximumOrderLevel field is ignored during capability"
         + @" negotiation and SHOULD be set to ORD_LEVEL_1_ORDERS (1).");
     site.CaptureRequirementIfAreEqual<ushort>(0, order.numberFonts, 1155,
         @"In TS_ORDER_CAPABILITYSET structure, the numberFonts field is ignored during capability "
         + @"negotiation and SHOULD be set to 0.");
     site.CaptureRequirementIfIsTrue((order.orderFlags & orderFlags_Values.NEGOTIATEORDERSUPPORT) == orderFlags_Values.NEGOTIATEORDERSUPPORT, 1159,
         @"In TS_ORDER_CAPABILITYSET structure, if the orderFlags is  NEGOTIATEORDERSUPPORT 0x0002 that "
         + @"indicates support for negotiating drawing orders in the orderSupport field. This flag MUST be set in the orderFlags field.");
     site.CaptureRequirementIfIsTrue((order.orderFlags & orderFlags_Values.ZEROBOUNDSDELTASSUPPORT) == orderFlags_Values.ZEROBOUNDSDELTASSUPPORT, 1160,
         @"In TS_ORDER_CAPABILITYSET structure, if the orderFlags is  ZEROBOUNDSDELTASSUPPORT 0x0008 that"
         + @" indicates support for the order encoding flag for zero bounds delta coordinates. This flag"
         + @" MUST be set in the orderFlags field.");
 }
        /// <summary>
        /// Create a TS_ORDER_CAPABILITYSET type Capability, 2.2.7.1.3   
        /// Problem: contain hardCode as SDK bug(miss member)
        /// </summary>
        /// <param name="orderSupport">An array of 32 bytes indicating support for various primary drawing orders. 
        /// The indices of this array are the negotiation indices for the primary orders specified in [MS-RDPEGDI] section 2.2.2.2.1.1.2.</param>
        /// <param name="negoOrdSupport">Indicates support for specifying supported drawing orders in the orderSupport field. 
        /// This flag MUST be set.</param>
        /// <param name="zbSDELT">Indicates support for the TS_ZERO_BOUNDS_DELTAS (0x20) flag (see [MS-RDPEGDI] 
        /// section 2.2.2.2.1.1.2). The client MUST set this flag.</param>
        /// <param name="colorIdx">Indicates support for sending color indices (not RGB values) in orders.</param>
        /// <param name="spBrush">Indicates that this party can receive only solid and pattern brushes.</param>
        /// <param name="ordFlagsExFlags">Indicates that the orderSupportExFlags field contains valid data.</param>
        /// <param name="cbRev3">The Cache Bitmap (Revision 3) Secondary Drawing Order ([MS-RDPEGDI] section 2.2.2.2.1.2.8) 
        /// is supported.</param>
        /// <param name="afmSupport">The Frame Marker Alternate Secondary Drawing Order ([MS-RDPEGDI] section 2.2.2.2.1.3.7)
        /// is supported.</param>
        /// <returns>TS_ORDER_CAPABILITYSET type Capability</returns>
        public static TS_ORDER_CAPABILITYSET CreateOrderCapSet(byte[] orderSupport, bool negoOrdSupport, bool zbSDELT, bool colorIdx, bool spBrush, bool ordFlagsExFlags,
            bool cbRev3, bool afmSupport)
        {
            TS_ORDER_CAPABILITYSET orderCapabilitySet = new TS_ORDER_CAPABILITYSET();

            orderCapabilitySet.capabilitySetType = capabilitySetType_Values.CAPSTYPE_ORDER;
            //A 16-element array of 8-bit, unsigned integers. Terminal descriptor.
            //This field is ignored and SHOULD be set to all zeros.
            orderCapabilitySet.terminalDescriptor = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            orderCapabilitySet.pad4octetsA = 1000000;
            //A 16-bit, unsigned integer. X granularity used in conjunction with the SaveBitmap Primary Drawing Order (see [MS-RDPEGDI] section 2.2.2.2.1.1.2.12).
            //This value is ignored and assumed to be 1.
            orderCapabilitySet.desktopSaveXGranularity = 1;
            //A 16-bit, unsigned integer. Y granularity used in conjunction with the SaveBitmap Primary Drawing Order (see [MS-RDPEGDI] section 2.2.2.2.1.1.2.12).
            //This value is ignored and assumed to be 20.
            orderCapabilitySet.desktopSaveYGranularity = 20;
            orderCapabilitySet.pad2octetsA = 0;
            //A 16-bit, unsigned integer. Maximum order level. This value is ignored and SHOULD be set to ORD_LEVEL_1_ORDERS (1).
            orderCapabilitySet.maximumOrderLevel = 1;
            //A 16-bit, unsigned integer. Number of fonts. This value is ignored and SHOULD be set to 0.
            orderCapabilitySet.numberFonts = 0;
            if (negoOrdSupport)
                orderCapabilitySet.orderFlags |= orderFlags_Values.NEGOTIATEORDERSUPPORT;
            if (zbSDELT)
                orderCapabilitySet.orderFlags |= orderFlags_Values.ZEROBOUNDSDELTASSUPPORT;
            if (colorIdx)
                orderCapabilitySet.orderFlags |= orderFlags_Values.COLORINDEXSUPPORT;
            if (spBrush)
                orderCapabilitySet.orderFlags |= orderFlags_Values.SOLIDPATTERNBRUSHONLY;
            if (ordFlagsExFlags)
                orderCapabilitySet.orderFlags |= (orderFlags_Values)0x0080;//<hardcode>

            orderCapabilitySet.orderSupport = orderSupport;

            //A 16-bit, unsigned integer. Values in this field MUST be ignored.<?>
            orderCapabilitySet.textFlags = 1697;

            if (cbRev3)
                orderCapabilitySet.orderSupportExFlags |= orderSupportExFlags_values.ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT;
            if (afmSupport)
                orderCapabilitySet.orderSupportExFlags |= orderSupportExFlags_values.ORDERFLAGS_EX_ALTSEC_FRAME_MARKER_SUPPORT;

            orderCapabilitySet.pad4octetsB = 1000000;
            //A 32-bit, unsigned integer. The maximum usable size of bitmap space for bitmap packing in the SaveBitmap Primary Drawing Order (see [MS-RDPEGDI] section 2.2.2.2.1.1.2.12).
            //This field is ignored by the client and assumed to be 230400 bytes (480 * 480).<?>
            orderCapabilitySet.desktopSaveSize = 1000000;
            orderCapabilitySet.pad2octetsC = 1;
            orderCapabilitySet.pad2octetsD = 0;
            //A 16-bit, unsigned integer. ANSI code page descriptor being used by the client (for a list of code pages, see [MSDN-CP]).
            //This field is ignored by the client and SHOULD be set to 0 by the server.
            orderCapabilitySet.textANSICodePage = 0;
            orderCapabilitySet.pad2octetsE = 0;
            orderCapabilitySet.lengthCapability = (ushort)(sizeof(ushort) * 14
                                                + sizeof(uint) * 3
                                                + orderCapabilitySet.terminalDescriptor.Length
                                                + orderCapabilitySet.orderSupport.Length);
            return orderCapabilitySet;
        }
        /// <summary>
        /// Parse TS_ORDER_CAPABILITYSET
        /// </summary>
        /// <param name="data">data to be parsed</param>
        /// <returns>TS_ORDER_CAPABILITYSET</returns>
        private TS_ORDER_CAPABILITYSET ParseCapsTypeOrder(byte[] data)
        {
            int currentIndex = 0;
            TS_ORDER_CAPABILITYSET set = new TS_ORDER_CAPABILITYSET();

            // TS_ORDER_CAPABILITYSET: capabilitySetType
            set.capabilitySetType = (capabilitySetType_Values)ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: lengthCapability
            set.lengthCapability = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: terminalDescriptor
            set.terminalDescriptor = GetBytes(data, ref currentIndex,
                ConstValue.TS_ORDER_CAPABILITYSET_TERMINAL_DESCRIPTOR_LENGTH);

            // TS_ORDER_CAPABILITYSET: pad4octetsA
            set.pad4octetsA = ParseUInt32(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: desktopSaveXGranularity
            set.desktopSaveXGranularity = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: desktopSaveYGranularity
            set.desktopSaveYGranularity = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: pad2octetsA
            set.pad2octetsA = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: maximumOrderLevel
            set.maximumOrderLevel = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: numberFonts
            set.numberFonts = ParseUInt16(data, ref currentIndex, false); ;

            // TS_ORDER_CAPABILITYSET: orderFlags
            set.orderFlags = (orderFlags_Values)ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: orderSupport
            set.orderSupport = GetBytes(data, ref currentIndex,
                ConstValue.TS_ORDER_CAPABILITYSET_ORDER_SUPPORT_LENGTH);

            // TS_ORDER_CAPABILITYSET: textFlags
            set.textFlags = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: orderSupportExFlags
            set.orderSupportExFlags = (orderSupportExFlags_values)ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: pad4octetsB
            set.pad4octetsB = ParseUInt32(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: desktopSaveSize
            set.desktopSaveSize = ParseUInt32(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: pad2octetsC
            set.pad2octetsC = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: pad2octetsD
            set.pad2octetsD = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: textANSICodePage
            set.textANSICodePage = ParseUInt16(data, ref currentIndex, false);

            // TS_ORDER_CAPABILITYSET: pad2octetsE
            set.pad2octetsE = ParseUInt16(data, ref currentIndex, false);

            // Check if data length is consistent with the decoded struct length
            VerifyDataLength(data.Length, currentIndex, ConstValue.ERROR_MESSAGE_DATA_LENGTH_INCONSISTENT);
            return set;
        }