#include "Errors.h" #include "string_utils.h" #include #include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/text_format.h" #include #include #include using namespace android::stream_proto; using namespace google::protobuf; using namespace google::protobuf::compiler; using namespace google::protobuf::io; using namespace std; /** * Position of the field type in a (long long) fieldId. */ const uint64_t FIELD_TYPE_SHIFT = 32; // // FieldId flags for whether the field is single, repeated or packed. // TODO: packed is not supported yet. // const uint64_t FIELD_COUNT_SHIFT = 40; const uint64_t FIELD_COUNT_MASK = 0x0fULL << FIELD_COUNT_SHIFT; const uint64_t FIELD_COUNT_UNKNOWN = 0; const uint64_t FIELD_COUNT_SINGLE = 1ULL << FIELD_COUNT_SHIFT; const uint64_t FIELD_COUNT_REPEATED = 2ULL << FIELD_COUNT_SHIFT; const uint64_t FIELD_COUNT_PACKED = 4ULL << FIELD_COUNT_SHIFT; // Indent const string INDENT = " "; /** * See if this is the file for this request, and not one of the imported ones. */ static bool should_generate_for_file(const CodeGeneratorRequest& request, const string& file) { const int N = request.file_to_generate_size(); for (int i=0; i"; case FieldDescriptorProto::TYPE_MESSAGE: return field.type_name(); case FieldDescriptorProto::TYPE_BYTES: return "bytes"; case FieldDescriptorProto::TYPE_UINT32: return "uint32"; case FieldDescriptorProto::TYPE_ENUM: return field.type_name(); case FieldDescriptorProto::TYPE_SFIXED32: return "sfixed32"; case FieldDescriptorProto::TYPE_SFIXED64: return "sfixed64"; case FieldDescriptorProto::TYPE_SINT32: return "sint32"; case FieldDescriptorProto::TYPE_SINT64: return "sint64"; default: // won't happen return "void"; } } static void write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& indent) { const int N = enu.value_size(); text << indent << "// enum " << enu.name() << endl; for (int i=0; i namespaces = split(file_descriptor.package(), '.'); for (vector::iterator it = namespaces.begin(); it != namespaces.end(); it++) { text << "namespace " << *it << " {" << endl; } text << endl; size_t N; N = file_descriptor.enum_type_size(); for (size_t i=0; i::iterator it = namespaces.begin(); it != namespaces.end(); it++) { text << "} // " << *it << endl; } text << endl; text << "#endif // " << header << endl; CodeGeneratorResponse::File* file_response = response->add_file(); file_response->set_name(make_filename(file_descriptor)); file_response->set_content(text.str()); } int main(int argc, char const *argv[]) { (void)argc; (void)argv; GOOGLE_PROTOBUF_VERIFY_VERSION; CodeGeneratorRequest request; CodeGeneratorResponse response; // Read the request request.ParseFromIstream(&cin); // Build the files we need. const int N = request.proto_file_size(); for (int i=0; i