E - type of enumerationpublic abstract class AbstractBitCodec<E extends OfpEnum> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected E[] |
flagSet
The union of all flags that can be bitmapped, across all versions.
|
protected int[] |
masks
Bit masks indicating valid bit placements for each protocol version.
|
protected static int |
NA_CODE
The value used to indicate that a flag is not applicable (for a given
protocol version.
|
| Constructor and Description |
|---|
AbstractBitCodec(int[] masks,
E[] flagSet)
Constructs the codec, which squirrels away the bit masks and flag set
for use during the
encode(java.util.Set<E>, com.h3c.of.lib.ProtocolVersion) and decode(int, com.h3c.of.lib.ProtocolVersion) methods. |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
cannotBeMapped(int value)
This test should return true if the given value (code, or bit) cannot
be mapped into the bitmap; false if it is okay.
|
Set<E> |
decode(int bitmap,
ProtocolVersion pv)
Decodes the given int value into a set of flags from the enumeration
class associated with this codec instance.
|
protected void |
disposeStorage()
Gives subclasses an opportunity to prepare temporary storage for
garbage collection.
|
int |
encode(Set<E> flags,
ProtocolVersion pv)
Encodes the given set of flags into a bitmap represented by an integer
value.
|
protected abstract String |
formatValue(int value)
Returns the appropriate formatting of the value for an exception message.
|
protected abstract int |
getBitToMap(E flag,
ProtocolVersion pv)
Given a flag and a protocol version, this method should return the
appropriate bit in the map that represents this flag.
|
protected abstract int |
getValue(E flag,
ProtocolVersion pv)
Returns the value (bit, or code) from the given flag, for the
given version.
|
protected void |
initStorage()
Gives subclasses an opportunity to initialize temporary storage before
validation of the flag set.
|
protected static final int NA_CODE
protected final int[] masks
public AbstractBitCodec(int[] masks,
E[] flagSet)
encode(java.util.Set<E>, com.h3c.of.lib.ProtocolVersion) and decode(int, com.h3c.of.lib.ProtocolVersion) methods.
Note that, most of the time, the flag set should be
EnumClass.values().masks - the "valid bit position" masks; one for each
protocol versionflagSet - the set of flags to iterate over during decodeNullPointerException - if either parameter is nullIllegalArgumentException - if masks does not include a mask for
every protocol version or flagSet is not valid for this codecprotected void initStorage()
protected void disposeStorage()
protected abstract int getValue(E flag, ProtocolVersion pv)
flag - the flagpv - the protocol versionprotected abstract boolean cannotBeMapped(int value)
value - the value to testprotected abstract String formatValue(int value)
value - the valuepublic Set<E> decode(int bitmap, ProtocolVersion pv)
strict parsing, an exception will be thrown if a 1-bit is discovered in
an invalid position. If non-strict parsing is in effect, such invalid
bits will be ignored silently.bitmap - the encoded bitmappv - the protocol versionNullPointerException - if pv is nullVersionMismatchException - if a bit position is not supported
in the given version, and strict parsing is enabledprotected abstract int getBitToMap(E flag, ProtocolVersion pv)
flag - the flagpv - the protocol versionpublic int encode(Set<E> flags, ProtocolVersion pv)
flags parameter may be empty or null, in which case
a bitmap of 0 (zero) is returned.flags - the set of flags to be encodedpv - the protocol versionNullPointerException - if protocol version is nullVersionMismatchException - if a flag is present that is not
supported in the given protocol versionIllegalArgumentException - if a flag is present that cannot be
mapped into the bitmapCopyright © 2014. All Rights Reserved.