summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--testfiles/Makefile23
-rw-r--r--testfiles/auto.proto99
-rw-r--r--testfiles/main.go22
4 files changed, 146 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 903d8f2..105c2d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,5 +4,5 @@ go.mod
go.sum
/files/*
/work/*
-autogenpb
-testSort/testSort
+autogenpb*
+testfiles/testfiles
diff --git a/testfiles/Makefile b/testfiles/Makefile
new file mode 100644
index 0000000..bc4405b
--- /dev/null
+++ b/testfiles/Makefile
@@ -0,0 +1,23 @@
+VERSION = $(shell git describe --tags)
+BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
+
+full: clean goimports auto vet build
+ ./testfiles
+
+vet:
+ @GO111MODULE=off go vet
+ @echo this go binary package should build okay
+
+build:
+ GO111MODULE=off go build
+
+auto:
+ ../autogenpb --proto auto.proto --package main
+
+goimports:
+ goimports -w *.go
+
+clean:
+ -rm -f go.*
+ -rm -f *.pb.go
+ -rm -f testfiles
diff --git a/testfiles/auto.proto b/testfiles/auto.proto
new file mode 100644
index 0000000..4095b0d
--- /dev/null
+++ b/testfiles/auto.proto
@@ -0,0 +1,99 @@
+syntax = "proto3";
+
+// here are some docs, but probably it's just easier to run
+// autogenpb on this file and see what gets autogenerated
+// in this directory. All autogenerated files are named *.pb.go
+
+// the 'uuid' standard at the end is an experiment
+// establish a way to identify arbitrary .pb files
+
+// You can generate Marshal & Unmarshal for any struct (message) you want
+// You can generate SortBy and Append functions ONLY FOR 'repeated <message>'
+// Also, those structs must be defined in the same file
+// Additionally, you must use `autogenpb:mutex` on the parent struct.
+// The autogenerated code requires a RW mutex and autogenpb will insert it into the struct
+
+package main;
+
+message Apple { // `autogenpb:marshal`
+ string name = 1; // `autogenpb:unique` // generates SortByxxx() and AppendUnique() functions
+ string genus = 2; // `autogenpb:unique` // generates same thing here but SortByGenus()
+}
+
+message Apples { // `autogenpb:marshal` `autogenpb:mutex`
+ string uuid = 1; // `autogen:default:b2a2de35-07b6-443b-8188-709e27bee8a7`
+ string version = 2; // `autogen:default:2`
+ repeated Apple Apples = 3; // `autogen:sort`
+ repeated Pears More = 4; // `autogen:sort`
+ repeated string Color = 5; // `autogen:sort` `autogen:unique`
+}
+
+message Pears {
+ string name = 1; //
+ string favorite = 2; // `autogenpb:sort`
+}
+
+// above is an example
+
+//
+// below are the actual structs autogen uses
+// autogen parses the .proto file and then store the information
+// it needs in these protobuf files, then it processes the
+// protobuf files to write out *.sort.pb.go and *.marshal.pb.go files
+//
+message MsgName {
+ // If you have:
+ //
+ // "Shelf" for msgname
+ // "Books" for name
+ //
+ // Then in the proto file, that would mean it would look like:
+ //
+ // message Shelf {
+ // and then
+ // repeated string Books = 42;
+ //
+ // autogenpb will then generate sort functions for each 'name'
+ // things like:
+ //
+ // for _, b := range all.Book {
+ //
+ // and sort functions like:
+ //
+ // func (a ShelfBook) Less(i, j int) bool { return a[i].Book < a[j].Book }
+ //
+
+ string name = 1; // the name of the message aka struct. for this example: "Shelf"
+ bool marshal = 2; // if "Shelf" should have Marshal & Unmarshal functions
+ bool mutex = 3; // an experiment to insert a mutex into the protoc generated msg struct (bad idea?)
+ repeated string sort = 4; // "Book", "Picture", etc
+ repeated string unique = 5; // if the fields should have AppendUnique() functions
+}
+
+message File { // `autogen:nomarshal`
+ string name = 1; // for this one: autogen.proto
+ string uuid = 2; // the uuid 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...
+ repeated MsgName msgNames = 4; // `autogen:unique` // in this file
+}
+
+// I know, I know, the whole point of using protobuf
+// is so you don't need a uuid or versions because it's
+// inherently forward compatable. nonetheless, a simple stubbed out
+// 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
+// maybe this is already been done and is pointless, but it seems like a good idea
+message Files { // `autogen:marshal`
+ string uuid = 1; // `autogen:uuid:fakeuuid`
+ int64 version = 2; // `autogen:id:42`
+ repeated File Files = 3; // an array of each .proto file in the working directory
+}
+
+// this generic message is used by autogen to identify and
+// then dump the uuid and version from any arbitrary .pb file
+message Identify { // `autogen:marshal`
+ string uuid = 1; //
+ int64 version = 2; //
+}
diff --git a/testfiles/main.go b/testfiles/main.go
new file mode 100644
index 0000000..b67f3d8
--- /dev/null
+++ b/testfiles/main.go
@@ -0,0 +1,22 @@
+//go:build go1.20
+// +build go1.20
+
+package main
+
+import "go.wit.com/log"
+
+// sent via -ldflags
+var VERSION string
+var BUILDTIME string
+
+var sortmap map[string]string
+var marshalKeys []string
+var uniqueKeys []string
+
+var pb *Files
+
+func main() {
+
+ pb = new(Files)
+ log.Info("did nothing yet")
+}