{"_id":"@1-/proto","name":"@1-/proto","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@1-/proto","version":"0.1.1","description":"Tree-shakable protobuf encoder and decoder","keywords":["decode","encode","grpc","protobuf","tree-shaking"],"homepage":"https://github.com/webc-site/npm/tree/main/proto","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"type":"module","exports":{"./*":"./*"},"dependencies":{"@3-/utf8":"^0.1.1"},"_id":"@1-/proto@0.1.1","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-mUBF7eyohUbQSqtmyhtz75+Ohs27BGGRNwvkGp+XlKifl5ayvap/GmMAUkyeSJpjJ+3uoFm+SVZlXjW8vl3qXQ==","shasum":"f83bffd3303f9f2c1748d849d73bf352cf6b0f23","tarball":"https://registry.npmjs.org/@1-/proto/-/proto-0.1.1.tgz","fileCount":7,"unpackedSize":24568,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBgNsItTJFz65xDdaZljj0Yw3PCB/VNIUAN12CvTn+30AiByQtwBHyohLblFdA2R1E0GNx5kJkteJJMHkkDE0mvLMQ=="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/proto_0.1.1_1786703635028_0.850615102324831"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-14T10:33:54.839Z","0.1.1":"2026-08-14T10:33:55.244Z","modified":"2026-08-14T10:33:55.434Z"},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"description":"Tree-shakable protobuf encoder and decoder","homepage":"https://github.com/webc-site/npm/tree/main/proto","keywords":["decode","encode","grpc","protobuf","tree-shaking"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"author":{"name":"x-at-01@googlegroups.com"},"bugs":{"url":"https://github.com/webc-site/npm/issues"},"license":"MulanPSL-2.0","readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# ProtoRPC : Efficient Binary RPC for JavaScript\n\n- [ProtoRPC : Efficient Binary RPC for JavaScript](#protorpc-efficient-binary-rpc-for-javascript)\n  - [Functionality](#functionality)\n  - [Usage Example](#usage-example)\n  - [Design Principles](#design-principles)\n  - [Technology Stack](#technology-stack)\n  - [Code Structure](#code-structure)\n  - [Historical Context](#historical-context)\n  - [About](#about)\n\n## Functionality\nProtoRPC provides a lightweight, zero-dependency RPC framework that implements Protocol Buffer wire format specifications for efficient binary communication. It enables high-performance remote procedure calls with automatic request batching, throttling, and streaming response handling. The library minimizes network payload size through compact binary encoding while maintaining full JavaScript compatibility.\n\n## Usage Example\nConfigure and use the RPC client with Protocol Buffer-style encoding:\n\n```javascript\nimport rpc from \"./src/rpc.js\";\nimport { uint32, string, $ } from \"./src/E.js\";\nimport { dUint32, string as dString, $ as d$ } from \"./src/D.js\";\n\n// Set base URL for RPC endpoint\nrpc.setBase(\"https://api.example.com/rpc\");\n\n// Define RPC method with Protocol Buffer-style encoding\n// Field 1: user ID (varint), Field 2: username (length-delimited string)\nconst getUser = rpc(1, // function ID\n  $([uint32, lengthDelimited(string)]), // encoder\n  d$([dUint32, dString]) // decoder\n);\n\n// Call the RPC method\nconst result = await getUser([123, \"Alice\"]);\n```\n\n## Design Principles\nThe architecture implements Protocol Buffer wire format with precise specification compliance:\n\n![](https://cdn.jsdmirror.com/gh/webc-fs/-@7D/u-YlWiZ2ue4aj7ZKZcjA.svg)\n\nKey implementation details:\n- Streaming response parsing using ReadableStream API with zero-copy operations\n- Precise Protocol Buffer wire format compliance: varint encoding, tag calculation (field<<3|wire_type), length-delimited strings\n- Automatic request batching with configurable throttle timeout (9ms default)\n- Call ID management with 32-bit unsigned integer rollover (U32_MAX = 4294967295)\n- Memory-efficient encoding with concat() utility for Uint8Array operations\n- StructuredClone() for deep copying default values in decoders\n- Zigzag encoding for signed integers (sint32/sint64)\n- Special error code handling using U32_MAX as sentinel value\n\n## Technology Stack\n- Core runtime: Modern JavaScript (ES2020+) with BigInt support\n- Binary encoding: Custom Protocol Buffer wire format implementation\n- HTTP transport: Native fetch API with ReadableStream response handling\n- Dependencies: utf8e/utf8d for UTF-8 encoding/decoding\n- Build system: Standard JavaScript modules\n\n## Code Structure\n```\nsrc/\n├── rpc.js          # Main RPC client with batching, throttling, and streaming response handling\n│   ├── PENDING queue for request batching\n│   ├── CALLBACK Map for promise resolution\n│   ├── run() throttle function (9ms timeout)\n│   ├── Streaming response parsing with readN() helper\n│   └── U32_MAX error code handling\n├── E.js            # Encoding library with Protocol Buffer wire format implementation\n│   ├── uint32/uint64/varint encoding with bit manipulation\n│   ├── fixed-size number encoding (double, float, fixed32/64)\n│   ├── string/bytes encoding with UTF-8 support\n│   ├── packed repeated fields support\n│   ├── zigzag encoding for signed integers\n│   └── map encoding with proper tag handling\n├── D.js            # Decoding library with field position mapping and wire type handling\n│   ├── varint decoding with bit manipulation\n│   ├── tag parsing for field identification\n│   ├── wire type handling for different encoding formats\n│   ├── structured unpacking with field position mapping\n│   └── structuredClone() for default value initialization\n├── f.js            # HTTP fetch wrapper with multiple response type handlers\n│   ├── fT: text response handler\n│   ├── fJ: JSON response handler\n│   ├── fB: ArrayBuffer response handler\n│   └── fS: streaming response handler (used by rpc.js)\n└── throttle.js     # Simple throttle utility for request batching (9ms timeout)\n```\n\n## Historical Context\nProtocol Buffers were developed by Google in 2001 to address the challenge of efficient data serialization across distributed systems. The original design focused on compact binary representation, language neutrality, and extensibility. ProtoRPC implements these core principles in JavaScript without external dependencies, bringing Protocol Buffer efficiency to web applications. Unlike traditional Protocol Buffer implementations that require code generation, ProtoRPC uses runtime encoding/decoding functions, making it ideal for dynamic JavaScript environments where compile-time code generation is impractical. The library's streaming response handling and memory-efficient Uint8Array operations represent modern JavaScript best practices for high-performance network communication.\n\n## About\n\nThis library is developed by [WebC.site](https://webc.site).\n\n[WebC.site](https://webc.site): A new paradigm of web development for AI\n\n\n---\n\n<a id=\"zh\"></a>\n# ProtoRPC : 面向 JavaScript 的高效二进制 RPC\n\n- [ProtoRPC : 面向 JavaScript 的高效二进制 RPC](#protorpc-面向-javascript-的高效二进制-rpc)\n  - [功能介绍](#功能介绍)\n  - [使用演示](#使用演示)\n  - [设计思路](#设计思路)\n  - [技术栈](#技术栈)\n  - [代码结构](#代码结构)\n  - [历史故事](#历史故事)\n  - [关于](#关于)\n\n## 功能介绍\nProtoRPC 提供轻量级、零依赖的 RPC 框架，实现 Protocol Buffer 线格式规范，支持高效的二进制通信。该框架支持高性能远程过程调用，具备自动请求批处理、节流控制和流式响应处理能力。通过紧凑的二进制编码，最小化网络负载大小，同时保持完整的 JavaScript 兼容性。\n\n## 使用演示\n配置并使用遵循 Protocol Buffer 规范的 RPC 客户端：\n\n```javascript\nimport rpc from \"./src/rpc.js\";\nimport { uint32, string, $ } from \"./src/E.js\";\nimport { dUint32, string as dString, $ as d$ } from \"./src/D.js\";\n\n// 设置 RPC 端点基础 URL\nrpc.setBase(\"https://api.example.com/rpc\");\n\n// 定义 RPC 方法（遵循 Protocol Buffer 编码规范）\n// 字段 1：用户 ID（varint 编码），字段 2：用户名（长度限定字符串）\nconst getUser = rpc(1, // 函数 ID\n  $([uint32, lengthDelimited(string)]), // 编码器\n  d$([dUint32, dString]) // 解码器\n);\n\n// 调用 RPC 方法\nconst result = await getUser([123, \"Alice\"]);\n```\n\n## 设计思路\n架构严格遵循 Protocol Buffer 线格式规范，实现精确的协议兼容：\n\n![](https://cdn.jsdmirror.com/gh/webc-fs/-@Lt/2rCdiyrRNnfjIEZ7BHlw.svg)\n\n关键实现细节：\n- 流式响应解析，使用 ReadableStream API 实现零拷贝操作\n- 严格遵循 Protocol Buffer 线格式规范：varint 编码、标签计算（字段<<3|线类型）、长度限定字符串\n- 自动请求批处理，支持可配置的节流超时（默认 9 毫秒）\n- 调用 ID 管理，支持 32 位无符号整数自动回绕（U32_MAX = 4294967295）\n- 内存高效编码，使用 concat() 工具函数处理 Uint8Array 操作\n- structuredClone() 用于解码器中默认值的深度复制\n- Zigzag 编码用于有符号整数（sint32/sint64）\n- 特殊错误码处理，使用 U32_MAX 作为哨兵值\n\n## 技术栈\n- 核心运行时：现代 JavaScript（ES2020+），支持 BigInt\n- 二进制编码：自定义 Protocol Buffer 线格式实现\n- HTTP 传输：原生 fetch API，支持 ReadableStream 响应处理\n- 依赖项：utf8e/utf8d 用于 UTF-8 编码/解码\n- 构建系统：标准 JavaScript 模块\n\n## 代码结构\n```\nsrc/\n├── rpc.js          # 主 RPC 客户端（含批处理、节流控制和流式响应处理）\n│   ├── PENDING 队列用于请求批处理\n│   ├── CALLBACK Map 用于 Promise 解析\n│   ├── run() 节流函数（9 毫秒超时）\n│   ├── 流式响应解析，使用 readN() 辅助函数\n│   └── U32_MAX 错误码处理\n├── E.js            # 编码库（Protocol Buffer 线格式实现）\n│   ├── uint32/uint64/varint 编码（位操作）\n│   ├── 定长数字编码（double、float、fixed32/64）\n│   ├── 字符串/字节编码（UTF-8 支持）\n│   ├── 打包重复字段支持\n│   ├── 有符号整数的 zigzag 编码\n│   └── 映射编码（带正确标签处理）\n├── D.js            # 解码库（字段位置映射和线类型处理）\n│   ├── varint 解码（位操作）\n│   ├── 标签解析（字段识别）\n│   ├── 线类型处理（不同编码格式）\n│   ├── 结构化解包（字段位置映射）\n│   └── structuredClone() 用于默认值初始化\n├── f.js            # HTTP fetch 封装（多种响应类型处理器）\n│   ├── fT：文本响应处理器\n│   ├── fJ：JSON 响应处理器\n│   ├── fB：ArrayBuffer 响应处理器\n│   └── fS：流式响应处理器（rpc.js 使用）\n└── throttle.js     # 简单节流工具（请求批处理，9 毫秒超时）\n```\n\n## 历史故事\nProtocol Buffers 由 Google 于 2001 年开发，旨在解决分布式系统中结构化数据高效序列化的难题。原始设计聚焦于紧凑的二进制表示、语言无关性和可扩展性。ProtoRPC 在 JavaScript 中实现了这些核心原则，无需外部依赖，将 Protocol Buffer 效率优势带入 Web 应用。与需要代码生成的传统 Protocol Buffer 实现不同，ProtoRPC 使用运行时编码/解码函数，在动态 JavaScript 环境中无需编译时代码生成，更适合实际 Web 开发场景。该库的流式响应处理和内存高效的 Uint8Array 操作代表了现代 JavaScript 高性能网络通信的最佳实践。\n\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n\n","readmeFilename":"README.md","_rev":"1-240fd90840a74883b44fbea3eb4e1372"}