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