@@ -13,10 +13,12 @@ var Type = protobuf.Type,
1313
1414var out = [ ] ;
1515var indent = 0 ;
16+ var config = { } ;
1617
1718static_target . description = "Static code without reflection" ;
1819
1920function static_target ( root , options , callback ) {
21+ config = options ;
2022 try {
2123 push ( "// Lazily resolved type references" ) ;
2224 push ( "var $lazyTypes = [];" ) ;
@@ -51,6 +53,7 @@ function static_target(root, options, callback) {
5153 } finally {
5254 out = [ ] ;
5355 indent = 0 ;
56+ config = { } ;
5457 }
5558}
5659
@@ -266,72 +269,91 @@ function buildType(ref, type) {
266269 push ( "});" ) ;
267270 } ) ;
268271
269- // #encode
270- push ( "" ) ;
271- pushComment ( [
272- "Encodes the specified " + type . name + "." ,
273- "@function" ,
274- "@param {" + fullName + "|Object} message " + type . name + " or plain object to encode" ,
275- "@param {Writer} [writer] Writer to encode to" ,
276- "@returns {Writer} Writer"
277- ] ) ;
278- buildFunction ( type , "encode" , protobuf . encode . generate ( type ) , {
279- Writer : "$protobuf.Writer" ,
280- util : "$protobuf.util"
281- } ) ;
272+ if ( config . encode !== false ) {
282273
283- // #encodeDelimited
284- push ( "" ) ;
285- pushComment ( [
286- "Encodes the specified " + type . name + ", length delimited ." ,
287- "@param {" + fullName + "|Object} message " + type . name + " or plain object to encode ",
288- "@param {Writer} [writer] Writer to encode to " ,
289- "@returns {Writer} Writer"
290- ] ) ;
291- push ( name ( type . name ) + ".encodeDelimited = function encodeDelimited(message, writer) {" ) ;
292- ++ indent ;
293- push ( "return this.encode(message, writer).ldelim();" ) ;
294- -- indent ;
295- push ( "};" ) ;
274+ // #encode
275+ push ( "" ) ;
276+ pushComment ( [
277+ "Encodes the specified " + type . name + "." ,
278+ "@function ",
279+ "@param {" + fullName + "|Object} message " + type . name + " or plain object to encode ",
280+ "@param {Writer} [writer] Writer to encode to" ,
281+ "@returns {Writer} Writer"
282+ ] ) ;
283+ buildFunction ( type , "encode" , protobuf . encode . generate ( type ) , {
284+ Writer : "$protobuf.Writer" ,
285+ util : "$protobuf.util"
286+ } ) ;
296287
297- // #decode
298- push ( "" ) ;
299- pushComment ( [
300- "Decodes a " + type . name + " from the specified reader or buffer." ,
301- "@function" ,
302- "@param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from" ,
303- "@param {number} [length] Message length if known beforehand" ,
304- "@returns {" + fullName + "} " + type . name
305- ] ) ;
306- buildFunction ( type , "decode" , protobuf . decode . generate ( type ) , {
307- Reader : "$protobuf.Reader" ,
308- util : "$protobuf.util"
309- } ) ;
288+ if ( config . delimited !== false ) {
310289
311- // #decodeDelimited
312- push ( "" ) ;
313- pushComment ( [
314- "Decodes a " + type . name + " from the specified reader or buffer , length delimited.",
315- "@param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from " ,
316- "@returns {" + fullName + "} " + type . name
317- ] ) ;
318- push ( name ( type . name ) + ".decodeDelimited = function decodeDelimited(readerOrBuffer) {" ) ;
319- ++ indent ;
320- push ( "readerOrBuffer = readerOrBuffer instanceof $protobuf.Reader ? readerOrBuffer : $protobuf.Reader(readerOrBuffer);" ) ;
321- push ( "return this.decode(readerOrBuffer, readerOrBuffer.uint32() );" ) ;
322- -- indent ;
323- push ( "};" ) ;
290+ // #encodeDelimited
291+ push ( "" ) ;
292+ pushComment ( [
293+ "Encodes the specified " + type . name + " , length delimited.",
294+ "@param {" + fullName + "|Object} message " + type . name + " or plain object to encode ",
295+ "@param {Writer} [writer] Writer to encode to" ,
296+ "@returns {Writer} Writer"
297+ ] ) ;
298+ push ( name ( type . name ) + ".encodeDelimited = function encodeDelimited(message, writer) {" ) ;
299+ ++ indent ;
300+ push ( "return this.encode(message, writer).ldelim( );" ) ;
301+ -- indent ;
302+ push ( "};" ) ;
324303
325- // #verify
326- push ( "" ) ;
327- pushComment ( [
328- "Verifies a " + type . name + "." ,
329- "@param {" + fullName + "|Object} message " + type . name + " or plain object to verify" ,
330- "@returns {?string} `null` if valid, otherwise the reason why it is not"
331- ] ) ;
332- buildFunction ( type , "verify" , protobuf . verify . generate ( type ) , {
333- util : "$protobuf.util"
334- } ) ;
304+ }
305+
306+ }
307+
308+ if ( config . decode !== false ) {
309+
310+ // #decode
311+ push ( "" ) ;
312+ pushComment ( [
313+ "Decodes a " + type . name + " from the specified reader or buffer." ,
314+ "@function" ,
315+ "@param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from" ,
316+ "@param {number} [length] Message length if known beforehand" ,
317+ "@returns {" + fullName + "} " + type . name
318+ ] ) ;
319+ buildFunction ( type , "decode" , protobuf . decode . generate ( type ) , {
320+ Reader : "$protobuf.Reader" ,
321+ util : "$protobuf.util"
322+ } ) ;
323+
324+ if ( config . delimited !== false ) {
325+
326+ // #decodeDelimited
327+ push ( "" ) ;
328+ pushComment ( [
329+ "Decodes a " + type . name + " from the specified reader or buffer, length delimited." ,
330+ "@param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from" ,
331+ "@returns {" + fullName + "} " + type . name
332+ ] ) ;
333+ push ( name ( type . name ) + ".decodeDelimited = function decodeDelimited(readerOrBuffer) {" ) ;
334+ ++ indent ;
335+ push ( "readerOrBuffer = readerOrBuffer instanceof $protobuf.Reader ? readerOrBuffer : $protobuf.Reader(readerOrBuffer);" ) ;
336+ push ( "return this.decode(readerOrBuffer, readerOrBuffer.uint32());" ) ;
337+ -- indent ;
338+ push ( "};" ) ;
339+
340+ }
341+ }
342+
343+ if ( config . verify !== false ) {
344+
345+ // #verify
346+ push ( "" ) ;
347+ pushComment ( [
348+ "Verifies a " + type . name + "." ,
349+ "@param {" + fullName + "|Object} message " + type . name + " or plain object to verify" ,
350+ "@returns {?string} `null` if valid, otherwise the reason why it is not"
351+ ] ) ;
352+ buildFunction ( type , "verify" , protobuf . verify . generate ( type ) , {
353+ util : "$protobuf.util"
354+ } ) ;
355+
356+ }
335357}
336358
337359function buildService ( ref , service ) {
0 commit comments