Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including ipp-encoder with all npm packages installed. Try it out:

var ippEncoder = require("ipp-encoder")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ipp-encoder v5.0.0

Internet Printing Protocol (IPP) encoder and decoder

ipp-encoder

Internet Printing Protocol (IPP) encoder and decoder.

This module can be used to implement either a printing client or a printer server.

Build status js-standard-style abstract-encoding

Installation

npm install ipp-encoder

Usage

Printer server example:

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

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

// ...handle request...

// prepare response
var response = {
  statusCode: C.SUCCESSFUL_OK, // set `operationId` instead if encoding a request
  requestId: decoded.requestId,
  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: { lang: 'en-us', 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' } }
    ] }
  ]
}

// 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[, start][, end])

Decode an IPP request buffer and returns the request object.

Options:

  • buffer - The buffer containing the request
  • start - An optional start-offset from where to start parsing the request (defaults to 0)
  • end - An optional end-offset specifying at which byte to end the decoding (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', value: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', value: ['en-us'] },
      { tag: 0x45, name: 'printer-uri', value: ['ipp://watson.local.:3000/'] },
      { tag: 0x42, name: 'job-name', value: ['foobar'] },
      { tag: 0x22, name: 'ipp-attribute-fidelity', value: [true] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'copies', value: [20] },
      { tag: 0x44, name: 'sides', value: ['two-sided-long-edge'] }
    ] }
  ]
}

After decoding ipp.request.decode.bytes is set to the amount of bytes used to decode the object.

Note that any data after the IPP headers are ignored.

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', value: ['utf-8'] },
      { tag: 0x48, name: 'attributes-natural-language', value: ['en-us'] },
      { tag: 0x41, name: 'status-message', value: ['successful-ok'] }
    ] },
    { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
      { tag: 0x21, name: 'job-id', value: [147] },
      { tag: 0x45, name: 'job-uri', value: ['ipp://watosn.local.:3000/123'] }
      { tag: 0x44, name: 'job-state', value: ['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.

After encoding, ipp.request.encode.bytes is set to the amount of bytes used to encode the object.

ipp.request.encodingLength(obj)

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

ipp.response.decode(buffer[, start][, end])

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

After decoding ipp.response.decode.bytes is set to the amount of bytes used to decode the object.

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

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

After encoding, ipp.response.encode.bytes is set to the amount of bytes used to encode the object.

ipp.response.encodingLength(obj)

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

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free