Skip to content

Commit 079388c

Browse files
committed
Docs: Updated converter documentation
1 parent 44167db commit 079388c

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

cli/targets/static.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,21 @@ function buildNamespace(ref, ns) {
145145

146146
function beautify(code) {
147147
return UglifyJS.minify(code
148-
.replace(/\br\b/g, "reader")
149-
.replace(/\bw\b/g, "writer")
150-
.replace(/\bm\b/g, "message")
151-
.replace(/\bt\b/g, "tag")
152-
.replace(/\bl\b/g, "len")
153-
.replace(/\bc\b/g, "end")
154-
.replace(/\bc2\b/g, "end2")
155-
.replace(/\bk\b/g, "key")
156-
.replace(/\bks\b/g, "keys")
157-
.replace(/\bks2\b/g, "keys2")
158-
.replace(/\be\b/g, "err")
159-
.replace(/\bf\b/g, "impl")
160-
.replace(/\bo\b/g, "options")
161-
.replace(/\bd\b/g, "object")
162-
.replace(/\bn\b/g, "long"),
148+
.replace(/\b(?!\\)r\b/g, "reader")
149+
.replace(/\b(?!\\)w\b/g, "writer")
150+
.replace(/\b(?!\\)m\b/g, "message")
151+
.replace(/\b(?!\\)t\b/g, "tag")
152+
.replace(/\b(?!\\)l\b/g, "len")
153+
.replace(/\b(?!\\)c\b/g, "end")
154+
.replace(/\b(?!\\)c2\b/g, "end2")
155+
.replace(/\b(?!\\)k\b/g, "key")
156+
.replace(/\b(?!\\)ks\b/g, "keys")
157+
.replace(/\b(?!\\)ks2\b/g, "keys2")
158+
.replace(/\b(?!\\)e\b/g, "err")
159+
.replace(/\b(?!\\)f\b/g, "impl")
160+
.replace(/\b(?!\\)o\b/g, "options")
161+
.replace(/\b(?!\\)d\b/g, "object")
162+
.replace(/\b(?!\\)n\b/g, "long"),
163163
{
164164
fromString: true,
165165
compress: false,

index.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ export class Class {
117117
*/
118118
export function common(name: string, json: { [k: string]: any }): void;
119119

120+
/**
121+
* Runtime message from/to plain object converters.
122+
* @namespace
123+
*/
124+
export namespace converter {
125+
126+
/**
127+
* Generates a plain object to runtime message converter specific to the specified message type.
128+
* @param {Type} mtype Message type
129+
* @returns {Codegen} Codegen instance
130+
*/
131+
function fromObject(mtype: Type): Codegen;
132+
133+
/**
134+
* Generates a runtime message to plain object converter specific to the specified message type.
135+
* @param {Type} mtype Message type
136+
* @returns {Codegen} Codegen instance
137+
*/
138+
function toObject(mtype: Type): Codegen;
139+
}
140+
120141
/**
121142
* Generates a decoder specific to the specified message type.
122143
* @param {Type} mtype Message type

src/common.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use strict";
2-
32
module.exports = common;
43

54
/**

src/converter.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"use strict";
2+
/**
3+
* Runtime message from/to plain object converters.
4+
* @namespace
5+
*/
26
var converter = exports;
37

48
var Enum = require("./enum"),
@@ -76,6 +80,11 @@ function genConvertValue_fromObject(gen, field, fieldIndex, prop) {
7680
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
7781
}
7882

83+
/**
84+
* Generates a plain object to runtime message converter specific to the specified message type.
85+
* @param {Type} mtype Message type
86+
* @returns {Codegen} Codegen instance
87+
*/
7988
converter.fromObject = function fromObject(mtype) {
8089
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
8190
var fields = mtype.fieldsArray;
@@ -152,6 +161,11 @@ function genConvertValue_toObject(gen, field, fieldIndex, prop) {
152161
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
153162
}
154163

164+
/**
165+
* Generates a runtime message to plain object converter specific to the specified message type.
166+
* @param {Type} mtype Message type
167+
* @returns {Codegen} Codegen instance
168+
*/
155169
converter.toObject = function toObject(mtype) {
156170
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
157171
var fields = mtype.fieldsArray;

tests/data/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6353,7 +6353,7 @@ $root.jspb = (function() {
63536353
}
63546354
var key = Object.keys(message.mapInt32String);
63556355
for (var i = 0; i < key.length; ++i) {
6356-
if (!/^-?(?:0|[1-9]\object*)$/.test(key[i])) {
6356+
if (!/^-?(?:0|[1-9][0-9]*)$/.test(key[i])) {
63576357
return "jspb.test.TestMapFieldsNoBinary.mapInt32String: integer key{key:int32} expected";
63586358
}
63596359
if (!util.isString(message.mapInt32String[key[i]])) {
@@ -6367,7 +6367,7 @@ $root.jspb = (function() {
63676367
}
63686368
var key = Object.keys(message.mapInt64String);
63696369
for (var i = 0; i < key.length; ++i) {
6370-
if (!/^(?:[\x00-\xff]{8}|-?(?:0|[1-9]\object*))$/.test(key[i])) {
6370+
if (!/^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/.test(key[i])) {
63716371
return "jspb.test.TestMapFieldsNoBinary.mapInt64String: integer|Long key{key:int64} expected";
63726372
}
63736373
if (!util.isString(message.mapInt64String[key[i]])) {

0 commit comments

Comments
 (0)