Class TLV
java.lang.Object
org.apache.directory.api.asn1.ber.tlv.TLV
This class is used to store Tags, Lengths and Values decoded from a PDU.
- Author:
- Apache Directory Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytetag flag for the primitive/constructed bit - 0010 0000 - 0x20static final intValue of the reserved extensionstatic final intA mask to get the Length formstatic final intA mask to get the long form valuestatic final inttag mask for the short tag format - 0001 1111 - 0x1Fstatic final bytemask to get the type class valuestatic final bytevalue for the universal type class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]getBytes(int length) Utility function that return a byte array representing the lengthintGet the TLV expected length.intgetId()Get the TLV's IDintGet the TLV's lengthintGet the already read bytesintGet the TLV's lengthstatic intgetNbBytes(int length) Utility function that return the number of bytes necessary to store the lengthGet the TLV's parentintgetSize()The TLV size is calculated by adding the Tag's size, the Length's size and the Value's length, if any.bytegetTag()Get the TLV's taggetValue()Get the TLV's value partvoidIncrement the number of bytes read for this TLVbooleanChecks to see if the current tlv's tag is constructed.static booleanisConstructed(byte tag) Checks to see if the tag is constructed.static booleanisPrimitive(byte tag) Checks to see if the tag represented by this Tag is primitive or constructed.static booleanisUniversal(byte tag) Tells if the tag is Universal or notvoidreset()Reset the TLV, so it can be reused for the next PDU decoding.voidsetExpectedLength(int expectedLength) Set the new expected length of the current TLV.voidsetLength(int length) Set the TLV's lengthvoidsetLengthBytesRead(int lengthBytesRead) Set the currently read TLV's length bytes.voidsetLengthNbBytes(int lengthNbBytes) Set the number of bytes we should use to store the TLV's length.voidSet the TLV's parentvoidsetTag(byte tag) Set a tag value for this TLV.toString()Get a String representation of the TLV
-
Field Details
-
CONSTRUCTED_FLAG
public static final byte CONSTRUCTED_FLAGtag flag for the primitive/constructed bit - 0010 0000 - 0x20- See Also:
-
TYPE_CLASS_MASK
public static final byte TYPE_CLASS_MASKmask to get the type class value- See Also:
-
TYPE_CLASS_UNIVERSAL
public static final byte TYPE_CLASS_UNIVERSALvalue for the universal type class- See Also:
-
SHORT_MASK
public static final int SHORT_MASKtag mask for the short tag format - 0001 1111 - 0x1F- See Also:
-
LENGTH_LONG_FORM
public static final int LENGTH_LONG_FORMA mask to get the Length form- See Also:
-
LENGTH_EXTENSION_RESERVED
public static final int LENGTH_EXTENSION_RESERVEDValue of the reserved extension- See Also:
-
LENGTH_SHORT_MASK
public static final int LENGTH_SHORT_MASKA mask to get the long form value- See Also:
-
-
Constructor Details
-
TLV
public TLV(int id) Creates a new TLV object.- Parameters:
id- the TLV's id
-
-
Method Details
-
isConstructed
public static boolean isConstructed(byte tag) Checks to see if the tag is constructed.- Parameters:
tag- the TLV's tag- Returns:
- true if constructed, false if primitive
-
isConstructed
public boolean isConstructed()Checks to see if the current tlv's tag is constructed.- Returns:
- true if constructed, false if primitive
-
isPrimitive
public static boolean isPrimitive(byte tag) Checks to see if the tag represented by this Tag is primitive or constructed.- Parameters:
tag- the tag to be checked- Returns:
- true if it is primitive, false if it is constructed
-
isUniversal
public static boolean isUniversal(byte tag) Tells if the tag is Universal or not- Parameters:
tag- the tag to be checked- Returns:
- true if it is primitive, false if it is constructed
-
reset
public void reset()Reset the TLV, so it can be reused for the next PDU decoding. -
getTag
public byte getTag()Get the TLV's tag- Returns:
- Returns the tag.
-
setTag
public void setTag(byte tag) Set a tag value for this TLV.- Parameters:
tag- the tag field for this TLV.
-
getValue
-
getSize
public int getSize()The TLV size is calculated by adding the Tag's size, the Length's size and the Value's length, if any.- Returns:
- Returns the size of the TLV.
-
getNbBytes
public static int getNbBytes(int length) Utility function that return the number of bytes necessary to store the length- Parameters:
length- The length to store in a byte array- Returns:
- The number of bytes necessary to store the length.
- See Also:
-
getBytes
public static byte[] getBytes(int length) Utility function that return a byte array representing the length- Parameters:
length- The length to store in a byte array- Returns:
- The byte array representing the length.
-
getParent
-
setParent
-
getExpectedLength
public int getExpectedLength()Get the TLV expected length.- Returns:
- The expectedLength.
-
setExpectedLength
public void setExpectedLength(int expectedLength) Set the new expected length of the current TLV.- Parameters:
expectedLength- The expectedLength to set.
-
getLengthNbBytes
public int getLengthNbBytes()Get the TLV's length- Returns:
- The number of bytes necessary to store the TLV's length
-
setLengthNbBytes
public void setLengthNbBytes(int lengthNbBytes) Set the number of bytes we should use to store the TLV's length.- Parameters:
lengthNbBytes- The number of bytes necessary to store the TLV's length
-
getLength
public int getLength()Get the TLV's length- Returns:
- the TLV's length
-
setLength
public void setLength(int length) Set the TLV's length- Parameters:
length- the TLV's length
-
getLengthBytesRead
public int getLengthBytesRead()Get the already read bytes- Returns:
- The currently read TLV's length bytes
-
setLengthBytesRead
public void setLengthBytesRead(int lengthBytesRead) Set the currently read TLV's length bytes.- Parameters:
lengthBytesRead- the currently read TLV's length bytes
-
incLengthBytesRead
public void incLengthBytesRead()Increment the number of bytes read for this TLV -
getId
public int getId()Get the TLV's ID- Returns:
- The TLV's ID
-
toString
-