@@ -120,7 +120,9 @@ grpc::string NodeObjectPath(const Descriptor* descriptor) {
120
120
}
121
121
122
122
// Prints out the message serializer and deserializer functions
123
- void PrintMessageTransformer (const Descriptor* descriptor, Printer* out) {
123
+ void PrintMessageTransformer (const Descriptor* descriptor,
124
+ Printer* out,
125
+ const Parameters& params) {
124
126
map<grpc::string, grpc::string> template_vars;
125
127
grpc::string full_name = descriptor->full_name ();
126
128
template_vars[" identifier_name" ] = MessageIdentifierName (full_name);
@@ -129,12 +131,14 @@ void PrintMessageTransformer(const Descriptor* descriptor, Printer* out) {
129
131
// Print the serializer
130
132
out->Print (template_vars, " function serialize_$identifier_name$(arg) {\n " );
131
133
out->Indent ();
132
- out->Print (template_vars, " if (!(arg instanceof $node_name$)) {\n " );
133
- out->Indent ();
134
- out->Print (template_vars,
135
- " throw new Error('Expected argument of type $name$');\n " );
136
- out->Outdent ();
137
- out->Print (" }\n " );
134
+ if (!params.omit_serialize_instanceof ) {
135
+ out->Print (template_vars, " if (!(arg instanceof $node_name$)) {\n " );
136
+ out->Indent ();
137
+ out->Print (template_vars,
138
+ " throw new Error('Expected argument of type $name$');\n " );
139
+ out->Outdent ();
140
+ out->Print (" }\n " );
141
+ }
138
142
out->Print (" return Buffer.from(arg.serializeBinary());\n " );
139
143
out->Outdent ();
140
144
out->Print (" }\n\n " );
@@ -232,12 +236,14 @@ void PrintImports(const FileDescriptor* file, Printer* out,
232
236
out->Print (" \n " );
233
237
}
234
238
235
- void PrintTransformers (const FileDescriptor* file, Printer* out) {
239
+ void PrintTransformers (const FileDescriptor* file,
240
+ Printer* out,
241
+ const Parameters& params) {
236
242
map<grpc::string, const Descriptor*> messages = GetAllMessages (file);
237
243
for (std::map<grpc::string, const Descriptor*>::iterator it =
238
244
messages.begin ();
239
245
it != messages.end (); it++) {
240
- PrintMessageTransformer (it->second , out);
246
+ PrintMessageTransformer (it->second , out, params );
241
247
}
242
248
out->Print (" \n " );
243
249
}
@@ -273,7 +279,7 @@ grpc::string GenerateFile(const FileDescriptor* file,
273
279
274
280
PrintImports (file, &out, params);
275
281
276
- PrintTransformers (file, &out);
282
+ PrintTransformers (file, &out, params );
277
283
278
284
PrintServices (file, &out, params);
279
285
0 commit comments