<h1><p align="center"><img alt="protobuf.js" src="https://github.com/dcodeIO/protobuf.js/raw/master/pbjs.png" width="120" height="104" /></p></h1>
<p align="center"><a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).
**protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [node.js](https://nodejs.org) and the browser. It's easy to use, blazingly fast and works out of the box with [.proto](https://developers.google.com/protocol-buffers/docs/proto) files!
Contents
--------
* [Installation](#installation)<br />
How to include protobuf.js in your project.
* [Usage](#usage)<br />
A brief introduction to using the toolset.
* [Valid Message](#valid-message)
* [Toolset](#toolset)<br />
* [Examples](#examples)<br />
A few examples to get you started.
* [Using .proto files](#using-proto-files)
* [Using JSON descriptors](#using-json-descriptors)
* [Using reflection only](#using-reflection-only)
* [Using custom classes](#using-custom-classes)
* [Using services](#using-services)
* [Usage with TypeScript](#usage-with-typescript)<br />
* [Additional documentation](#additional-documentation)<br />
A list of available documentation resources.
* [Performance](#performance)<br />
A few internals and a benchmark on performance.
* [Compatibility](#compatibility)<br />
Notes on compatibility regarding browsers and optional libraries.
* [Building](#building)<br />
How to build the library and its components yourself.
Installation
---------------
### node.js
```
$> npm install protobufjs [--save --save-prefix=~]
```
```js
var protobuf = require("protobufjs");
```
The command line utility lives in the protobufjs-cli package and must be installed separately:
```
$> npm install protobufjs-cli [--save --save-prefix=~]
```
**Note** that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on `~6.A.B` instead of `^6.A.B` (hence the `--save-prefix` above).
### Browsers
Development:
```
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/protobuf.js"></script>
```
Production:
```
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/protobuf.min.js"></script>
```
**Remember** to replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon.
The library supports CommonJS and AMD loaders and also exports globally as `protobuf`.
### Distributions
Where bundle size is a factor, there are additional stripped-down versions of the [full library][dist-full] (~19kb gzipped) available that exclude certain functionality:
* When working with JSON descriptors (i.e. generated by [pbjs](cli/README.md#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
```js
var protobuf = require("protobufjs/light");
```
* When working with statically generated code only, see the [minimal library][dist-minimal] (~6.5kb gzipped) that also excludes reflection. CommonJS entry point is:
```js
var protobuf = require("protobufjs/minimal");
```
| Distribution | Location
|------------|-----------------------------------
| Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
| Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
| Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
Usage
-----
Because JavaScript is a dynamically typed language, protobuf.js introduces the concept of a **valid message** in order to provide the best possible [performance](#performance) (and, as a side product, proper typings):
### Valid message
> A valid message is an object (1) not missing any required fields and (2) exclusively composed of JS types understood by the wire format writer.
There are two possible types of valid messages and the encoder is able to work with both of these for convenience:
* **Message instances** (explicit instances of message classes with default values on their prototype) always (have to) satisfy the requirements of a valid message by design and
* **Plain JavaScript objects** that just so happen to be composed in a way satisfying the requirements of a valid message as well.
In a nutshell, the wire format writer understands the following types:
| Field type | Expected JS type (create, encode) | Conversion (fromObject)
|------------|-----------------------------------|------------------------
| s-/u-/int32<br />s-/fixed32 | `number` (32 bit integer) | <code>value | 0</code> if signed<br />`value >>> 0` if unsigned
| s-/u-/int64<br />s-/fixed64 | `Long`-like (optimal)<br />`number` (53 bit integer) | `Long.fromValue(value)` with long.js<br />`parseInt(value, 10)` otherwise
| float<br />double | `number` | `Number(value)`
| bool | `boolean` | `Boolean(value)`
| string | `string` | `String(value)`
| bytes | `Uint8Array` (optimal)<br />`Buffer` (optimal under node)<br />`Array.<number>` (8 bit integers) | `base64.decode(value)` if a `string`<br />`Object` with non-zero `.length` is assumed to be buffer-like
| enum | `number` (32 bit integer) | Looks up the numeric id if a `string`
| message | Valid message | `Message.fromObject(value)`
* Explicit `undefined` and `null` are considered as not set if the field is optional.
* Repeated fields are `Array.<T>`.
* Map fields are `Object.<string,T>` with the key being the string representation of the respective value or an 8 characters long binary hash string for `Long`-likes.
* Types marked as *optimal* provide the best performance because no conversion step (i.e. number to low and high bits or base64 string to buffer) is required.
### Toolset
With that in mind and again for performance reasons, each message class provides a distinct set of methods with each method doing just one thing. This avoids unnecessary assertions / redundant operations where performance is a concern but also forces a user to perform verification (of plain JavaScript objects that *might* just so happen to be a valid message) explicitly where necessary - for example when dealing with user input.
**Note** that `Message` below refers to any message class.
* **Message.verify**(message: `Object`): `null|string`<br />
verifies that a **plain JavaScript object** satisfies the requirements of a valid message and thus can be encoded without issues. Instead of throwing, it returns the error message as a string, if any.
```js
var payload = "invalid (not an object)";
var err = AwesomeMessage.verify(payload);
if (err)
throw Error(err);
```
* **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
encodes a **message instance** or valid **plain JavaScript object**. This method does not implicitly verify the message and it's up to the user to make sure that the payload is a valid message.
```js
var buffer = AwesomeMessage.encode(message).finish();
```
* **Message.encodeDelimited**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
works like `Message.encode` but additionally prepends the length of the message as a vari
没有合适的资源?快使用搜索试试~ 我知道了~
Cocos Creator 3.x 中使用 Socket.io

共1700个文件
js:512个
json:357个
ts:288个


温馨提示
Cocos Creator 3.x 中使用 Socket.io Cocos Creator 3.x 中使用 Socket.io 文档地址:https://blog.csdn.net/nicepainkiller/article/details/127239678 文档地址:https://blog.csdn.net/nicepainkiller/article/details/127239678
资源详情
资源评论
资源推荐
收起资源包目录





























































































共 1700 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17























nicepainkiller
- 粉丝: 9745
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 微信小程序 蓝牙实现.zip
- A191基于springboot+vue的可追溯果蔬生产过程的管理系统(LW文档+完整前后端代码+sql脚本+开发文档+全套软件)
- 基于多智能体协调的车路协同关键技术研究仿真平台_城市规模交通信号控制仿真系统_多智能体算法优化与深度强化学习模型集成_实时交通流模拟与信号灯智能调度_用于提升城市交通效率与减少拥堵.zip
- taro + vue3 开发微信小程序的模板.zip
- 基于ghost的微信小程序版博客.zip
- 微信小程序 自定义tabbar.zip
- 微信小程序-家居电商(1).zip
- 基于强化学习的智能空战决策系统_深度强化学习_多智能体对抗_空战模拟器_OpenAIGym环境_自主决策算法_无人机与战斗机对抗_战术机动与武器使用_实时动态环境_奖励函数设计_.zip
- 基于多算法融合的信号源仿真系统_包含信号生成调制解调噪声模拟频谱分析波形重构参数优化实时处理多线程计算数据可视化性能评估误差校正动态调整模型验证实验对比.zip
- 基于ROS的智能车轨迹跟踪算法的仿真与设计项目_2021年江苏理工学院王博的毕业设计_通过ROS系统实现智能车轨迹跟踪算法的仿真与设计_包括PID法轨迹跟踪_纯跟踪结合PID的轨迹.zip
- 多进程并发环境模拟与低级调度算法仿真实现_操作系统实验项目_通过程序仿真掌握并发环境原理进程PCB与控制操作原语进程切换以及进程调度算法的实现步骤_设计并实现时钟中断产生模块文件操.zip
- 微信小程序开发资源汇总.zip
- VIENNA电路控制算法Psim仿真项目_虚拟零序解耦滞环控制数字控制抛物线法电力电子变换器仿真模型_用于研究和优化Vienna整流器的控制策略性能比较与验证_基于Psim平台的电.zip
- 多肉物语的微信小程序.zip
- 微信小程序-云课堂.zip
- 基于HivisionIDPhotos + Uniapp 实现的微信小程序端.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论11