* @throws NotEnoughDataInBufferException
*/
static public Tlv readTlv(ChannelBuffer buffer) throws NotEnoughDataInBufferException {
// a TLV is at least 4 bytes (tag+length)
if (buffer.readableBytes() < 4) {
throw new NotEnoughDataInBufferException("Parsing TLV tag and length", buffer.readableBytes(), 4);
}
short tag = buffer.readShort();
int length = buffer.readUnsignedShort();
// check if we have enough data for the TLV
if (buffer.readableBytes() < length) {
throw new NotEnoughDataInBufferException("Parsing TLV value", buffer.readableBytes(), length);
}
byte[] value = new byte[length];
buffer.readBytes(value);