summaryrefslogtreecommitdiff
path: root/file.proto
blob: 594033a305bf53146965ab96b5005da8e453e3a0 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
syntax = "proto3";

// Look at "example/fruit.proto" not this file

// this file is actually used by autogenpb

// 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;

//
// 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 MsgVar {
        string                varName           = 1;  // the variable name
        string                varType           = 2;  // the variable type
        bool                  isRepeated        = 3;  // does the variable repeate
        bool                  hasSort           = 4;  // marked with sort
        bool                  hasUnique         = 5;  // marked with unique
}

message MsgName {
        string                name              = 1;  // the name of the message aka struct. for this example: "Shelf"
        string                lockname          = 2;  // name of the lockfile. ends in Mu
        bool                  doMarshal         = 3;  // if msg struct should have Marshal & Unmarshal functions
        bool                  doMutex           = 4;  // true if a mutex is needed for the message struct
        bool                  doProtocMutex     = 5;  // an experiment to insert a mutex into the protoc generated msg struct (bad idea?)
        bool                  mutexFound        = 6;  // true if the mutex was added to the protoc pb.go file
        repeated string       sort              = 7;  // keys to sort on
        repeated string       unique            = 8;  // if the fields should have AppendUnique() functions
        repeated MsgVar       vars              = 9;  // store all the vars in the message
        bool                  needIter          = 10; // true if the sort iterator has not been generated yet
        bool                  needAll           = 11; // true if the sort iterator has not been generated yet
        bool                  noMutex           = 12; // only use the global mutex
        bool                  doGui             = 13; // if a gui.pb.go file should be created
        string                guiVarName        = 14; // the name of the variable to use
        MsgName               localMsgs         = 15; // messages can define other local only messages
}

message Sort {
        string                msgName           = 1;  // `autogenpb:unique` File
        string                varType           = 2;  // `autogenpb:unique` MsgName
        string                varName           = 3;  // `autogenpb:unique` msgNames, sortNames
        string                lockname          = 4;  //
        bool                  needAll           = 5;  //
}
// used to auto-format protobuf files
message FormatMsg {
        enum Type {
                MESSAGE          = 0;
                ENUM             = 1;
                ONEOF            = 2;
                VAR              = 3;
        }

        int64                 depth             = 1;  // used to indent output
        int64                 maxVarname        = 2;  // max string length of var names
        int64                 maxVartype        = 3;  // max string length of var types
        string                header            = 4;  // the 'message {','enum {', etc line
        repeated string       notes             = 5;  // unknown lines or comments
        repeated FormatMsg    msgs              = 6;  // locally defined messages and enums
        repeated string       lines             = 7;  // the variables
        string                footer            = 8;  // the '}' line
        Type                  type              = 9;  // yep. type. yep. that's what this is for
        bool                  padAfter          = 10;
        bool                  isEmpty           = 11; // true when things like: message blah {}
}
message Find {
        string                parent            = 1;  // `autogenpb:unique` File
        string                varType           = 2;  // `autogenpb:unique` MsgName
        string                varName           = 3;  // `autogenpb:unique` msgNames, sortNames
        bool                  needAll           = 4;  //
}

message File {                                        // `autogenpb:var:w io.Writer`
        string                Package           = 1;  // whatever the package name is at the top of the .go file
        string                filename          = 2;  // yellow.proto
        string                pbfilename        = 3;  // yellow.pb.go
        string                filebase          = 4;  // yellow
        string                uuid              = 5;  // the uuid to use in a func NewMsgName()
        string                version           = 6;  // the version to use in a func NewMsgName()
        MsgName               bases             = 7;  // the message in "plural" form
        MsgName               base              = 8;  // the primary repeated message for the master struct

                                                      // every struct in this proto file, this file has: "Apple", "Apples", ... "File", etc...
        repeated MsgName      msgNames          = 9;
        repeated MsgName      sortNames         = 10; // variables that are repeated can have the standard functions generated (Sort(), etc)
        map<string, string>   iterMap           = 11;
        repeated Sort         toSort            = 12; // variables that are repeated can have the standard functions generated (Sort(), etc)
        string                goPath            = 13; // the version to use in a func NewMsgName()
        bool                  doGui             = 14; // if a gui.pb.go file should be created
}
// 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:6c9ae4dd-648d-4b51-9738-bd59fb8fafd5`
        string                version           = 2;  // `autogenpb:version:v0.0.38`
        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;  //
        string                version           = 2;  //
}
// footer was empty