diff options
| author | Jeff Carr <[email protected]> | 2025-10-08 01:24:58 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-08 01:24:58 -0500 |
| commit | c85f4d0302f3eff04558dfdd388dcbf631e37222 (patch) | |
| tree | c92efb3754f026287055f3e9727b1402f22a992f /populatePackagePB.go | |
| parent | 25bb3b31718d8ccf5e66f8bb9a11b7a4f295bf0f (diff) | |
make a map[string]string for adding to the PB
Diffstat (limited to 'populatePackagePB.go')
| -rw-r--r-- | populatePackagePB.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/populatePackagePB.go b/populatePackagePB.go new file mode 100644 index 0000000..10fb4f2 --- /dev/null +++ b/populatePackagePB.go @@ -0,0 +1,33 @@ +package debian + +import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" +) + +func setString(pb proto.Message, varname string, val string) bool { + msg := pb.ProtoReflect() // This is the entry point to the reflection API. + + descriptor := msg.Descriptor() // Get the message's descriptor, which contains metadata about its fields. + + fieldName := protoreflect.Name(varname) + fieldDescriptor := descriptor.Fields().ByName(fieldName) + + if fieldDescriptor == nil { + return false + } + + if fieldDescriptor.Kind() != protoreflect.StringKind { + // The field exists but is not a string, so we can't return it as one. + return false + } + + valueToSet := protoreflect.ValueOfString(varname) + + // 6. If the field exists and is a string, get its value. + // The value is returned as a protoreflect.Value. + msg.Set(fieldDescriptor, valueToSet) + + // 7. Convert the protoreflect.Value to a native Go string. + return true +} |
