Is there any interest in adding support for a Boolean type? If you think this fits, I can PR it.
I implemented it like this:
function encode (value, buffer, offset) {
if (typeof value !== 'boolean') throw new TypeError('value must be a boolean')
if (!buffer) buffer = Buffer.allocUnsafe(1)
if (!offset) offset = 0
buffer.writeUInt8(Number(value), offset)
return buffer
}
function decode (buffer, offset, end) {
if (!offset) offset = 0
if (!end) return Boolean(buffer.readUInt8(offset))
return Boolean(buffer.slice(offset, end).readUInt8(0))
}
function encodingLength () {
return 1
}
encode.bytes = decode.bytes = 1
export const VBoolean = {
encode,
decode,
encodingLength
}
Is there any interest in adding support for a
Booleantype? If you think this fits, I can PR it.I implemented it like this: