<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/protobufjs@7.X.X/dist/protobuf.js"></script>
```
Production:
```
<script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/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个
5星 · 超过95%的资源 需积分: 40 11 下载量 49 浏览量
2022-10-10
11:26:59
上传
评论 1
收藏 6.44MB RAR 举报
温馨提示
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
资源详情
资源评论
资源推荐
收起资源包目录
Cocos Creator 3.x 中使用 Socket.io (1700个子文件)
1f505ca8-b164-4d35-b697-504d100015e4 511B
22a135d0-b2ef-4c1b-86d2-5bbbd88e4875 853B
2c657d26-de3b-4070-9cad-2ca3a33bbd72 108B
3b7550e2-beea-4079-ad8d-dfef104086bd 5KB
3e7d59d5-5478-474a-bb27-6eddb22dc614 901B
400f1cd3-9a46-4349-b3c1-f451e22a219b 342B
4584ab47-6c1b-44fc-a41d-e32ba87e9660 373B
865b04b2-bc79-40fc-9bdf-a7557665b27c 124B
8c76e1e2-a206-4662-aa79-42c0c858d647 293B
8f8bba83-df9c-4afe-8450-e12d0dbe71b7 225B
91d50ce0-702d-47fd-b540-447a0de3471d 521B
aa709c4b-426b-46f3-a856-4a0f22f52d6d 455B
ad05fddb-302f-40f5-81d2-27f671ddf0b6 109B
buffer.bin 210KB
1263d74c-8167-4928-91a6-4e2672411f47@801ec.bin 84KB
1263d74c-8167-4928-91a6-4e2672411f47@40ece.bin 83KB
1263d74c-8167-4928-91a6-4e2672411f47@17020.bin 80KB
1263d74c-8167-4928-91a6-4e2672411f47@8abdc.bin 15KB
1263d74c-8167-4928-91a6-4e2672411f47@2e76e.bin 8KB
1263d74c-8167-4928-91a6-4e2672411f47@38fd2.bin 8KB
1263d74c-8167-4928-91a6-4e2672411f47@a804a.bin 1KB
1263d74c-8167-4928-91a6-4e2672411f47@fc873.bin 236B
c3dd770e-f74d-491f-85f7-4607add32858 2KB
c7e748e8-be82-4f6f-b2c0-085b604e40e5 123B
mime.cmd 316B
style.css 2KB
d9956a56-5622-44a1-8b50-42449f24ecdd 1KB
e220b271-6a70-47c0-8d12-850150694608 40B
e7e9f9b7-58f3-44b4-b31c-7e7b0f601e92 110B
.editorconfig 569B
.editorconfig 286B
.eslintignore 10B
.eslintignore 10B
.eslintrc 1KB
.eslintrc 1KB
.eslintrc 585B
.eslintrc 247B
.eslintrc 231B
.eslintrc 180B
.eslintrc 176B
.eslintrc 172B
.eslintrc 164B
out.gltf 22KB
index.html 2KB
52ef29ed-bd92-4e94-ab2f-0ebc91bf3a60.jpg 372KB
80aabd92-9942-4765-b685-8577a1c88b4e.jpg 9KB
86eb75aa-3b2f-4c7b-b59e-bdc2e3984665.jpg 9KB
61ac0181-00bd-4c17-97f0-5fc7f4bafb3d.jpg 9KB
6c895e98-967e-4a6d-8c08-bf6b035fa2c1.jpg 9KB
e049bea9-db6b-463b-8502-61bf426357a1.jpg 9KB
03721795-84b1-4dcd-8eb3-c8e6b88ee535.jpg 8KB
cc.js 1.85MB
ammo-f0bdd709.js 1.16MB
ammo-instantiated-3f62aafc.js 1.01MB
socket.io.js 283KB
socket.io.js 283KB
protobuf.js 272KB
protobuf.js 225KB
ammo.wasm-baa9669a.js 189KB
socket.io.js 174KB
socket.io.js 148KB
socket.io.js 148KB
engine.io.js 118KB
socket.io.js 112KB
bundle.js 86KB
protobuf.js 77KB
protobuf.min.js 72KB
qs.js 68KB
protobuf.min.js 62KB
socket.io.msgpack.min.js 61KB
socket.io.min.js 60KB
socket.io.msgpack.min.js 48KB
index.js 43KB
socket.io.min.js 43KB
index.js 40KB
system.js 40KB
engine.io.min.js 36KB
parse.js 35KB
socket.io.esm.min.js 34KB
stringify.js 34KB
index.js 34KB
websocket.js 34KB
websocket.js 34KB
sbcs-data-generated.js 31KB
websocket.js 29KB
response.js 27KB
parse.js 25KB
websocket.js 25KB
XMLHttpRequest.js 23KB
XMLHttpRequest.js 23KB
index.js 23KB
socket.js 22KB
socket.js 22KB
server.js 21KB
dbcs-codec.js 21KB
protobuf.min.js 20KB
type.js 20KB
socket.js 19KB
index.js 19KB
ipaddr.js 19KB
共 1700 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
坎大哈
- 粉丝: 8485
- 资源: 76
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电子万年历软件仿真(经过多次修改,保证正确性)
- Unity XR 手势射击控制脚本(适用于任何可手势识别的设备)
- 机械设计全自动电表(NB和IC卡表)控制和上壳装配线sw16可编辑非常好的设计图纸100%好用.zip
- 基于matlab的EAN-13条形码识别系统GUI界面.zip代码53
- matlab基于bp神经网络交通信号标志识别GUI界面13个标志.zip代码54
- 电子万年历答辩实物展示视频mp4格式
- 基于python实现的程序,包括哈希感知算法cvHash,图像切割cvsplit,固定目标检测cvRec(附文档ppt)等
- 计算0-10000之间所有偶数的和
- multiled.zip
- 基于php实现的哈希算法的人脸检索
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论11