summaryrefslogtreecommitdiff
path: root/example/file.proto
blob: d65ccd0002308d92af0d3ae54dd742c545c91355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;    // `autogenpb:default:b2a2de35-07b6-443b-8188-709e27bee8a7`
	string   version        = 2;    // `autogenpb:default:2`
        repeated Apple apples   = 3;    // `autogenpb:sort` `autogenpb:unique`
        repeated Pear  pears    = 4;    // `autogenpb:sort` `autogenpb:unique`
        repeated Pear  more     = 5;    // `autogenpb:sort` `autogenpb:unique` // not supported. 'More' can only be the string 'Pears'
        repeated string  color  = 6;    // `autogenpb:sort` `autogenpb:unique`
}

message Pear {
	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 aq	= 5;    // if the fields should have AppendUnique() functions
        repeated string uniq    = 6;    // the non-repeating fields that should be unique
}

message Unique {
        string   name	        = 1;    // the variable name of the repeatable struct that must be unique
        string   msgName	= 2;    // the struct that is repeated
        repeated string keys	= 3;    // the variables in that structure to check are unique
}

message File {                                  // `autogenpb: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;    // `autogenpb: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 {                           // `autogenpb:marshal`
        string   uuid	          = 1;    // `autogenpb:uuid:fakeuuid`
        string   version          = 2;    // `autogenpb: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 {                        // `autogenpb:marshal`
        string   uuid	          = 1;    //
        int64    version          = 2;    //
}