npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

eup-ipp-encoder

v0.1.1

Published

Internet Printing Protocol (IPP) encoder and decoder

Readme

eup-ipp-encoder

一个轻量级、专注的互联网打印协议(IPP)编码器和解码器库。

本库致力于提供纯净的IPP消息序列化和反序列化功能,专注于做好编码和解码的核心工作,不包含任何无关的辅助功能。

本项目基于 watson/ipp-encoder 改造优化而来

TypeScript

安装

npm install eup-ipp-encoder

使用示例

以下是一个简单的打印机服务器场景示例:

import * as ipp from 'eup-ipp-encoder'

// 解码来自IPP客户端的二进制请求
const decoded = ipp.decoder.decodeRequest(buf)

// ...在这里处理客户端请求...

// 准备响应数据
const response: ipp.IPPResponse = {
  statusCode: 0x00, // 如果是编码请求,则使用 `operationId` 替代
  requestId: decoded.requestId,
  groups: [
    { 
      tag: 0x01, // OPERATION_ATTRIBUTES_TAG
      attributes: [
        { tag: 0x21, name: 'job-id', value: [147] },
        { tag: 0x36, name: 'job-name', value: [{ lang: 'en-us', value: 'Foobar' }] }
      ] 
    }
  ]
}

// 将响应编码为二进制缓冲区
ipp.encoder.encode(response) // 返回 <Buffer 01 01 00 00 ... >

API 文档

ipp.decoder.decodeRequest(buffer[, start][, end])

将IPP请求的二进制缓冲区解码为结构化的JavaScript对象。

参数说明:

  • buffer - 包含IPP请求数据的二进制缓冲区
  • start - 可选参数,指定解码的起始偏移位置(默认值:0
  • end - 可选参数,指定解码的结束偏移位置(默认值:buffer.length

返回的请求对象结构:

{
  version: {
    major: 1,        // IPP协议主版本号
    minor: 1         // IPP协议次版本号
  },
  operationId: 0x02,  // IPP操作标识符
  requestId: 1,       // 请求ID
  groups: [           // 属性组数组
    { 
      tag: 0x01,      // OPERATION_ATTRIBUTES_TAG
      attributes: [   // 属性列表
        { tag: 0x21, name: 'job-id', value: [147] },
        { tag: 0x36, name: 'job-name', value: [{ lang: 'en-us', value: 'Foobar' }] },
        { tag: 0x22, name: 'ipp-attribute-fidelity', value: [true] }
      ] 
    }
  ]
}

ipp.decoder.decodeResponse(buffer[, start][, end])

decodeRequest() 方法用法完全相同,但专门用于解码IPP响应消息。

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

将结构化的IPP请求或响应对象编码为二进制缓冲区。

参数说明:

  • obj - 要编码的IPP请求或响应对象
  • buffer - 可选参数,用于存储编码后数据的目标缓冲区
  • offset - 可选参数,指定在目标缓冲区中的写入起始位置(默认值:0

响应对象示例结构:

{
  statusCode: 0x00,   // 响应状态码(请求使用operationId)
  requestId: 1,       // 请求ID(与对应的请求保持一致)
  groups: [           // 属性组数组
    { 
      tag: 0x01,      // OPERATION_ATTRIBUTES_TAG
      attributes: [   // 属性列表
        { tag: 0x21, name: 'job-id', value: [147] },
        { tag: 0x22, name: 'ipp-attribute-fidelity', value: [true] },
        { tag: 0x36, name: 'job-name', value: [{ lang: 'en-us', value: 'Foobar' }] }
      ] 
    }
  ]
}

提示:可以在请求或响应对象中指定自定义IPP版本(格式与上述示例中的version字段相同),默认使用IPP 1.1版本。

ipp.encoder.encodingLength(obj)

计算编码指定IPP请求或响应对象所需的字节数,用于预先分配合适大小的缓冲区。

支持的IPP标签

本库支持以下IPP标签的编码和解码功能:

分隔符标签

分隔符标签用于组织属性组:

  • OPERATION_ATTRIBUTES_TAG (0x01) - 操作属性组标签
  • JOB_ATTRIBUTES_TAG (0x02) - 作业属性组标签
  • END_OF_ATTRIBUTES_TAG (0x03) - 属性组结束标签

值类型标签

值类型标签用于标识属性值的数据类型:

  • INTEGER (0x21) - 整数类型
  • BOOLEAN (0x22) - 布尔类型
  • ENUM (0x23) - 枚举类型
  • DATE_TIME (0x31) - 日期时间类型
  • TEXT_WITH_LANG (0x35) - 带语言信息的文本
  • NAME_WITH_LANG (0x36) - 带语言信息的名称
  • KEYWORD (0x44) - 关键字类型

许可证

MIT