mirror of
https://github.com/arkadiyt/protodump.git
synced 2026-10-23 18:49:38 +02:00
Handle nested messages/enums; fix streaming bug
This commit is contained in:
1 parent
6e610acbaa
commit
d57358e131
1 file changed
+16
-7
+16
-7
@@ -51,14 +51,14 @@ func (pd *ProtoDefinition) writeMethod(method protoreflect.MethodDescriptor) {
|
|||||||
// TODO need to handle method options
|
// TODO need to handle method options
|
||||||
pd.writeIndented("rpc ")
|
pd.writeIndented("rpc ")
|
||||||
pd.write(string(method.Name()))
|
pd.write(string(method.Name()))
|
||||||
pd.write("(")
|
pd.write(" (")
|
||||||
if method.IsStreamingClient() {
|
if method.IsStreamingClient() {
|
||||||
pd.write("streaming ")
|
pd.write("stream ")
|
||||||
}
|
}
|
||||||
pd.write(string(method.Input().Name()))
|
pd.write(string(method.Input().Name()))
|
||||||
pd.write(") returns (")
|
pd.write(") returns (")
|
||||||
if method.IsStreamingServer() {
|
if method.IsStreamingServer() {
|
||||||
pd.write("streaming ")
|
pd.write("stream ")
|
||||||
}
|
}
|
||||||
pd.write(string(method.Output().Name()))
|
pd.write(string(method.Output().Name()))
|
||||||
pd.write(") {}\n")
|
pd.write(") {}\n")
|
||||||
@@ -79,10 +79,11 @@ func (pd *ProtoDefinition) writeService(service protoreflect.ServiceDescriptor)
|
|||||||
|
|
||||||
func (pd *ProtoDefinition) writeType(field protoreflect.FieldDescriptor) {
|
func (pd *ProtoDefinition) writeType(field protoreflect.FieldDescriptor) {
|
||||||
kind := field.Kind().String()
|
kind := field.Kind().String()
|
||||||
|
|
||||||
if kind == "message" {
|
if kind == "message" {
|
||||||
pd.write(string(field.Message().Name()))
|
pd.write(string(field.Message().FullName()))
|
||||||
} else if kind == "enum" {
|
} else if kind == "enum" {
|
||||||
pd.write(string(field.Enum().Name()))
|
pd.write(string(field.Enum().FullName()))
|
||||||
} else if kind == "map" {
|
} else if kind == "map" {
|
||||||
pd.write("map<")
|
pd.write("map<")
|
||||||
pd.writeType(field.MapKey())
|
pd.writeType(field.MapKey())
|
||||||
@@ -125,7 +126,7 @@ func (pd *ProtoDefinition) writeField(field protoreflect.FieldDescriptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pd *ProtoDefinition) writeEnum(enum protoreflect.EnumDescriptor) {
|
func (pd *ProtoDefinition) writeEnum(enum protoreflect.EnumDescriptor) {
|
||||||
pd.write("enum ")
|
pd.writeIndented("enum ")
|
||||||
pd.write(string(enum.Name()))
|
pd.write(string(enum.Name()))
|
||||||
pd.write(" {\n")
|
pd.write(" {\n")
|
||||||
// TODO need to handle enum options (allow_alias)
|
// TODO need to handle enum options (allow_alias)
|
||||||
@@ -143,7 +144,7 @@ func (pd *ProtoDefinition) writeEnum(enum protoreflect.EnumDescriptor) {
|
|||||||
|
|
||||||
func (pd *ProtoDefinition) writeMessage(message protoreflect.MessageDescriptor) {
|
func (pd *ProtoDefinition) writeMessage(message protoreflect.MessageDescriptor) {
|
||||||
// TODO need to handle message options
|
// TODO need to handle message options
|
||||||
pd.write("message ")
|
pd.writeIndented("message ")
|
||||||
pd.write(string(message.Name()))
|
pd.write(string(message.Name()))
|
||||||
pd.write(" {\n")
|
pd.write(" {\n")
|
||||||
pd.indent()
|
pd.indent()
|
||||||
@@ -171,6 +172,14 @@ func (pd *ProtoDefinition) writeMessage(message protoreflect.MessageDescriptor)
|
|||||||
pd.write(";\n")
|
pd.write(";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < message.Messages().Len(); i++ {
|
||||||
|
pd.writeMessage(message.Messages().Get(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < message.Enums().Len(); i++ {
|
||||||
|
pd.writeEnum(message.Enums().Get(i))
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < message.Fields().Len(); i++ {
|
for i := 0; i < message.Fields().Len(); i++ {
|
||||||
field := message.Fields().Get(i)
|
field := message.Fields().Get(i)
|
||||||
if field.ContainingOneof() == nil {
|
if field.ContainingOneof() == nil {
|
||||||
|
|||||||
Reference in new issue
Block a user