Permalink
Browse files

Docs: Updated converter documentation

  • Loading branch information...
dcodeIO committed Jan 12, 2017
1 parent 44167db commit 079388ca65dfd581d74188a6ae49cfa01b103809
Showing with 52 additions and 18 deletions.
  1. +15 −15 cli/targets/static.js
  2. +21 −0 index.d.ts
  3. +0 −1 src/common.js
  4. +14 −0 src/converter.js
  5. +2 −2 tests/data/test.js
@@ -145,21 +145,21 @@ function buildNamespace(ref, ns) {
function beautify(code) {
return UglifyJS.minify(code
.replace(/\br\b/g, "reader")
.replace(/\bw\b/g, "writer")
.replace(/\bm\b/g, "message")
.replace(/\bt\b/g, "tag")
.replace(/\bl\b/g, "len")
.replace(/\bc\b/g, "end")
.replace(/\bc2\b/g, "end2")
.replace(/\bk\b/g, "key")
.replace(/\bks\b/g, "keys")
.replace(/\bks2\b/g, "keys2")
.replace(/\be\b/g, "err")
.replace(/\bf\b/g, "impl")
.replace(/\bo\b/g, "options")
.replace(/\bd\b/g, "object")
.replace(/\bn\b/g, "long"),
.replace(/\b(?!\\)r\b/g, "reader")
.replace(/\b(?!\\)w\b/g, "writer")
.replace(/\b(?!\\)m\b/g, "message")
.replace(/\b(?!\\)t\b/g, "tag")
.replace(/\b(?!\\)l\b/g, "len")
.replace(/\b(?!\\)c\b/g, "end")
.replace(/\b(?!\\)c2\b/g, "end2")
.replace(/\b(?!\\)k\b/g, "key")
.replace(/\b(?!\\)ks\b/g, "keys")
.replace(/\b(?!\\)ks2\b/g, "keys2")
.replace(/\b(?!\\)e\b/g, "err")
.replace(/\b(?!\\)f\b/g, "impl")
.replace(/\b(?!\\)o\b/g, "options")
.replace(/\b(?!\\)d\b/g, "object")
.replace(/\b(?!\\)n\b/g, "long"),
{
fromString: true,
compress: false,
@@ -117,6 +117,27 @@ export class Class {
*/
export function common(name: string, json: { [k: string]: any }): void;
/**
* Runtime message from/to plain object converters.
* @namespace
*/
export namespace converter {
/**
* Generates a plain object to runtime message converter specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
function fromObject(mtype: Type): Codegen;
/**
* Generates a runtime message to plain object converter specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
function toObject(mtype: Type): Codegen;
}
/**
* Generates a decoder specific to the specified message type.
* @param {Type} mtype Message type
@@ -1,5 +1,4 @@
"use strict";
module.exports = common;
/**
@@ -1,4 +1,8 @@
"use strict";
/**
* Runtime message from/to plain object converters.
* @namespace
*/
var converter = exports;
var Enum = require("./enum"),
@@ -76,6 +80,11 @@ function genConvertValue_fromObject(gen, field, fieldIndex, prop) {
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
}
/**
* Generates a plain object to runtime message converter specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
converter.fromObject = function fromObject(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.fieldsArray;
@@ -152,6 +161,11 @@ function genConvertValue_toObject(gen, field, fieldIndex, prop) {
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
}
/**
* Generates a runtime message to plain object converter specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
converter.toObject = function toObject(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.fieldsArray;
@@ -6353,7 +6353,7 @@ $root.jspb = (function() {
}
var key = Object.keys(message.mapInt32String);
for (var i = 0; i < key.length; ++i) {
if (!/^-?(?:0|[1-9]\object*)$/.test(key[i])) {
if (!/^-?(?:0|[1-9][0-9]*)$/.test(key[i])) {
return "jspb.test.TestMapFieldsNoBinary.mapInt32String: integer key{key:int32} expected";
}
if (!util.isString(message.mapInt32String[key[i]])) {
@@ -6367,7 +6367,7 @@ $root.jspb = (function() {
}
var key = Object.keys(message.mapInt64String);
for (var i = 0; i < key.length; ++i) {
if (!/^(?:[\x00-\xff]{8}|-?(?:0|[1-9]\object*))$/.test(key[i])) {
if (!/^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/.test(key[i])) {
return "jspb.test.TestMapFieldsNoBinary.mapInt64String: integer|Long key{key:int64} expected";
}
if (!util.isString(message.mapInt64String[key[i]])) {

0 comments on commit 079388c

Please sign in to comment.