protocommand
A NodeJS module for parsing fixed sized protocol commands from a Buffer. This is useful for implementing protocol commands such as that of MAIL, RCPT for the SMTP protocol.
Options
Options define the format of the specific protocol.
- size:Integer -> Fixed Command Size e.g. AUTH = 4
- delimiter:String -> Delimiter e.g. AUTH|USERNAME|PASSWORD = '|'
- criteria:Regex -> Test, defaults to /^([a-zA-Z0-9 _-]+)$/ You can set options using
var protocommand = ;protocommandsize = 5;protocommanddelimiter = ',';
Methods
A protocol buffer is required for all methods. You can slightly manipulate the format using the Size, Next and Criteria (REGEX) options. e.g. AUTH username password
get(buffer)
returns either false or String command.
var protocommand = ;var buffer = 15;buffer; ifprotocommand === 'AUTH' /* Do Something */
params(buffer)
parses all parameters following the command and returns in Array format.
var protocommand = ;var buffer = 15;buffer; ifprotocommand === 'AUTH' var params = protocommand; console; // logs: ['admin', 'test']
make(command, param1, param2, ...)
creates a new protocol command and returns in Buffer format.
var protocommand = ;var buffer = protocommand;