Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions cmd/protoc-gen-cpp-tableau-loader/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,50 +165,58 @@ func ParseCppClassType(md protoreflect.MessageDescriptor) string {
return strings.ReplaceAll(protoFullName, ".", "::")
}

func ParseLeveledMapPrefix(md protoreflect.MessageDescriptor, mapFd protoreflect.FieldDescriptor) string {
if mapFd.MapValue().Kind() == protoreflect.MessageKind {
localMsgProtoName := strings.TrimPrefix(string(mapFd.MapValue().Message().FullName()), string(md.FullName())+".")
return strings.ReplaceAll(localMsgProtoName, ".", "_")
}
return mapFd.MapValue().Kind().String()
}

type MapKey struct {
Type string
Name string
}

type MapKeys []MapKey
type MapKeySlice []MapKey

func (keys MapKeys) AddMapKey(newKey MapKey) MapKeys {
func (s MapKeySlice) AddMapKey(newKey MapKey) MapKeySlice {
if newKey.Name == "" {
newKey.Name = fmt.Sprintf("key%d", len(keys)+1)
newKey.Name = fmt.Sprintf("key%d", len(s)+1)
} else {
for _, key := range keys {
for _, key := range s {
if key.Name == newKey.Name {
// rewrite to avoid name confict
newKey.Name = fmt.Sprintf("%s%d", newKey.Name, len(keys)+1)
newKey.Name = fmt.Sprintf("%s%d", newKey.Name, len(s)+1)
break
}
}
}
return append(keys, newKey)
return append(s, newKey)
}

// GenGetParams generates function parameters, which are the names listed in the function's definition.
func (keys MapKeys) GenGetParams() string {
func (s MapKeySlice) GenGetParams() string {
var params []string
for _, key := range keys {
for _, key := range s {
params = append(params, ToConstRefType(key.Type)+" "+key.Name)
}
return strings.Join(params, ", ")
}

// GenGetArguments generates function arguments, which are the real values passed to the function.
func (keys MapKeys) GenGetArguments() string {
func (s MapKeySlice) GenGetArguments() string {
var params []string
for _, key := range keys {
for _, key := range s {
params = append(params, key.Name)
}
return strings.Join(params, ", ")
}

// GenOtherArguments generates function arguments for other value of std::tie.
func (keys MapKeys) GenOtherArguments(other string) string {
func (s MapKeySlice) GenOtherArguments(other string) string {
var params []string
for _, key := range keys {
for _, key := range s {
params = append(params, other+"."+key.Name)
}
return strings.Join(params, ", ")
Expand All @@ -218,6 +226,10 @@ func Indent(depth int) string {
return strings.Repeat(" ", depth)
}

func Whitespace(count int) string {
Comment thread
wenchy marked this conversation as resolved.
return strings.Repeat(" ", count)
}

func ParseMapValueType(fd protoreflect.FieldDescriptor) string {
valueType := ParseCppType(fd.MapValue())
if fd.MapValue().Kind() == protoreflect.MessageKind {
Expand Down
309 changes: 0 additions & 309 deletions cmd/protoc-gen-cpp-tableau-loader/index/index.go

This file was deleted.

Loading