JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3096
  • Score
    100M100P100Q165032F
  • License MIT

Internet Printing Protocol (IPP) encoder and decoder

Package Exports

  • ipp-encoder
  • ipp-encoder/constants

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ipp-encoder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ipp-encoder

Internet Printing Protocol (IPP) encoder and decoder.

Build status js-standard-style abstract-encoding

Installation

npm install ipp-encoder

Usage

var ipp = require('ipp-encoder')
var C = ipp.CONSTANTS

// decode binary buffer from IPP client
var decoded = ipp.request.decode(buf)

// prepare response
var response = {
  statusCode: C.SUCCESSFUL_OK,
  requestId: decoded.requestId, // set `operationId` instead if encoding a request
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: C.CHARSET, name: 'attributes-charset', value: 'utf-8' },
      { tag: C.NATURAL_LANG, name: 'attributes-natural-language', value: 'en-us' },
      { tag: C.TEXT_WITH_LANG, name: 'status-message', value: 'successful-ok' }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: C.INTEGER, name: 'job-id', value: 147 },
      { tag: C.NAME_WITH_LANG, name: 'job-name', value: { lang: 'en-us',
value: 'Foobar' } }
    ] }
  ],
  data: new Buffer('...')
}

// encode response to binary buffer
ipp.response.encode(response) // <Buffer 01 01 00 00 ... >

API

ipp.CONSTANTS

An object containing IPP constants. See constants.js for the complete list.

ipp.STATUS_CODES

Map of IPP status codes to descriptive strings. See status-codes.js for the complete list.

ipp.request.decode(buffer[, offset][, length])

Decode an IPP request buffer and returns the request object.

Options:

  • buffer - The buffer containing the request
  • offset - An optional offset from where to start parsing the request (defaults to 0)
  • length - An optional number of bytes to parse (defaults to buffer.length)

Request object structure:

{
  version: {
    major: 1,
    minor: 1
  },
  operationId: 0x02,
  requestId: 1,
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: 0x47, name: 'attributes-charset', values: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', values: ['en-us'] },
      { tag: 0x45, name: 'printer-uri', values: ['ipp://watson.local.:3000/'] },
      { tag: 0x42, name: 'job-name', values: ['foobar'] },
      { tag: 0x22, name: 'ipp-attribute-fidelity', values: [true] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'copies', values: [20] },
      { tag: 0x44, name: 'sides', values: ['two-sided-long-edge'] }
    ] }
  ],
  data: <Buffer 25 21 50 53 ...>
}

ipp.request.encode(obj[, buffer][, offset])

Encode an IPP request object and returns en encoded buffer.

Options:

  • obj - The object containing the request
  • buffer - An optional buffer in which to write the encoded request
  • offset - An optional offset from where to start writing the encoded data in the buffer (defaults to 0)

Response object structure:

{
  statusCode: 0x00,
  requestId: 1,
  groups: [
    { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
      { tag: 0x47, name: 'attributes-charset', values: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', values: ['en-us'] },
      { tag: 0x41, name: 'status-message', values: ['successful-ok'] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'job-id', values: [147] },
      { tag: 0x45, name: 'job-uri', values: ['ipp://watosn.local.:3000/123'] }
      { tag: 0x44, name: 'job-state', values: ['pending'] }
    ] }
  ]
}

It's possible to provide a custom IPP version in the same format is seen in the request. Default IPP version is 1.1.

ipp.request.encodingLength(obj)

Returns the number of bytes it would take to encode the given IPP request object.

ipp.response.decode(buffer[, offset][, length])

Same as ipp.request.decode(), but for IPP responses.

ipp.response.encode(obj[, buffer][, offset])

Same as ipp.request.encode(), but for IPP responses.

ipp.response.encodingLength(obj)

Same as ipp.request.encodingLength(), but for IPP responses.

License

MIT