Created
January 21, 2013 18:56
-
-
Save fbettag/4588348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def apply(sender: InetSocketAddress, buf: ByteBuf): Try[NetFlowV5Packet] = Try[NetFlowV5Packet] { | |
val version = buf.getInteger(0, 2).toInt | |
if (version != 5) return Failure(new InvalidFlowVersionException(version)) | |
val packet = NetFlowV5Packet(sender, buf.readableBytes) | |
packet.count = buf.getInteger(2, 2).toInt | |
if (packet.count <= 0 || buf.readableBytes < headerSize + packet.count * flowSize) | |
return Failure(new CorruptFlowPacketException) | |
packet.uptime = buf.getInteger(4, 4) / 1000 | |
packet.date = new org.joda.time.DateTime(buf.getInteger(8, 4) * 1000) | |
packet.flowSequence = buf.getInteger(16, 4) | |
packet.engineType = buf.getInteger(20, 1).toInt | |
packet.engineId = buf.getInteger(21, 1).toInt | |
packet.samplingInterval = buf.getInteger(22, 2).toInt | |
packet.flows = Array.range(0, packet.count) flatMap { i => | |
NetFlowV5(sender, buf.slice(headerSize + (i * flowSize), flowSize), packet.uptime).toOption | |
} | |
packet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment