Class KlvContext

java.lang.Object
org.codice.ddf.libs.klv.KlvContext

public class KlvContext extends Object
Represents the context used for decoding KLV-encoded data. A KlvContext specifies the key length and length encoding type for the data elements (the fundamental units of KLV) in the data as well as what data elements can be found within.

Basically, this class makes it possible to decode KLV-encoded data with an arbitrary structure. The value portion of each KLV set can contain either a raw data value (such as a number or string) or another chain of data elements (sometimes called a local set). So, whatever is decoding it needs to know how to interpret the values of the data elements it finds. This class allows you to provide that information so your KLV can be decoded.

In essence, a KlvContext represents the structure of the encoded KLV data you wish to decode.

  • Constructor Details

    • KlvContext

      public KlvContext(Klv.KeyLength keyLength, Klv.LengthEncoding lengthEncoding)
      Constructs a KlvContext containing the properties of a specific KLV-encoded data set.
      Parameters:
      keyLength - the key length of the data elements inside the KLV-encoded data
      lengthEncoding - the length encoding method of the data elements inside the KLV-encoded data
      Throws:
      IllegalArgumentException - if any of the arguments are null
    • KlvContext

      public KlvContext(Klv.KeyLength keyLength, Klv.LengthEncoding lengthEncoding, Collection<? extends KlvDataElement> dataElements)
      Constructs a KlvContext containing the properties of a specific KLV-encoded data set, including the data elements that could possibly be found within the data.
      Parameters:
      keyLength - the key length of the data elements inside the KLV-encoded data
      lengthEncoding - the length encoding method of the date elements inside the KLV-encoded data
      dataElements - the data elements that could possibly be found inside the data
      Throws:
      IllegalArgumentException - if any of the arguments are null
  • Method Details

    • addDataElement

      public void addDataElement(KlvDataElement dataElement)
      Adds a KlvDataElement to the KlvContext.
      Parameters:
      dataElement - the KlvDataElement to add
      Throws:
      IllegalArgumentException - if the argument is null
    • addDataElements

      public void addDataElements(Collection<? extends KlvDataElement> dataElements)
      Adds multiple KlvDataElements to the KlvContext.
      Parameters:
      dataElements - the KlvDataElements to add
      Throws:
      IllegalArgumentException - if the argument is null
    • getKeyLength

      public Klv.KeyLength getKeyLength()
    • getLengthEncoding

      public Klv.LengthEncoding getLengthEncoding()
    • getDataElements

      public Map<String,KlvDataElement> getDataElements()
      Returns the KlvDataElements inside this KlvContext as a Map, where the keys are the data elements' names and the values are the data elements.
      Returns:
      a Map containing the KlvDataElements inside this KlvContext
    • hasDataElement

      public boolean hasDataElement(String name)
      Determines whether this KlvContext contains a KlvDataElement with the given name.
      Parameters:
      name - the data element's name
      Returns:
      whether this KlvContext contains a data element with the name name
    • getDataElementByName

      public KlvDataElement getDataElementByName(String name)
      Returns the KlvDataElement in this KlvContext with the given name.
      Parameters:
      name - the data element's name
      Returns:
      the KlvDataElement in this KlvContext with the name name, or null if this KlvContext does not have a KlvDataElement with the name name