varstruct-match
create varstruct codec that can match multiple data types.
Each item encoded is prefixed with a type value, I suggest using a byte or a varint.
Example
var varmatch = var varstruct = var VarUIntProtobuf = //create some simple codecsvar foobar = //test functions - return true if the argument can be encoded with this codec. { return t && tfoo && tbar } { return typeof n === 'number' && n % 1 === 0 } var codec = //encode with the first rulecodec//=> <Buffer 01 01 02> //encode with the second rulecodec//=> <Buffer 02 03 01 02 03 04 05 06> //encode with the third rulecodec//=> <Buffer 03 07>
once the codec is defined, you can just pass any valid object.
API
varmatch(tagCodec, [typeCodec1, typeCodec2, ..., typeCodecN])
create an instance, specifying the codec for the matching field.
License
MIT