1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifdef _WIN32 9 #include <fcntl.h> 10 #else 11 #include <unistd.h> 12 #endif 13 14 #include "google/protobuf/descriptor.pb.h" 15 #include "absl/log/absl_check.h" 16 #include "absl/strings/escaping.h" 17 #include "google/protobuf/compiler/plugin.pb.h" 18 #include "google/protobuf/io/io_win32.h" 19 20 using google::protobuf::compiler::CodeGeneratorRequest; 21 using google::protobuf::compiler::CodeGeneratorResponse; 22 23 // This fake protoc plugin does nothing but write out the CodeGeneratorRequest 24 // in base64. This is not very useful except that it gives us a way to make 25 // assertions in tests about the contents of requests that protoc sends to 26 // plugins. main(int argc,char * argv[])27int main(int argc, char* argv[]) { 28 29 #ifdef _WIN32 30 google::protobuf::io::win32::setmode(STDIN_FILENO, _O_BINARY); 31 google::protobuf::io::win32::setmode(STDOUT_FILENO, _O_BINARY); 32 #endif 33 34 CodeGeneratorRequest request; 35 ABSL_CHECK(request.ParseFromFileDescriptor(STDIN_FILENO)); 36 ABSL_CHECK(!request.file_to_generate().empty()); 37 CodeGeneratorResponse response; 38 response.set_supported_features( 39 CodeGeneratorResponse::FEATURE_SUPPORTS_EDITIONS); 40 response.set_minimum_edition(google::protobuf::Edition::EDITION_PROTO2); 41 response.set_maximum_edition(google::protobuf::Edition::EDITION_MAX); 42 response.add_file()->set_name( 43 absl::StrCat(request.file_to_generate(0), ".request")); 44 response.mutable_file(0)->set_content( 45 absl::Base64Escape(request.SerializeAsString())); 46 ABSL_CHECK(response.SerializeToFileDescriptor(STDOUT_FILENO)); 47 return 0; 48 } 49