Skip to content
Browse files

Slightly improve performance

  • Loading branch information...
1 parent 71a5ecb commit 012879c37c625c054e0aa7bce4821f7f3ea9673c @kunklejr kunklejr committed Jan 5, 2012
Showing with 7 additions and 12 deletions.
  1. +7 −12 lib/pcap-parser.js
View
19 lib/pcap-parser.js
@@ -5,6 +5,12 @@ var fs = require('fs');
var GLOBAL_HEADER_LENGTH = 24; //bytes
var PACKET_HEADER_LENGTH = 16; //bytes
+var parsers = {
+ 'globalHeader': parseGlobalHeader,
+ 'packetHeader': parsePacketHeader,
+ 'packetBody' : parsePacketBody
+};
+
function onError(err) {
this.emit('error', err);
}
@@ -15,18 +21,7 @@ function onEnd() {
function onData(data) {
updateBuffer.call(this, data);
- while (process.call(this)) {}
-}
-
-function process() {
- switch (this.state) {
- case 'globalHeader':
- return parseGlobalHeader.call(this);
- case 'packetHeader':
- return parsePacketHeader.call(this);
- case 'packetBody':
- return parsePacketBody.call(this);
- }
+ while (parsers[this.state].call(this)) {}
}
function updateBuffer(data) {

0 comments on commit 012879c

Please sign in to comment.
Something went wrong with that request. Please try again.