text: //----------------------------------------------------------------------------
  //
  // TSDuck - The MPEG Transport Stream Toolkit
  // Copyright (c) 2005-2021, Thierry Lelegard
  // All rights reserved.
  //
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are met:
  //
  // 1. Redistributions of source code must retain the above copyright notice,
  //    this list of conditions and the following disclaimer.
  // 2. Redistributions in binary form must reproduce the above copyright
  //    notice, this list of conditions and the following disclaimer in the
  //    documentation and/or other materials provided with the distribution.
  //
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  // THE POSSIBILITY OF SUCH DAMAGE.
  //
  //----------------------------------------------------------------------------
  
  #include "tsAdaptationFieldDataDescriptor.h"
  #include "tsDescriptor.h"
  #include "tsTablesDisplay.h"
  #include "tsPSIRepository.h"
  #include "tsPSIBuffer.h"
  #include "tsDuckContext.h"
  #include "tsxmlElement.h"
  #include "tsNames.h"
  TSDUCK_SOURCE;
  
  #define MY_XML_NAME u"adaptation_field_data_descriptor"
  #define MY_CLASS ts::AdaptationFieldDataDescriptor
  #define MY_DID ts::DID_ADAPTFIELD_DATA
  #define MY_STD ts::Standards::DVB
  
  TS_REGISTER_DESCRIPTOR(MY_CLASS, ts::EDID::Standard(MY_DID), MY_XML_NAME, MY_CLASS::DisplayDescriptor);
  
  
  //----------------------------------------------------------------------------
  // Constructors
  //----------------------------------------------------------------------------
  
  ts::AdaptationFieldDataDescriptor::AdaptationFieldDataDescriptor(uint8_t id) :
      AbstractDescriptor(MY_DID, MY_XML_NAME, MY_STD, 0),
      adaptation_field_data_identifier(id)
  {
  }
  
  void ts::AdaptationFieldDataDescriptor::clearContent()
  {
      adaptation_field_data_identifier = 0;
  }
  
  ts::AdaptationFieldDataDescriptor::AdaptationFieldDataDescriptor(DuckContext& duck, const Descriptor& desc) :
      AdaptationFieldDataDescriptor()
  {
      deserialize(duck, desc);
  }
  
  
  //----------------------------------------------------------------------------
  // Serialization / deserialization
  //----------------------------------------------------------------------------
  
  void ts::AdaptationFieldDataDescriptor::serializePayload(PSIBuffer& buf) const
  {
      buf.putUInt8(adaptation_field_data_identifier);
  }
  
  void ts::AdaptationFieldDataDescriptor::deserializePayload(PSIBuffer& buf)
  {
      adaptation_field_data_identifier = buf.getUInt8();
  }
  
  
  //----------------------------------------------------------------------------
  // Static method to display a descriptor.
  //----------------------------------------------------------------------------
  
  void ts::AdaptationFieldDataDescriptor::DisplayDescriptor(TablesDisplay& disp, PSIBuffer& buf, const UString& margin, DID did, TID tid, PDS pds)
  {
      if (buf.canReadBytes(1)) {
          const uint8_t id = buf.getUInt8();
          disp << margin << UString::Format(u"Adaptation field data identifier: 0x%X", {id}) << std::endl;
          for (int i = 0; i < 8; ++i) {
              if ((id & (1 << i)) != 0) {
                  disp << margin << "  " << NameFromSection(u"AdaptationFieldDataIdentifier", (1 << i), names::HEXA_FIRST) << std::endl;
              }
          }
      }
  }
  
  
  //----------------------------------------------------------------------------
  // XML serialization
  //----------------------------------------------------------------------------
  
  void ts::AdaptationFieldDataDescriptor::buildXML(DuckContext& duck, xml::Element* root) const
  {
      root->setIntAttribute(u"adaptation_field_data_identifier", adaptation_field_data_identifier, true);
  }
  
  
  //----------------------------------------------------------------------------
  // XML deserialization
  //----------------------------------------------------------------------------
  
  bool ts::AdaptationFieldDataDescriptor::analyzeXML(DuckContext& duck, const xml::Element* element)
  {
      return element->getIntAttribute(adaptation_field_data_identifier, u"adaptation_field_data_identifier", true);
  }
  