Comparing version 1.5.1 to 1.6.0
# History | ||
## 1.6.0 | ||
* add full packet parser | ||
## 1.5.1 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "protodef", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "A simple yet powerful way to define binary protocols", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,4 +8,5 @@ const ProtoDef = require("./protodef"); | ||
Parser:require("./serializer").Parser, | ||
FullPacketParser:require("./serializer").FullPacketParser, | ||
types:proto.types, | ||
utils:require("./utils") | ||
}; |
@@ -62,5 +62,35 @@ const Transform = require("readable-stream").Transform; | ||
class FullPacketParser extends Transform { | ||
constructor(proto,mainType) { | ||
super({ readableObjectMode: true }); | ||
this.proto=proto; | ||
this.mainType=mainType; | ||
} | ||
parsePacketBuffer(buffer) { | ||
return this.proto.parsePacketBuffer(this.mainType,buffer); | ||
} | ||
_transform(chunk, enc, cb) { | ||
try { | ||
var packet = this.parsePacketBuffer(chunk); | ||
if(packet.metadata.size!=chunk.length) | ||
cb(new Error("Chunk size is "+chunk.length+" but only "+packet.metadata.size+" was read "+chunk.buffer.toString("hex"))); | ||
else { | ||
this.push(packet); | ||
cb(); | ||
} | ||
} | ||
catch(e) { | ||
cb(e); | ||
} | ||
} | ||
} | ||
module.exports={ | ||
Serializer:Serializer, | ||
Parser:Parser | ||
Parser:Parser, | ||
FullPacketParser:FullPacketParser | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99830
3106