Decodes a BER-TLV object from a byte array.
int curIndex = 0;
int endIndex = data.length;
int tag, length = 0;
try {
/* tag */
tag = data[curIndex++] & 0xff;
if (tag == BER_PROACTIVE_COMMAND_TAG) {
/* length */
int temp = data[curIndex++] & 0xff;
if (temp < 0x80) {
length = temp;
} else if (temp == 0x81) {
temp = data[curIndex++] & 0xff;
if (temp < 0x80) {
throw new ResultException(
ResultCode.CMD_DATA_NOT_UNDERSTOOD);
}
length = temp;
} else {
throw new ResultException(
ResultCode.CMD_DATA_NOT_UNDERSTOOD);
}
} else {
if (ComprehensionTlvTag.COMMAND_DETAILS.value() == (tag & ~0x80)) {
tag = BER_UNKNOWN_TAG;
curIndex = 0;
}
}
} catch (IndexOutOfBoundsException e) {
throw new ResultException(ResultCode.REQUIRED_VALUES_MISSING);
} catch (ResultException e) {
throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
}
/* COMPREHENSION-TLVs */
if (endIndex - curIndex < length) {
throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
}
List<ComprehensionTlv> ctlvs = ComprehensionTlv.decodeMany(data,
curIndex);
return new BerTlv(tag, ctlvs);