public static NetFlowV5Packet parsePacket(ByteBuf bb) {
        final int readableBytes = bb.readableBytes();

        final NetFlowV5Header header = parseHeader(bb.slice(bb.readerIndex(), HEADER_LENGTH));
        final int packetLength = HEADER_LENGTH + header.count() * RECORD_LENGTH;
        if (header.count() <= 0 || readableBytes < packetLength) {
            throw new CorruptFlowPacketException("Insufficient data (expected: " + packetLength + " bytes, actual: " + readableBytes + " bytes)");
        }

        final ImmutableList.Builder<NetFlowV5Record> records = ImmutableList.builder();
        int offset = HEADER_LENGTH;
        for (int i = 0; i < header.count(); i++) {
            records.add(parseRecord(bb.slice(offset + bb.readerIndex(), RECORD_LENGTH)));
            offset += RECORD_LENGTH;
        }

        return NetFlowV5Packet.create(header, records.build(), offset);
    }
@Test
    public void testParse1() throws IOException {
        final byte[] b = Resources.toByteArray(Resources.getResource("netflow-data/netflow-v5-1.dat"));
        NetFlowV5Packet packet = NetFlowV5Parser.parsePacket(Unpooled.wrappedBuffer(b));
        assertNotNull(packet);

        NetFlowV5Header h = packet.header();
        assertEquals(5, h.version());
        assertEquals(2, h.count());
        assertEquals(3381L, h.sysUptime());
        assertEquals(1430591888L, h.unixSecs());
        assertEquals(280328000, h.unixNsecs());

        final List<NetFlowV5Record> records = packet.records();
        assertEquals(2, records.size());

        final NetFlowV5Record record1 = records.get(0);
        assertEquals(InetAddresses.forString("10.0.2.15"), record1.dstAddr());
        assertEquals(6, record1.protocol());
        assertEquals(0, record1.srcAs());
        assertEquals(InetAddresses.forString("10.0.2.2"), record1.srcAddr());
        assertEquals(2577L, record1.last());
        assertEquals(22, record1.dstPort());
        assertEquals(230L, record1.octetCount());
        assertEquals(54435, record1.srcPort());
        assertEquals(0, record1.srcMask());
        assertEquals(0, record1.tos());
        assertEquals(0, record1.inputIface());
        assertEquals(InetAddresses.forString("0.0.0.0"), record1.nextHop());
        assertEquals(16, record1.tcpFlags());
        assertEquals(0, record1.dstAs());
        assertEquals(0, record1.outputIface());
        assertEquals(4294967295L, record1.first());
        assertEquals(0, record1.dstMask());
        assertEquals(5L, record1.packetCount());


        final NetFlowV5Record record2 = records.get(1);
        assertEquals(InetAddresses.forString("10.0.2.2"), record2.dstAddr());
        assertEquals(6, record2.protocol());
        assertEquals(0, record2.srcAs());
        assertEquals(InetAddresses.forString("10.0.2.15"), record2.srcAddr());
        assertEquals(2577L, record2.last());
        assertEquals(54435, record2.dstPort());
        assertEquals(304L, record2.octetCount());
        assertEquals(22, record2.srcPort());
        assertEquals(0, record2.srcMask());
        assertEquals(0, record2.tos());
        assertEquals(0, record2.inputIface());
        assertEquals(InetAddresses.forString("0.0.0.0"), record2.nextHop());
        assertEquals(24, record2.tcpFlags());
        assertEquals(0, record2.dstAs());
        assertEquals(0, record2.outputIface());
        assertEquals(4294967295L, record2.first());
        assertEquals(0, record2.dstMask());
        assertEquals(4L, record2.packetCount());
    }