@Test(expected = TcTmException.class) public void testInvalidTwoBytesEncapsulation() throws TcTmException { pd.process(new byte[] { (byte) 0xE1, 1 }, 0, 2); }
public void process(byte[] data, int offset, int length) throws TcTmException { while (length > 0) { if (headerOffset == 0) { byte d0 = data[offset]; offset++; length--; headerLength = getHeaderLength(d0); header[0] = d0; if (headerLength == 1) { if (stripEncapsulationHeader) { packet = ZERO_BYTES; } else { packet = new byte[] { d0 }; } sendToConsumer(); headerOffset = 0; } else { headerOffset++; } } else if (headerOffset < headerLength) { int n = Math.min(length, headerLength - headerOffset); System.arraycopy(data, offset, header, headerOffset, n); offset += n; headerOffset += n; length -= n; if (headerOffset == headerLength) { allocatePacket(); } } else { int n = Math.min(packet.length - packetOffset, length); System.arraycopy(data, offset, packet, packetOffset, n); offset += n; packetOffset += n; length -= n; if (packetOffset == packet.length) { sendToConsumer(); packet = null; headerOffset = 0; } } } }
PacketDecoder { public void process(byte[] data, int offset, int length) throws TcTmException { while (length > 0) { if (headerOffset == 0) { byte d0 = data[offset]; offset++; length--; headerLength = getHeaderLength(d0); header[0] = d0; if (headerLength == 1) { if (stripEncapsulationHeader) { packet = ZERO_BYTES; } else { packet = new byte[] { d0 }; } sendToConsumer(); headerOffset = 0; } else { headerOffset++; } } else if (headerOffset < headerLength) { int n = Math.min(length, headerLength - headerOffset); System.arraycopy(data, offset, header, headerOffset, n); offset += n; headerOffset += n; length -= n; if (headerOffset == headerLength) { allocatePacket(); } } else { int n = Math.min(packet.length - packetOffset, length); System.arraycopy(data, offset, packet, packetOffset, n); offset += n; packetOffset += n; length -= n; if (packetOffset == packet.length) { sendToConsumer(); packet = null; headerOffset = 0; } } } } }
PacketDecoder { public void process(byte[] data, int offset, int length) throws TcTmException { while (length > 0) { if (headerOffset == 0) { byte d0 = data[offset]; offset++; length--; headerLength = getHeaderLength(d0); header[0] = d0; if (headerLength == 1) { if (stripEncapsulationHeader) { packet = ZERO_BYTES; } else { packet = new byte[] { d0 }; } sendToConsumer(); headerOffset = 0; } else { headerOffset++; } } else if (headerOffset < headerLength) { int n = Math.min(length, headerLength - headerOffset); System.arraycopy(data, offset, header, headerOffset, n); offset += n; headerOffset += n; length -= n; if (headerOffset == headerLength) { allocatePacket(); } } else { int n = Math.min(packet.length - packetOffset, length); System.arraycopy(data, offset, packet, packetOffset, n); offset += n; packetOffset += n; length -= n; if (packetOffset == packet.length) { sendToConsumer(); packet = null; headerOffset = 0; } } } } PacketDecoder(int maxPacketLength, Consumer<byte[]> consumer); }
PacketDecoder { public void process(byte[] data, int offset, int length) throws TcTmException { while (length > 0) { if (headerOffset == 0) { byte d0 = data[offset]; offset++; length--; headerLength = getHeaderLength(d0); header[0] = d0; if (headerLength == 1) { if (stripEncapsulationHeader) { packet = ZERO_BYTES; } else { packet = new byte[] { d0 }; } sendToConsumer(); headerOffset = 0; } else { headerOffset++; } } else if (headerOffset < headerLength) { int n = Math.min(length, headerLength - headerOffset); System.arraycopy(data, offset, header, headerOffset, n); offset += n; headerOffset += n; length -= n; if (headerOffset == headerLength) { allocatePacket(); } } else { int n = Math.min(packet.length - packetOffset, length); System.arraycopy(data, offset, packet, packetOffset, n); offset += n; packetOffset += n; length -= n; if (packetOffset == packet.length) { sendToConsumer(); packet = null; headerOffset = 0; } } } } PacketDecoder(int maxPacketLength, Consumer<byte[]> consumer); void process(byte[] data, int offset, int length); void reset(); boolean hasIncompletePacket(); boolean skipIdlePackets(); void skipIdlePackets(boolean skipIdlePackets); boolean stripEncapsulationHeader(); void stripEncapsulationHeader(boolean stripEncapsulationHeader); }
PacketDecoder { public void process(byte[] data, int offset, int length) throws TcTmException { while (length > 0) { if (headerOffset == 0) { byte d0 = data[offset]; offset++; length--; headerLength = getHeaderLength(d0); header[0] = d0; if (headerLength == 1) { if (stripEncapsulationHeader) { packet = ZERO_BYTES; } else { packet = new byte[] { d0 }; } sendToConsumer(); headerOffset = 0; } else { headerOffset++; } } else if (headerOffset < headerLength) { int n = Math.min(length, headerLength - headerOffset); System.arraycopy(data, offset, header, headerOffset, n); offset += n; headerOffset += n; length -= n; if (headerOffset == headerLength) { allocatePacket(); } } else { int n = Math.min(packet.length - packetOffset, length); System.arraycopy(data, offset, packet, packetOffset, n); offset += n; packetOffset += n; length -= n; if (packetOffset == packet.length) { sendToConsumer(); packet = null; headerOffset = 0; } } } } PacketDecoder(int maxPacketLength, Consumer<byte[]> consumer); void process(byte[] data, int offset, int length); void reset(); boolean hasIncompletePacket(); boolean skipIdlePackets(); void skipIdlePackets(boolean skipIdlePackets); boolean stripEncapsulationHeader(); void stripEncapsulationHeader(boolean stripEncapsulationHeader);  }