Package org.codice.ddf.libs.klv
Class KlvContext
java.lang.Object
org.codice.ddf.libs.klv.KlvContext
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 Summary
ConstructorsConstructorDescriptionKlvContext(Klv.KeyLength keyLength, Klv.LengthEncoding lengthEncoding) Constructs aKlvContextcontaining the properties of a specific KLV-encoded data set.KlvContext(Klv.KeyLength keyLength, Klv.LengthEncoding lengthEncoding, Collection<? extends KlvDataElement> dataElements) Constructs aKlvContextcontaining the properties of a specific KLV-encoded data set, including the data elements that could possibly be found within the data. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataElement(KlvDataElement dataElement) Adds aKlvDataElementto theKlvContext.voidaddDataElements(Collection<? extends KlvDataElement> dataElements) Adds multipleKlvDataElements to theKlvContext.getDataElementByName(String name) Returns theKlvDataElementin thisKlvContextwith the given name.Returns theKlvDataElements inside thisKlvContextas aMap, where the keys are the data elements' names and the values are the data elements.booleanhasDataElement(String name) Determines whether thisKlvContextcontains aKlvDataElementwith the given name.
-
Constructor Details
-
KlvContext
Constructs aKlvContextcontaining the properties of a specific KLV-encoded data set.- Parameters:
keyLength- the key length of the data elements inside the KLV-encoded datalengthEncoding- 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 aKlvContextcontaining 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 datalengthEncoding- the length encoding method of the date elements inside the KLV-encoded datadataElements- the data elements that could possibly be found inside the data- Throws:
IllegalArgumentException- if any of the arguments are null
-
-
Method Details
-
addDataElement
Adds aKlvDataElementto theKlvContext.- Parameters:
dataElement- theKlvDataElementto add- Throws:
IllegalArgumentException- if the argument is null
-
addDataElements
Adds multipleKlvDataElements to theKlvContext.- Parameters:
dataElements- theKlvDataElements to add- Throws:
IllegalArgumentException- if the argument is null
-
getKeyLength
-
getLengthEncoding
-
getDataElements
Returns theKlvDataElements inside thisKlvContextas aMap, where the keys are the data elements' names and the values are the data elements.- Returns:
- a
Mapcontaining theKlvDataElements inside thisKlvContext
-
hasDataElement
Determines whether thisKlvContextcontains aKlvDataElementwith the given name.- Parameters:
name- the data element's name- Returns:
- whether this
KlvContextcontains a data element with the namename
-
getDataElementByName
Returns theKlvDataElementin thisKlvContextwith the given name.- Parameters:
name- the data element's name- Returns:
- the
KlvDataElementin thisKlvContextwith the namename, or null if thisKlvContextdoes not have aKlvDataElementwith the namename
-