Browse Source

Vendor protoc codegen descriptor stubs (protoc_gen_{request,response}_pb2)

the-codemancer 2 months ago
parent
commit
55143d5fc8

+ 38 - 0
proto/google/protobuf/compiler/codegen_request.proto

@@ -0,0 +1,38 @@
+// Vendored subset of google/protobuf/compiler/codegen_request.proto.
+//
+// protoc emits a full CodeGeneratorRequest on the plugin's stdin. We only
+// need the fields chattolib's protoc plugin reads, so this is a trimmed copy.
+// protoc tolerates the subset: it still serializes the complete request, and
+// we parse only what we need. Field numbers match the canonical proto so the
+// wire format lines up.
+syntax = "proto2";
+package google.protobuf.compiler;
+
+message FileDescriptorProto {
+  optional string name = 1;
+  optional string package = 2;
+  repeated DescriptorProto message_type = 3;
+  repeated ServiceDescriptorProto service = 6;
+}
+
+message DescriptorProto {
+  optional string name = 1;
+}
+
+message MethodDescriptorProto {
+  optional string name = 1;
+  optional string input_type = 2;
+  optional string output_type = 3;
+}
+
+message ServiceDescriptorProto {
+  optional string name = 1;
+  repeated MethodDescriptorProto method = 2;
+}
+
+message CodeGeneratorRequest {
+  repeated string file_to_generate = 1;
+  optional string parameter = 2;
+  optional string language = 3;
+  repeated FileDescriptorProto proto_file = 15;
+}

+ 18 - 0
proto/google/protobuf/compiler/codegen_response.proto

@@ -0,0 +1,18 @@
+// Vendored subset of google/protobuf/compiler/codegen_response.proto.
+// The plugin writes a CodeGeneratorResponse to stdout; protoc reads the
+// `file` entries. Field numbers match the canonical proto.
+syntax = "proto2";
+package google.protobuf.compiler;
+import "codegen_request.proto";
+
+message CodeGeneratorResponse {
+  optional string error = 1;
+  optional string generated_code_info = 2;
+  repeated File file = 15;
+
+  message File {
+    optional string name = 1;
+    optional string insertion_point = 2;
+    optional string content = 15;
+  }
+}

+ 0 - 0
src/chattolib/_pb/google/__init__.py


+ 0 - 0
src/chattolib/_pb/google/protobuf/__init__.py


+ 44 - 0
src/chattolib/_pb/google/protobuf/protoc_gen_request_pb2.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# NO CHECKED-IN PROTOBUF GENCODE
+# source: codegen_request.proto
+# Protobuf Python Version: 7.36.0
+"""Generated protocol buffer code."""
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import descriptor_pool as _descriptor_pool
+from google.protobuf import runtime_version as _runtime_version
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf.internal import builder as _builder
+_runtime_version.ValidateProtobufRuntimeVersion(
+    _runtime_version.Domain.PUBLIC,
+    7,
+    36,
+    0,
+    '',
+    'codegen_request.proto'
+)
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+
+
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x63odegen_request.proto\x12\x18google.protobuf.compiler\"\xb8\x01\n\x13\x46ileDescriptorProto\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07package\x18\x02 \x01(\t\x12?\n\x0cmessage_type\x18\x03 \x03(\x0b\x32).google.protobuf.compiler.DescriptorProto\x12\x41\n\x07service\x18\x06 \x03(\x0b\x32\x30.google.protobuf.compiler.ServiceDescriptorProto\"\x1f\n\x0f\x44\x65scriptorProto\x12\x0c\n\x04name\x18\x01 \x01(\t\"N\n\x15MethodDescriptorProto\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x12\n\ninput_type\x18\x02 \x01(\t\x12\x13\n\x0boutput_type\x18\x03 \x01(\t\"g\n\x16ServiceDescriptorProto\x12\x0c\n\x04name\x18\x01 \x01(\t\x12?\n\x06method\x18\x02 \x03(\x0b\x32/.google.protobuf.compiler.MethodDescriptorProto\"\x98\x01\n\x14\x43odeGeneratorRequest\x12\x18\n\x10\x66ile_to_generate\x18\x01 \x03(\t\x12\x11\n\tparameter\x18\x02 \x01(\t\x12\x10\n\x08language\x18\x03 \x01(\t\x12\x41\n\nproto_file\x18\x0f \x03(\x0b\x32-.google.protobuf.compiler.FileDescriptorProto')
+
+_globals = globals()
+_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
+_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'codegen_request_pb2', _globals)
+if not _descriptor._USE_C_DESCRIPTORS:
+  DESCRIPTOR._loaded_options = None
+  _globals['_FILEDESCRIPTORPROTO']._serialized_start=52
+  _globals['_FILEDESCRIPTORPROTO']._serialized_end=236
+  _globals['_DESCRIPTORPROTO']._serialized_start=238
+  _globals['_DESCRIPTORPROTO']._serialized_end=269
+  _globals['_METHODDESCRIPTORPROTO']._serialized_start=271
+  _globals['_METHODDESCRIPTORPROTO']._serialized_end=349
+  _globals['_SERVICEDESCRIPTORPROTO']._serialized_start=351
+  _globals['_SERVICEDESCRIPTORPROTO']._serialized_end=454
+  _globals['_CODEGENERATORREQUEST']._serialized_start=457
+  _globals['_CODEGENERATORREQUEST']._serialized_end=609
+# @@protoc_insertion_point(module_scope)

+ 39 - 0
src/chattolib/_pb/google/protobuf/protoc_gen_response_pb2.py

@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# NO CHECKED-IN PROTOBUF GENCODE
+# source: codegen_response.proto
+# Protobuf Python Version: 7.36.0
+"""Generated protocol buffer code."""
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import descriptor_pool as _descriptor_pool
+from google.protobuf import runtime_version as _runtime_version
+from google.protobuf import symbol_database as _symbol_database
+from google.protobuf.internal import builder as _builder
+_runtime_version.ValidateProtobufRuntimeVersion(
+    _runtime_version.Domain.PUBLIC,
+    7,
+    36,
+    0,
+    '',
+    'codegen_response.proto'
+)
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+from . import protoc_gen_request_pb2 as codegen__request__pb2
+
+
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x63odegen_response.proto\x12\x18google.protobuf.compiler\x1a\x15\x63odegen_request.proto\"\xc7\x01\n\x15\x43odeGeneratorResponse\x12\r\n\x05\x65rror\x18\x01 \x01(\t\x12\x1b\n\x13generated_code_info\x18\x02 \x01(\t\x12\x42\n\x04\x66ile\x18\x0f \x03(\x0b\x32\x34.google.protobuf.compiler.CodeGeneratorResponse.File\x1a>\n\x04\x46ile\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x17\n\x0finsertion_point\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x0f \x01(\t')
+
+_globals = globals()
+_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
+_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'codegen_response_pb2', _globals)
+if not _descriptor._USE_C_DESCRIPTORS:
+  DESCRIPTOR._loaded_options = None
+  _globals['_CODEGENERATORRESPONSE']._serialized_start=76
+  _globals['_CODEGENERATORRESPONSE']._serialized_end=275
+  _globals['_CODEGENERATORRESPONSE_FILE']._serialized_start=213
+  _globals['_CODEGENERATORRESPONSE_FILE']._serialized_end=275
+# @@protoc_insertion_point(module_scope)

+ 35 - 0
tests/test_codegen_descriptors.py

@@ -0,0 +1,35 @@
+"""The vendored protoc codegen descriptors must be importable and usable."""
+
+
+def test_codegen_request_round_trips():
+    from chattolib._pb.google.protobuf import protoc_gen_request_pb2 as g
+
+    req = g.CodeGeneratorRequest()
+    req.language = "chattolib"
+    req.file_to_generate.append("chatto/api/v1/rooms.proto")
+    # A service with one unary method.
+    fd = req.proto_file.add()
+    fd.name = "chatto/api/v1/rooms.proto"
+    fd.package = "chatto.api.v1"
+    svc = fd.service.add()
+    svc.name = "RoomService"
+    m = svc.method.add()
+    m.name = "JoinRoom"
+    m.input_type = ".chatto.api.v1.JoinRoomRequest"
+    m.output_type = ".chatto.api.v1.JoinRoomResponse"
+
+    data = req.SerializeToString()
+    req2 = g.CodeGeneratorRequest.FromString(data)
+    assert req2.file_to_generate[0] == "chatto/api/v1/rooms.proto"
+    assert req2.proto_file[0].service[0].method[0].name == "JoinRoom"
+
+
+def test_codegen_response_file_field():
+    from chattolib._pb.google.protobuf import protoc_gen_response_pb2 as g
+
+    resp = g.CodeGeneratorResponse()
+    resp.file.add().name = "out/foo_connect.py"
+    resp.file.add().content = "print('hi')"
+    data = resp.SerializeToString()
+    resp2 = g.CodeGeneratorResponse.FromString(data)
+    assert resp2.file[1].content == "print('hi')"