Skip to content

Commit

Permalink
Docs: Updated converter documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 12, 2017
1 parent 44167db commit 079388c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
30 changes: 15 additions & 15 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use strict";

module.exports = common;

/**
Expand Down
14 changes: 14 additions & 0 deletions src/converter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"use strict";
/**
* Runtime message from/to plain object converters.
* @namespace
*/
var converter = exports;

var Enum = require("./enum"),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]])) {
Expand All @@ -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]])) {
Expand Down

0 comments on commit 079388c

Please sign in to comment.