mirror of
https://github.com/arkadiyt/protodump.git
synced 2026-10-21 01:36:52 +02:00
More bug fixes
This commit is contained in:
1 parent
63401cf45c
commit
49de7c273a
3 files changed
+29
-9
No files matched your search
@@ -3,6 +3,7 @@ syntax = "proto3";
|
||||
package hello.world;
|
||||
|
||||
option go_package = "./;helloworld";
|
||||
option php_namespace = "Google\\Cloud\\Iam\\V1";
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (.hello.world.HelloRequest) returns (.hello.world.HelloReply) {}
|
||||
@@ -30,14 +31,14 @@ message HelloRequest {
|
||||
}
|
||||
|
||||
string name = 1;
|
||||
hello.world.HelloRequest.Test blah = 2;
|
||||
hello.world.HelloRequest.NestedEnum blahblah = 3;
|
||||
hello.world.HelloReply blaha = 4;
|
||||
.hello.world.HelloRequest.Test blah = 2;
|
||||
.hello.world.HelloRequest.NestedEnum blahblah = 3;
|
||||
.hello.world.HelloReply blaha = 4;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
hello.world.HelloRequest.Test blah = 2;
|
||||
hello.world.HelloRequest.NestedEnum blahblah = 3;
|
||||
.hello.world.HelloRequest.Test blah = 2;
|
||||
.hello.world.HelloRequest.NestedEnum blahblah = 3;
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -2,6 +2,7 @@ package protodump
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -44,7 +45,13 @@ func (pd *ProtoDefinition) String() string {
|
||||
}
|
||||
|
||||
func (pd *ProtoDefinition) Filename() string {
|
||||
return pd.filename
|
||||
goPackage := pd.pb.GetOptions().GetGoPackage()
|
||||
index := strings.Index(goPackage, ";")
|
||||
if index == -1 {
|
||||
return pd.descriptor.Path()
|
||||
}
|
||||
|
||||
return path.Join(goPackage[:index], path.Base(pd.descriptor.Path()))
|
||||
}
|
||||
|
||||
func (pd *ProtoDefinition) writeMethod(method protoreflect.MethodDescriptor) {
|
||||
@@ -83,8 +90,10 @@ func (pd *ProtoDefinition) writeType(field protoreflect.FieldDescriptor) {
|
||||
kind := field.Kind().String()
|
||||
|
||||
if kind == "message" {
|
||||
pd.write(".")
|
||||
pd.write(string(field.Message().FullName()))
|
||||
} else if kind == "enum" {
|
||||
pd.write(".")
|
||||
pd.write(string(field.Enum().FullName()))
|
||||
} else if kind == "map" {
|
||||
pd.write("map<")
|
||||
@@ -217,7 +226,7 @@ func (pd *ProtoDefinition) writeStringFileOptions(name string, value string) {
|
||||
pd.write("option ")
|
||||
pd.write(name)
|
||||
pd.write(" = \"")
|
||||
pd.write(value)
|
||||
pd.write(strings.ReplaceAll(value, "\\", "\\\\"))
|
||||
pd.write("\";\n")
|
||||
}
|
||||
|
||||
@@ -333,7 +342,6 @@ func NewFromDescriptor(pb *descriptorpb.FileDescriptorProto) (*ProtoDefinition,
|
||||
pd := ProtoDefinition{
|
||||
pb: pb,
|
||||
descriptor: descriptor,
|
||||
filename: descriptor.Path(),
|
||||
}
|
||||
|
||||
pd.writeFileDescriptor()
|
||||
|
||||
+12
-1
@@ -13,13 +13,24 @@ const magicByte = 0xa
|
||||
|
||||
func consumeBytes(data []byte, position int) int {
|
||||
start := position
|
||||
consumedFieldOne := false
|
||||
for {
|
||||
_, _, len := protowire.ConsumeField(data[position:])
|
||||
number, _, len := protowire.ConsumeField(data[position:])
|
||||
if len < 0 {
|
||||
_ = protowire.ParseError(len)
|
||||
return position - start
|
||||
|
||||
}
|
||||
|
||||
// Only consume Field 1 once (to handle the case where protobuf definitions are adjacent
|
||||
// in program memory)
|
||||
if number == 1 {
|
||||
if consumedFieldOne {
|
||||
return position - start
|
||||
}
|
||||
consumedFieldOne = true
|
||||
}
|
||||
|
||||
position += len
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user