@@ -154,11 +154,12 @@ function beautify(code) {
154154 . replace ( / \b c 2 \b / g, "end2" )
155155 . replace ( / \b k \b / g, "key" )
156156 . replace ( / \b k s \b / g, "keys" )
157+ . replace ( / \b k s 2 \b / g, "keys2" )
157158 . replace ( / \b e \b / g, "err" )
158159 . replace ( / \b f \b / g, "impl" )
159160 . replace ( / \b o \b / g, "options" )
160- . replace ( / \b s \b / g, "src " )
161- . replace ( / \b d \b / g, "dst " ) ,
161+ . replace ( / \b d \b / g, "object " )
162+ . replace ( / \b n \b / g, "long " ) ,
162163 {
163164 fromString : true ,
164165 compress : false ,
@@ -443,40 +444,63 @@ function buildType(ref, type) {
443444 if ( config . convert ) {
444445 push ( "" ) ;
445446 pushComment ( [
446- "Converts " + aOrAn ( type . name ) + " message." ,
447- "@function" ,
448- "@param {" + fullName + "|Object} source " + type . name + " message or plain object to convert" ,
449- "@param {*} impl Converter implementation to use" ,
450- "@param {Object.<string,*>} [options] Conversion options" ,
451- "@returns {" + fullName + "|Object} Converted message"
447+ "Creates " + aOrAn ( type . name ) + " message from a plain object. Also converts values to their respective internal types." ,
448+ "@param {Object.<string,*>} object Plain object" ,
449+ "@returns {" + fullName + "} " + type . name
452450 ] ) ;
453- buildFunction ( type , "convert " , protobuf . converter ( type ) , {
451+ buildFunction ( type , "fromObject " , protobuf . converter . fromObject ( type ) , {
454452 util : "$protobuf.util" ,
455453 types : hasTypes ? "$types" : undefined
456454 } ) ;
457455
458456 push ( "" ) ;
459457 pushComment ( [
460- "Creates " + aOrAn ( type . name ) + " message from JSON." ,
461- "@param {Object.<string,*>} source Source object" ,
462- "@param {Object.<string,*>} [options] Conversion options" ,
458+ "Creates " + aOrAn ( type . name ) + " message from a plain object. Also converts values to their respective internal types." ,
459+ "This is an alias of {@link " + fullName + ".fromObject}." ,
460+ "@function" ,
461+ "@param {Object.<string,*>} object Plain object" ,
463462 "@returns {" + fullName + "} " + type . name
464463 ] ) ;
465- push ( name ( type . name ) + ".from = function from(source, options) {" ) ;
464+ push ( name ( type . name ) + ".from = " + name ( type . name ) + ".fromObject;" ) ;
465+
466+ push ( "" ) ;
467+ pushComment ( [
468+ "Creates a plain object from " + aOrAn ( type . name ) + " message. Also converts values to other types if specified." ,
469+ "@param {" + fullName + "} message " + type . name ,
470+ "@param {$protobuf.ConversionOptions} [options] Conversion options" ,
471+ "@returns {Object.<string,*>} Plain object"
472+ ] ) ;
473+ buildFunction ( type , "toObject" , protobuf . converter . toObject ( type ) , {
474+ util : "$protobuf.util" ,
475+ types : hasTypes ? "$types" : undefined
476+ } ) ;
477+
478+ push ( "" ) ;
479+ pushComment ( [
480+ "Creates a plain object from this " + type . name + " message. Also converts values to other types if specified." ,
481+ "@param {$protobuf.ConversionOptions} [options] Conversion options" ,
482+ "@returns {Object.<string,*>} Plain object"
483+ ] ) ;
484+ push ( "$prototype.toObject = function toObject(options) {" ) ;
466485 ++ indent ;
467- push ( "return this.convert(source, $protobuf.converters.message , options);" ) ;
486+ push ( "return this.constructor.toObject(this , options);" ) ;
468487 -- indent ;
469488 push ( "};" ) ;
470489
471490 push ( "" ) ;
472491 pushComment ( [
473- "Converts this " + type . name + " message to JSON." ,
474- "@param {Object.<string,*>} [options] Conversion options" ,
492+ "Converts this " + type . name + " to JSON." ,
475493 "@returns {Object.<string,*>} JSON object"
476494 ] ) ;
477- push ( "$prototype.asJSON = function asJSON(options ) {" ) ;
495+ push ( "$prototype.toJSON = function toJSON( ) {" ) ;
478496 ++ indent ;
479- push ( "return this.constructor.convert(this, $protobuf.converters.json, options);" ) ;
497+ push ( "return this.constructor.toObject(this, {" ) ;
498+ ++ indent ;
499+ push ( "longs: String," ) ;
500+ push ( "enums: String," ) ;
501+ push ( "bytes: String" ) ;
502+ -- indent ;
503+ push ( "});" ) ;
480504 -- indent ;
481505 push ( "};" ) ;
482506 }
0 commit comments