compact-encoding-net
Compact codecs for net types
Last updated 3 years ago by kasperisager .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install compact-encoding-net 
SYNC missed versions from official npm registry.

compact-encoding-net

compact-encoding codecs for net types.

Installation

npm install compact-encoding-net

Codecs

port

Codec for 16 bit port numbers.

const { port } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(port, 8080)

Decoding

cenc.decode(port, buffer)
// 8080

ipv4

Codec for IPv4 addresses.

:warning: The codec is only defined for valid IPv4 addresses.

const { ipv4 } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ipv4, '127.0.0.1')

Decoding

cenc.decode(ipv4, buffer)
// '127.0.0.1'

ipv4Address

Codec for IPv4 addresses plus a port.

const { ipv4Address } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ipv4, { host: '127.0.0.1', port: 8080 })

Decoding

cenc.decode(ipv4Address, buffer)
// { host: '127.0.0.1', port: 8080 }

ipv6

Codec for IPv6 addresses.

:warning: The codec is only defined for valid IPv6 addresses.

const { ipv6 } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ipv6, '::1')

Decoding

cenc.decode(ipv6, buffer)
// '0:0:0:0:0:0:0:1'

ipv6Address

Codec for IPv6 addresses plus a port.

const { ipv6Address } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ipv6Address, { host: '::1', port: 8080 })

Decoding

cenc.decode(ipv6Address, buffer)
// { host: '0:0:0:0:0:0:0:1', port: 8080 }

ip

Codec for dual IPv4/6 addresses.

:warning: The codec is only defined for valid IPv4 and IPv6 addresses.

const { ip } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ip, '::1')

Decoding

cenc.decode(ip, buffer)
// '0:0:0:0:0:0:0:1'

ipAddress

Codec for dual IPv4/6 addresses plus a port.

const { ipAddress } = require('compact-encoding-net')

Encoding

const buffer = cenc.encode(ipAddress, { host: '::1', port: 8080 })

Decoding

cenc.decode(ipv6Address, buffer)
// { host: '0:0:0:0:0:0:0:1', family: 6, port: 8080 }

License

ISC

Current Tags

  • 1.2.0                                ...           latest (2 years ago)

4 Versions

  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE