@@ -166,6 +166,10 @@ function buildType(ref, type) {
166166 -- indent ;
167167 push ( "}" ) ;
168168
169+ push ( "" ) ;
170+ push ( "/** @alias " + fullName + ".prototype */" ) ;
171+ push ( "var $prototype = " + name ( type . name ) + ".prototype;" ) ;
172+
169173 // default values
170174 type . fieldsArray . forEach ( function ( field ) {
171175 field . resolve ( ) ;
@@ -210,16 +214,52 @@ function buildType(ref, type) {
210214 jsType = "Array.<" + jsType + ">" ;
211215 push ( "" ) ;
212216 pushComment ( [
213- field . name + "." ,
217+ type . name + " " + field . name + "." ,
214218 "@name " + fullName + "#" + name ( field . name ) ,
215219 "@type {" + jsType + "}"
216220 ] ) ;
217221 if ( Array . isArray ( field . defaultValue ) ) {
218- push ( name ( type . name ) + ". prototype[" + JSON . stringify ( field . name ) + "] = $protobuf.util.emptyArray;" ) ;
222+ push ( "$ prototype[" + JSON . stringify ( field . name ) + "] = $protobuf.util.emptyArray;" ) ;
219223 } else if ( util . isObject ( field . defaultValue ) )
220- push ( name ( type . name ) + ". prototype[" + JSON . stringify ( field . name ) + "] = $protobuf.util.emptyObject;" ) ;
224+ push ( "$ prototype[" + JSON . stringify ( field . name ) + "] = $protobuf.util.emptyObject;" ) ;
221225 else
222- push ( name ( type . name ) + ".prototype[" + JSON . stringify ( field . name ) + "] = " + JSON . stringify ( field . defaultValue ) + ";" ) ;
226+ push ( "$prototype[" + JSON . stringify ( field . name ) + "] = " + JSON . stringify ( field . defaultValue ) + ";" ) ;
227+ } ) ;
228+
229+ // virtual oneof fields
230+ type . oneofsArray . forEach ( function ( oneof ) {
231+ oneof . resolve ( ) ;
232+ push ( "" ) ;
233+ pushComment ( [
234+ type . name + " " + oneof . name + "." ,
235+ "@name " + fullName + "#" + name ( oneof . name ) ,
236+ "@type {string|undefined}"
237+ ] ) ;
238+ push ( "$protobuf.util.prop($prototype, " + JSON . stringify ( oneof . name ) + ", {" ) ;
239+ ++ indent ;
240+ push ( "get: function getVirtual() {" ) ;
241+ ++ indent ;
242+ oneof . oneof . forEach ( function ( name ) {
243+ push ( "if (this[" + JSON . stringify ( name ) + "] !== undefined)" ) ;
244+ ++ indent ;
245+ push ( "return " + JSON . stringify ( name ) + ";" ) ;
246+ -- indent ;
247+ } ) ;
248+ push ( "return undefined;" ) ;
249+ -- indent ;
250+ push ( "}," ) ;
251+ push ( "set: function setVirtual(value) {" ) ;
252+ ++ indent ;
253+ oneof . oneof . forEach ( function ( name ) {
254+ push ( "if (value !== " + JSON . stringify ( name ) + ")" ) ;
255+ ++ indent ;
256+ push ( "delete this[" + JSON . stringify ( name ) + "];" ) ;
257+ -- indent ;
258+ } ) ;
259+ -- indent ;
260+ push ( "}" ) ;
261+ -- indent ;
262+ push ( "});" ) ;
223263 } ) ;
224264
225265 // #encode
0 commit comments