This commit is contained in:
Jeff Carr 2025-01-09 03:42:29 -06:00
parent 355817c0db
commit 4ff3a92bc6
2 changed files with 35 additions and 20 deletions

View File

@ -38,18 +38,33 @@ func (pb *Files) findAutogenpb(f *File) error {
// log.Info("line:", line) // log.Info("line:", line)
parts := strings.Fields(line) parts := strings.Fields(line)
if strings.Contains(line, "autogenpb:marshal") {
if strings.Contains(line, "autogenpb:sort") {
if parts[0] == "repeated" {
newm := parts[1] newm := parts[1]
if curmsg != nil { if curmsg == nil {
log.Info("Error: Found Sort for:", newm, "however, this struct can't be used")
// log.Info("found marshal", newm) // log.Info("found marshal", newm)
marshalKeys = append(marshalKeys, newm) marshalKeys = append(marshalKeys, newm)
} else {
log.Info("Found Sort for:", newm, "in struct", curmsg.Name)
}
} else {
log.Info("Error:", line)
log.Info("Error: can not sort on non repeated fields")
} }
} }
if strings.Contains(line, "autogenpb:unique") { if strings.Contains(line, "autogenpb:unique") {
if parts[0] == "repeated" {
// log.Info("Found Unique for:", parts)
newu := parts[1] newu := parts[1]
newu = cases.Title(language.English, cases.NoLower).String(newu) newu = cases.Title(language.English, cases.NoLower).String(newu)
// log.Info("found unique field", newu) log.Info("found unique field", newu, "in struct", curmsg.Name)
uniqueKeys = append(uniqueKeys, newu) // uniqueKeys = append(uniqueKeys, newu)
} else {
log.Info("Error:", line)
log.Info("Error: can not append on non repeated fields")
}
} }
} }
return nil return nil

View File

@ -21,11 +21,11 @@ message Apple { // `autogenpb:marshal`
} }
message Apples { // `autogenpb:marshal` `autogenpb:mutex` message Apples { // `autogenpb:marshal` `autogenpb:mutex`
string uuid = 1; // `autogen:default:b2a2de35-07b6-443b-8188-709e27bee8a7` string uuid = 1; // `autogenpb:default:b2a2de35-07b6-443b-8188-709e27bee8a7`
string version = 2; // `autogen:default:2` string version = 2; // `autogenpb:default:2`
repeated Apple Apples = 3; // `autogen:sort` repeated Apple Apples = 3; // `autogenpb:sort`
repeated Pears More = 4; // `autogen:sort` repeated Pears More = 4; // `autogenpb:sort`
repeated string Color = 5; // `autogen:sort` `autogen:unique` repeated string Color = 5; // `autogenpb:sort` `autogenpb:unique`
} }
message Pears { message Pears {
@ -70,13 +70,13 @@ message MsgName {
repeated string unique = 5; // if the fields should have AppendUnique() functions repeated string unique = 5; // if the fields should have AppendUnique() functions
} }
message File { // `autogen:nomarshal` message File { // `autogenpb:nomarshal`
string name = 1; // for this one: autogen.proto string name = 1; // for this one: autogen.proto
string uuid = 2; // the uuid to use in a func NewMsgName() string uuid = 2; // the uuid to use in a func NewMsgName()
int64 version = 3; // the version to use in a func NewMsgName() int64 version = 3; // the version to use in a func NewMsgName()
// in this proto file, this would have "Apple", "Apples", ... "File", etc... // in this proto file, this would have "Apple", "Apples", ... "File", etc...
repeated MsgName msgNames = 4; // `autogen:unique` // in this file repeated MsgName msgNames = 4; // `autogenpb:unique` // in this file
} }
// I know, I know, the whole point of using protobuf // I know, I know, the whole point of using protobuf
@ -85,15 +85,15 @@ message File { // `autogen:nomarshal`
// trivial and empty protobuf message can marshal and identify all the files // trivial and empty protobuf message can marshal and identify all the files
// also, this could be used to modify /usr/bin/file /usr/share/magic to identify the files // also, this could be used to modify /usr/bin/file /usr/share/magic to identify the files
// maybe this is already been done and is pointless, but it seems like a good idea // maybe this is already been done and is pointless, but it seems like a good idea
message Files { // `autogen:marshal` message Files { // `autogenpb:marshal`
string uuid = 1; // `autogen:uuid:fakeuuid` string uuid = 1; // `autogenpb:uuid:fakeuuid`
int64 version = 2; // `autogen:id:42` int64 version = 2; // `autogenpb:id:42`
repeated File Files = 3; // an array of each .proto file in the working directory repeated File Files = 3; // an array of each .proto file in the working directory
} }
// this generic message is used by autogen to identify and // this generic message is used by autogen to identify and
// then dump the uuid and version from any arbitrary .pb file // then dump the uuid and version from any arbitrary .pb file
message Identify { // `autogen:marshal` message Identify { // `autogenpb:marshal`
string uuid = 1; // string uuid = 1; //
int64 version = 2; // int64 version = 2; //
} }