aboutsummaryrefslogtreecommitdiff
path: root/proto
diff options
context:
space:
mode:
authorAudrius Butkevicius <audrius.butkevicius@gmail.com>2020-10-02 07:07:05 +0100
committerGitHub <noreply@github.com>2020-10-02 08:07:05 +0200
commite027175446e2bba3431bcd3095294531d68f35f8 (patch)
treee926d1bd88642361d7d04100fc49c2147a8fcf5d /proto
parent77749323024d3c7462dd72f4ca7420c1dce40038 (diff)
downloadsyncthing-e027175446e2bba3431bcd3095294531d68f35f8.tar.gz
syncthing-e027175446e2bba3431bcd3095294531d68f35f8.zip
all: Move remaining protos to use the vanity plugin (#7009)
Diffstat (limited to 'proto')
-rw-r--r--proto/ext.proto1
-rw-r--r--proto/ext/ext.pb.go52
-rw-r--r--proto/generate.go5
-rw-r--r--proto/lib/config/blockpullorder.proto4
-rw-r--r--proto/lib/config/foldertype.proto4
-rw-r--r--proto/lib/db/structs.proto89
-rw-r--r--proto/lib/fs/copyrangemethod.proto4
-rw-r--r--proto/lib/fs/types.proto4
-rw-r--r--proto/lib/protocol/bep.proto94
-rw-r--r--proto/scripts/protoc_plugin.go152
10 files changed, 264 insertions, 145 deletions
diff --git a/proto/ext.proto b/proto/ext.proto
index 1b3da600b..73b4ba730 100644
--- a/proto/ext.proto
+++ b/proto/ext.proto
@@ -17,6 +17,7 @@ extend google.protobuf.FieldOptions {
optional bool restart = 75008;
optional bool device_id = 75009;
optional string goname = 75010;
+ optional string gotype = 75011;
}
extend google.protobuf.EnumValueOptions {
diff --git a/proto/ext/ext.pb.go b/proto/ext/ext.pb.go
index 82a6747c6..2e9f4aecc 100644
--- a/proto/ext/ext.pb.go
+++ b/proto/ext/ext.pb.go
@@ -84,6 +84,15 @@ var E_Goname = &proto.ExtensionDesc{
Filename: "ext.proto",
}
+var E_Gotype = &proto.ExtensionDesc{
+ ExtendedType: (*descriptor.FieldOptions)(nil),
+ ExtensionType: (*string)(nil),
+ Field: 75011,
+ Name: "ext.gotype",
+ Tag: "bytes,75011,opt,name=gotype",
+ Filename: "ext.proto",
+}
+
var E_Enumgoname = &proto.ExtensionDesc{
ExtendedType: (*descriptor.EnumValueOptions)(nil),
ExtensionType: (*string)(nil),
@@ -101,31 +110,32 @@ func init() {
proto.RegisterExtension(E_Restart)
proto.RegisterExtension(E_DeviceId)
proto.RegisterExtension(E_Goname)
+ proto.RegisterExtension(E_Gotype)
proto.RegisterExtension(E_Enumgoname)
}
func init() { proto.RegisterFile("ext.proto", fileDescriptor_95fe6908ffcf64d3) }
var fileDescriptor_95fe6908ffcf64d3 = []byte{
- // 305 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0xd1, 0x3d, 0x4b, 0x03, 0x31,
- 0x18, 0xc0, 0x71, 0x8e, 0x16, 0xdb, 0x66, 0xec, 0x24, 0x82, 0xb5, 0x6e, 0x9d, 0xee, 0x10, 0x41,
- 0x31, 0x74, 0x52, 0x14, 0x1c, 0x44, 0x28, 0xe2, 0xe0, 0x52, 0xd2, 0xcb, 0xd3, 0x34, 0x92, 0x97,
- 0x72, 0x49, 0x24, 0x6e, 0xea, 0x37, 0xf0, 0x2b, 0x39, 0x69, 0x27, 0xfd, 0x06, 0xd2, 0xd1, 0xef,
- 0xe0, 0x0b, 0x77, 0x97, 0x93, 0x42, 0x87, 0xdb, 0x42, 0xf8, 0xff, 0x1e, 0x12, 0x1e, 0xd4, 0x01,
- 0x6f, 0xe3, 0x79, 0xa6, 0xad, 0xee, 0x36, 0xc0, 0xdb, 0xad, 0x3e, 0xd3, 0x9a, 0x09, 0x48, 0x8a,
- 0xab, 0x89, 0x9b, 0x26, 0x14, 0x4c, 0x9a, 0xf1, 0xb9, 0xd5, 0x59, 0x99, 0xe1, 0x21, 0x6a, 0x7b,
- 0x29, 0xc6, 0x96, 0x30, 0xd3, 0xdd, 0x89, 0xcb, 0x3c, 0xae, 0xf2, 0xf8, 0x02, 0x8c, 0x21, 0x0c,
- 0x2e, 0xe7, 0x96, 0x6b, 0x65, 0x36, 0x9f, 0x5f, 0x9a, 0xfd, 0x68, 0xd0, 0x1e, 0xb5, 0xbc, 0x14,
- 0x57, 0x84, 0x19, 0xbc, 0x87, 0x1a, 0x5e, 0x8a, 0xee, 0xf6, 0x1a, 0x3c, 0xe3, 0x20, 0x68, 0xc5,
- 0xbe, 0xdf, 0x72, 0xd6, 0x19, 0xe5, 0x2d, 0xde, 0x47, 0xcd, 0x5b, 0xa3, 0x55, 0x9d, 0xf9, 0x09,
- 0xa6, 0x88, 0xf1, 0x11, 0x6a, 0x51, 0x98, 0x12, 0x27, 0x6c, 0x9d, 0xfb, 0x0d, 0xae, 0xea, 0x73,
- 0x9a, 0x81, 0xb1, 0x24, 0xab, 0xa5, 0x0f, 0x8b, 0xf0, 0xbb, 0xd0, 0xe3, 0x21, 0xea, 0x50, 0xb8,
- 0xe3, 0x29, 0x8c, 0x39, 0xad, 0xc3, 0x8f, 0x01, 0xb7, 0x4b, 0x71, 0x4e, 0xf1, 0x21, 0xda, 0x60,
- 0x5a, 0x11, 0x09, 0x75, 0xf4, 0x69, 0x51, 0x3e, 0x39, 0xe4, 0xf8, 0x04, 0x21, 0x50, 0x4e, 0x06,
- 0xbc, 0xbb, 0x86, 0x4f, 0x95, 0x93, 0xd7, 0x44, 0xb8, 0xff, 0xb5, 0x7c, 0x7d, 0x94, 0x03, 0x56,
- 0xd8, 0xf1, 0xc1, 0xeb, 0xb2, 0x17, 0xbd, 0x2f, 0x7b, 0xd1, 0xe7, 0xb2, 0x17, 0xdd, 0x0c, 0x18,
- 0xb7, 0x33, 0x37, 0x89, 0x53, 0x2d, 0x13, 0x73, 0xaf, 0x52, 0x3b, 0xe3, 0x8a, 0xad, 0x9c, 0x8a,
- 0xd9, 0x09, 0x78, 0xfb, 0x17, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x40, 0x4c, 0x73, 0x42, 0x02, 0x00,
- 0x00,
+ // 318 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0xd1, 0xcb, 0x4a, 0x33, 0x31,
+ 0x14, 0xc0, 0x71, 0x86, 0x96, 0xaf, 0x6d, 0x96, 0x5d, 0x7d, 0x08, 0xd6, 0xba, 0xeb, 0x6a, 0x06,
+ 0x11, 0x14, 0x43, 0x57, 0x8a, 0x82, 0x0b, 0x11, 0x8a, 0xb8, 0x70, 0x53, 0xd2, 0x99, 0xd3, 0x34,
+ 0x92, 0xcb, 0x30, 0x39, 0x23, 0xd3, 0x9d, 0x97, 0x27, 0xf0, 0x95, 0x5c, 0x69, 0x57, 0xfa, 0x06,
+ 0xd2, 0xa5, 0xef, 0xe0, 0x85, 0xe9, 0xa4, 0x5a, 0xe8, 0x22, 0xbb, 0x10, 0xfe, 0xbf, 0x93, 0x84,
+ 0x90, 0x16, 0x14, 0x18, 0xa6, 0x99, 0x41, 0xd3, 0xae, 0x41, 0x81, 0x1b, 0x5d, 0x6e, 0x0c, 0x97,
+ 0x10, 0x2d, 0xb6, 0x46, 0xf9, 0x38, 0x4a, 0xc0, 0xc6, 0x99, 0x48, 0xd1, 0x64, 0x55, 0x46, 0xfb,
+ 0xa4, 0x59, 0x28, 0x39, 0x44, 0xc6, 0x6d, 0x7b, 0x2b, 0xac, 0xf2, 0x70, 0x99, 0x87, 0x67, 0x60,
+ 0x2d, 0xe3, 0x70, 0x9e, 0xa2, 0x30, 0xda, 0xfe, 0x7f, 0x7c, 0xaa, 0x77, 0x83, 0x5e, 0x73, 0xd0,
+ 0x28, 0x94, 0xbc, 0x60, 0xdc, 0xd2, 0x1d, 0x52, 0x2b, 0x94, 0x6c, 0x6f, 0xae, 0xc1, 0x13, 0x01,
+ 0x32, 0x59, 0xb2, 0xcf, 0x97, 0x92, 0xb5, 0x06, 0x65, 0x4b, 0x77, 0x49, 0xfd, 0xda, 0x1a, 0xed,
+ 0x33, 0x5f, 0xce, 0x2c, 0x62, 0x7a, 0x40, 0x1a, 0x09, 0x8c, 0x59, 0x2e, 0xd1, 0xe7, 0xbe, 0x9d,
+ 0x5b, 0xf6, 0x25, 0xcd, 0xc0, 0x22, 0xcb, 0xbc, 0xf4, 0x76, 0xe6, 0x5e, 0xe7, 0x7a, 0xda, 0x27,
+ 0xad, 0x04, 0x6e, 0x44, 0x0c, 0x43, 0x91, 0xf8, 0xf0, 0x9d, 0xc3, 0xcd, 0x4a, 0x9c, 0x26, 0x74,
+ 0x9f, 0xfc, 0xe3, 0x46, 0x33, 0x05, 0x3e, 0x7a, 0x3f, 0xab, 0xae, 0xec, 0xf2, 0x0a, 0xe2, 0x34,
+ 0xf5, 0xc2, 0x87, 0x3f, 0x58, 0xe6, 0xf4, 0x88, 0x10, 0xd0, 0xb9, 0x72, 0xa7, 0x6e, 0xaf, 0xe1,
+ 0x63, 0x9d, 0xab, 0x4b, 0x26, 0xf3, 0xdf, 0xff, 0xfc, 0x78, 0xab, 0x06, 0xac, 0xb0, 0xc3, 0xbd,
+ 0xe7, 0x79, 0x27, 0x78, 0x9d, 0x77, 0x82, 0xf7, 0x79, 0x27, 0xb8, 0xea, 0x71, 0x81, 0x93, 0x7c,
+ 0x14, 0xc6, 0x46, 0x45, 0x76, 0xaa, 0x63, 0x9c, 0x08, 0xcd, 0x57, 0x56, 0x8b, 0xd9, 0x11, 0x14,
+ 0xf8, 0x13, 0x00, 0x00, 0xff, 0xff, 0x5a, 0xa4, 0x49, 0x7c, 0x7b, 0x02, 0x00, 0x00,
}
diff --git a/proto/generate.go b/proto/generate.go
index 4cf477dca..6a0e5e1e9 100644
--- a/proto/generate.go
+++ b/proto/generate.go
@@ -25,10 +25,7 @@ import (
// Inception, go generate calls the script itself that then deals with generation.
// This is only done because go:generate does not support wildcards in paths.
-//go:generate go run generate.go lib/config lib/fs
-
-// Use the standard compiler here. We can revisit this later, but we don't plan on exposing this via any APIs.
-//go:generate protoc -I ../ -I . --gogofast_out=paths=source_relative:.. lib/protocol/bep.proto
+//go:generate go run generate.go lib/protocol lib/config lib/fs lib/db
func main() {
for _, path := range os.Args[1:] {
diff --git a/proto/lib/config/blockpullorder.proto b/proto/lib/config/blockpullorder.proto
index 124b54844..a80cb6b4a 100644
--- a/proto/lib/config/blockpullorder.proto
+++ b/proto/lib/config/blockpullorder.proto
@@ -2,7 +2,11 @@ syntax = "proto3";
package config;
+import "repos/protobuf/gogoproto/gogo.proto";
+
enum BlockPullOrder {
+ option (gogoproto.goproto_enum_stringer) = false;
+
BLOCK_PULL_ORDER_STANDARD = 0;
BLOCK_PULL_ORDER_RANDOM = 1;
BLOCK_PULL_ORDER_IN_ORDER = 2;
diff --git a/proto/lib/config/foldertype.proto b/proto/lib/config/foldertype.proto
index 5ab498c31..69ff2a432 100644
--- a/proto/lib/config/foldertype.proto
+++ b/proto/lib/config/foldertype.proto
@@ -2,7 +2,11 @@ syntax = "proto3";
package config;
+import "repos/protobuf/gogoproto/gogo.proto";
+
enum FolderType {
+ option (gogoproto.goproto_enum_stringer) = false;
+
FOLDER_TYPE_SEND_RECEIVE = 0;
FOLDER_TYPE_SEND_ONLY = 1;
FOLDER_TYPE_RECEIVE_ONLY = 2;
diff --git a/proto/lib/db/structs.proto b/proto/lib/db/structs.proto
new file mode 100644
index 000000000..c197d20c9
--- /dev/null
+++ b/proto/lib/db/structs.proto
@@ -0,0 +1,89 @@
+syntax = "proto3";
+
+package db;
+
+import "repos/protobuf/gogoproto/gogo.proto";
+import "lib/protocol/bep.proto";
+import "ext.proto";
+
+message FileVersion {
+ protocol.Vector version = 1;
+ bool deleted = 2;
+ repeated bytes devices = 3;
+ repeated bytes invalid_devices = 4;
+}
+
+message VersionList {
+ option (gogoproto.goproto_stringer) = false;
+ repeated FileVersion versions = 1 [(ext.goname) = "RawVersions"];
+}
+
+// Must be the same as FileInfo but without the blocks field
+message FileInfoTruncated {
+ option (gogoproto.goproto_stringer) = false;
+ string name = 1;
+ int64 size = 3;
+ int64 modified_s = 5;
+ uint64 modified_by = 12 [(ext.gotype) = "github.com/syncthing/syncthing/lib/protocol.ShortID"];
+ protocol.Vector version = 9;
+ int64 sequence = 10;
+ // repeated BlockInfo Blocks = 16
+ string symlink_target = 17;
+ bytes blocks_hash = 18;
+ protocol.FileInfoType type = 2;
+ uint32 permissions = 4;
+ int32 modified_ns = 11;
+ int32 block_size = 13 [(ext.goname) = "RawBlockSize"];
+
+ // see bep.proto
+ uint32 local_flags = 1000;
+ bytes version_hash = 1001;
+
+ bool deleted = 6;
+ bool invalid = 7 [(ext.goname) = "RawInvalid"];
+ bool no_permissions = 8;
+}
+
+// BlockList is the structure used to store block lists
+message BlockList {
+ repeated protocol.BlockInfo blocks = 1;
+}
+
+// IndirectionHashesOnly is used to only unmarshal the indirection hashes
+// from a FileInfo
+message IndirectionHashesOnly {
+ bytes blocks_hash = 18;
+ bytes version_hash = 1001;
+}
+
+// For each folder and device we keep one of these to track the current
+// counts and sequence. We also keep one for the global state of the folder.
+message Counts {
+ option (gogoproto.goproto_stringer) = false;
+
+ int32 files = 1;
+ int32 directories = 2;
+ int32 symlinks = 3;
+ int32 deleted = 4;
+ int64 bytes = 5;
+ int64 sequence = 6; // zero for the global state
+ bytes device_id = 17 [(ext.goname) = "DeviceID"]; // device ID for remote devices, or special values for local/global
+ uint32 local_flags = 18; // the local flag for this count bucket
+}
+
+message CountsSet {
+ repeated Counts counts = 1;
+ int64 created = 2; // unix nanos
+}
+
+message FileVersionDeprecated {
+ protocol.Vector version = 1;
+ bytes device = 2;
+ bool invalid = 3;
+ bool deleted = 4;
+}
+
+message VersionListDeprecated {
+ option (gogoproto.goproto_stringer) = false;
+ repeated FileVersionDeprecated versions = 1;
+}
diff --git a/proto/lib/fs/copyrangemethod.proto b/proto/lib/fs/copyrangemethod.proto
index 5adaed385..a651a1025 100644
--- a/proto/lib/fs/copyrangemethod.proto
+++ b/proto/lib/fs/copyrangemethod.proto
@@ -2,7 +2,11 @@ syntax = "proto3";
package fs;
+import "repos/protobuf/gogoproto/gogo.proto";
+
enum CopyRangeMethod {
+ option (gogoproto.goproto_enum_stringer) = false;
+
COPY_RANGE_METHOD_STANDARD = 0;
COPY_RANGE_METHOD_IOCTL = 1;
COPY_RANGE_METHOD_COPY_FILE_RANGE = 2;
diff --git a/proto/lib/fs/types.proto b/proto/lib/fs/types.proto
index 994ac123f..6f3a5c78d 100644
--- a/proto/lib/fs/types.proto
+++ b/proto/lib/fs/types.proto
@@ -2,7 +2,11 @@ syntax = "proto3";
package fs;
+import "repos/protobuf/gogoproto/gogo.proto";
+
enum FilesystemType {
+ option (gogoproto.goproto_enum_stringer) = false;
+
FILESYSTEM_TYPE_BASIC = 0;
FILESYSTEM_TYPE_FAKE = 1;
}
diff --git a/proto/lib/protocol/bep.proto b/proto/lib/protocol/bep.proto
index f2c222d2c..d470c7d7c 100644
--- a/proto/lib/protocol/bep.proto
+++ b/proto/lib/protocol/bep.proto
@@ -2,17 +2,9 @@ syntax = "proto3";
package protocol;
+import "ext.proto";
import "repos/protobuf/gogoproto/gogo.proto";
-option (gogoproto.goproto_getters_all) = false;
-option (gogoproto.sizer_all) = false;
-option (gogoproto.protosizer_all) = true;
-option (gogoproto.goproto_enum_stringer_all) = true;
-option (gogoproto.goproto_enum_prefix_all) = false;
-option (gogoproto.goproto_unkeyed_all) = false;
-option (gogoproto.goproto_unrecognized_all) = false;
-option (gogoproto.goproto_sizecache_all) = false;
-
// --- Pre-auth ---
message Hello {
@@ -29,19 +21,19 @@ message Header {
}
enum MessageType {
- CLUSTER_CONFIG = 0 [(gogoproto.enumvalue_customname) = "messageTypeClusterConfig"];
- INDEX = 1 [(gogoproto.enumvalue_customname) = "messageTypeIndex"];
- INDEX_UPDATE = 2 [(gogoproto.enumvalue_customname) = "messageTypeIndexUpdate"];
- REQUEST = 3 [(gogoproto.enumvalue_customname) = "messageTypeRequest"];
- RESPONSE = 4 [(gogoproto.enumvalue_customname) = "messageTypeResponse"];
- DOWNLOAD_PROGRESS = 5 [(gogoproto.enumvalue_customname) = "messageTypeDownloadProgress"];
- PING = 6 [(gogoproto.enumvalue_customname) = "messageTypePing"];
- CLOSE = 7 [(gogoproto.enumvalue_customname) = "messageTypeClose"];
+ MESSAGE_TYPE_CLUSTER_CONFIG = 0;
+ MESSAGE_TYPE_INDEX = 1;
+ MESSAGE_TYPE_INDEX_UPDATE = 2;
+ MESSAGE_TYPE_REQUEST = 3;
+ MESSAGE_TYPE_RESPONSE = 4;
+ MESSAGE_TYPE_DOWNLOAD_PROGRESS = 5;
+ MESSAGE_TYPE_PING = 6;
+ MESSAGE_TYPE_CLOSE = 7;
}
enum MessageCompression {
- NONE = 0 [(gogoproto.enumvalue_customname) = "MessageCompressionNone"];
- LZ4 = 1 [(gogoproto.enumvalue_customname) = "MessageCompressionLZ4"];
+ MESSAGE_COMPRESSION_NONE = 0;
+ MESSAGE_COMPRESSION_LZ4 = 1 [(ext.enumgoname) = "MessageCompressionLZ4"];
}
// --- Actual messages ---
@@ -49,11 +41,11 @@ enum MessageCompression {
// Cluster Config
message ClusterConfig {
- repeated Folder folders = 1 [(gogoproto.nullable) = false];
+ repeated Folder folders = 1;
}
message Folder {
- string id = 1 [(gogoproto.customname) = "ID"];
+ string id = 1 [(ext.goname) = "ID"];
string label = 2;
bool read_only = 3;
bool ignore_permissions = 4;
@@ -61,37 +53,37 @@ message Folder {
bool disable_temp_indexes = 6;
bool paused = 7;
- repeated Device devices = 16 [(gogoproto.nullable) = false];
+ repeated Device devices = 16;
}
message Device {
- bytes id = 1 [(gogoproto.customname) = "ID", (gogoproto.customtype) = "DeviceID", (gogoproto.nullable) = false];
+ bytes id = 1 [(ext.goname) = "ID", (ext.device_id) = true];
string name = 2;
repeated string addresses = 3;
Compression compression = 4;
string cert_name = 5;
int64 max_sequence = 6;
bool introducer = 7;
- uint64 index_id = 8 [(gogoproto.customname) = "IndexID", (gogoproto.customtype) = "IndexID", (gogoproto.nullable) = false];
+ uint64 index_id = 8 [(ext.goname) = "IndexID", (ext.gotype) = "IndexID"];
bool skip_introduction_removals = 9;
}
enum Compression {
- METADATA = 0 [(gogoproto.enumvalue_customname) = "CompressMetadata"];
- NEVER = 1 [(gogoproto.enumvalue_customname) = "CompressNever"];
- ALWAYS = 2 [(gogoproto.enumvalue_customname) = "CompressAlways"];
+ COMPRESSION_METADATA = 0;
+ COMPRESSION_NEVER = 1;
+ COMPRESSION_ALWAYS = 2;
}
// Index and Index Update
message Index {
string folder = 1;
- repeated FileInfo files = 2 [(gogoproto.nullable) = false];
+ repeated FileInfo files = 2;
}
message IndexUpdate {
string folder = 1;
- repeated FileInfo files = 2 [(gogoproto.nullable) = false];
+ repeated FileInfo files = 2;
}
message FileInfo {
@@ -103,16 +95,16 @@ message FileInfo {
string name = 1;
int64 size = 3;
int64 modified_s = 5;
- uint64 modified_by = 12 [(gogoproto.customtype) = "ShortID", (gogoproto.nullable) = false];
- Vector version = 9 [(gogoproto.nullable) = false];
+ uint64 modified_by = 12 [(ext.gotype) = "ShortID"];
+ Vector version = 9;
int64 sequence = 10;
- repeated BlockInfo blocks = 16 [(gogoproto.nullable) = false];
+ repeated BlockInfo blocks = 16;
string symlink_target = 17;
bytes blocks_hash = 18;
FileInfoType type = 2;
uint32 permissions = 4;
int32 modified_ns = 11;
- int32 block_size = 13 [(gogoproto.customname) = "RawBlockSize"];
+ int32 block_size = 13 [(ext.goname) = "RawBlockSize"];
// The local_flags fields stores flags that are relevant to the local
// host only. It is not part of the protocol, doesn't get sent or
@@ -124,16 +116,16 @@ message FileInfo {
bytes version_hash = 1001;
bool deleted = 6;
- bool invalid = 7 [(gogoproto.customname) = "RawInvalid"];
+ bool invalid = 7 [(ext.goname) = "RawInvalid"];
bool no_permissions = 8;
}
enum FileInfoType {
- FILE = 0 [(gogoproto.enumvalue_customname) = "FileInfoTypeFile"];
- DIRECTORY = 1 [(gogoproto.enumvalue_customname) = "FileInfoTypeDirectory"];
- SYMLINK_FILE = 2 [(gogoproto.enumvalue_customname) = "FileInfoTypeDeprecatedSymlinkFile", deprecated = true];
- SYMLINK_DIRECTORY = 3 [(gogoproto.enumvalue_customname) = "FileInfoTypeDeprecatedSymlinkDirectory", deprecated = true];
- SYMLINK = 4 [(gogoproto.enumvalue_customname) = "FileInfoTypeSymlink"];
+ FILE_INFO_TYPE_FILE = 0;
+ FILE_INFO_TYPE_DIRECTORY = 1;
+ FILE_INFO_TYPE_SYMLINK_FILE = 2 [deprecated = true];
+ FILE_INFO_TYPE_SYMLINK_DIRECTORY = 3 [deprecated = true];
+ FILE_INFO_TYPE_SYMLINK = 4;
}
message BlockInfo {
@@ -145,18 +137,18 @@ message BlockInfo {
}
message Vector {
- repeated Counter counters = 1 [(gogoproto.nullable) = false];
+ repeated Counter counters = 1;
}
message Counter {
- uint64 id = 1 [(gogoproto.customname) = "ID", (gogoproto.customtype) = "ShortID", (gogoproto.nullable) = false];
+ uint64 id = 1 [(ext.goname) = "ID", (ext.gotype) = "ShortID"];
uint64 value = 2;
}
// Request
message Request {
- int32 id = 1 [(gogoproto.customname) = "ID"];
+ int32 id = 1 [(ext.goname) = "ID"];
string folder = 2;
string name = 3;
int64 offset = 4;
@@ -169,36 +161,36 @@ message Request {
// Response
message Response {
- int32 id = 1 [(gogoproto.customname) = "ID"];
+ int32 id = 1 [(ext.goname) = "ID"];
bytes data = 2;
ErrorCode code = 3;
}
enum ErrorCode {
- NO_ERROR = 0 [(gogoproto.enumvalue_customname) = "ErrorCodeNoError"];
- GENERIC = 1 [(gogoproto.enumvalue_customname) = "ErrorCodeGeneric"];
- NO_SUCH_FILE = 2 [(gogoproto.enumvalue_customname) = "ErrorCodeNoSuchFile"];
- INVALID_FILE = 3 [(gogoproto.enumvalue_customname) = "ErrorCodeInvalidFile"];
+ ERROR_CODE_NO_ERROR = 0;
+ ERROR_CODE_GENERIC = 1;
+ ERROR_CODE_NO_SUCH_FILE = 2;
+ ERROR_CODE_INVALID_FILE = 3;
}
// DownloadProgress
message DownloadProgress {
string folder = 1;
- repeated FileDownloadProgressUpdate updates = 2 [(gogoproto.nullable) = false];
+ repeated FileDownloadProgressUpdate updates = 2;
}
message FileDownloadProgressUpdate {
FileDownloadProgressUpdateType update_type = 1;
string name = 2;
- Vector version = 3 [(gogoproto.nullable) = false];
+ Vector version = 3;
repeated int32 block_indexes = 4 [packed=false];
int32 block_size = 5;
}
enum FileDownloadProgressUpdateType {
- APPEND = 0 [(gogoproto.enumvalue_customname) = "UpdateTypeAppend"];
- FORGET = 1 [(gogoproto.enumvalue_customname) = "UpdateTypeForget"];
+ FILE_DOWNLOAD_PROGRESS_UPDATE_TYPE_APPEND = 0;
+ FILE_DOWNLOAD_PROGRESS_UPDATE_TYPE_FORGET = 1;
}
// Ping
diff --git a/proto/scripts/protoc_plugin.go b/proto/scripts/protoc_plugin.go
index 29565c169..8ede1f24e 100644
--- a/proto/scripts/protoc_plugin.go
+++ b/proto/scripts/protoc_plugin.go
@@ -34,11 +34,11 @@ func main() {
vanity.ForEachFile(files, vanity.TurnOffGoUnrecognizedAll)
vanity.ForEachFile(files, vanity.TurnOffGoUnkeyedAll)
vanity.ForEachFile(files, vanity.TurnOffGoSizecacheAll)
- vanity.ForEachFile(files, vanity.TurnOffGoEnumStringerAll)
+ vanity.ForEachFile(files, vanity.TurnOnMarshalerAll)
+ vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll)
vanity.ForEachEnumInFiles(files, HandleCustomEnumExtensions)
vanity.ForEachFile(files, SetPackagePrefix("github.com/syncthing/syncthing"))
-
- vanity.ForEachMessageInFiles(files, HandleCustomExtensions)
+ vanity.ForEachFile(files, HandleFile)
vanity.ForEachFieldInFilesExcludingExtensions(files, TurnOffNullableForMessages)
resp := command.Generate(req)
@@ -204,88 +204,102 @@ func GetMessageBoolExtension(msg *descriptor.DescriptorProto, extension *proto.E
return *val, true
}
-func HandleCustomExtensions(msg *descriptor.DescriptorProto) {
- generateXmlTags := true
- if generate, ok := GetMessageBoolExtension(msg, ext.E_XmlTags); ok {
- generateXmlTags = generate
- }
-
- vanity.ForEachField([]*descriptor.DescriptorProto{msg}, func(field *descriptor.FieldDescriptorProto) {
- if field.Options == nil {
- field.Options = &descriptor.FieldOptions{}
- }
- deprecated := field.Options.Deprecated != nil && *field.Options.Deprecated == true
+func HandleFile(file *descriptor.FileDescriptorProto) {
+ vanity.ForEachMessageInFiles([]*descriptor.FileDescriptorProto{file}, HandleCustomExtensions(file))
+}
- if field.Type != nil && *field.Type == descriptor.FieldDescriptorProto_TYPE_INT32 {
- SetStringFieldOption(field, gogoproto.E_Casttype, "int")
+func HandleCustomExtensions(file *descriptor.FileDescriptorProto) func(msg *descriptor.DescriptorProto) {
+ return func(msg *descriptor.DescriptorProto) {
+ generateXmlTags := true
+ if generate, ok := GetMessageBoolExtension(msg, ext.E_XmlTags); ok {
+ generateXmlTags = generate
}
- if field.TypeName != nil && *field.TypeName == ".google.protobuf.Timestamp" {
- vanity.SetBoolFieldOption(gogoproto.E_Stdtime, true)(field)
- }
+ vanity.ForEachField([]*descriptor.DescriptorProto{msg}, func(field *descriptor.FieldDescriptorProto) {
+ if field.Options == nil {
+ field.Options = &descriptor.FieldOptions{}
+ }
+ deprecated := field.Options.Deprecated != nil && *field.Options.Deprecated == true
- if goName, ok := GetFieldStringExtension(field, ext.E_Goname); ok {
- SetStringFieldOption(field, gogoproto.E_Customname, goName)
- } else if deprecated {
- SetStringFieldOption(field, gogoproto.E_Customname, "Deprecated"+toCamelCase(*field.Name, true))
- }
+ if field.Type != nil && *field.Type == descriptor.FieldDescriptorProto_TYPE_INT32 {
+ SetStringFieldOption(field, gogoproto.E_Casttype, "int")
+ }
- if val, ok := GetFieldBooleanExtension(field, ext.E_DeviceId); ok && val {
- SetStringFieldOption(field, gogoproto.E_Customtype, "github.com/syncthing/syncthing/lib/protocol.DeviceID")
- }
+ if field.TypeName != nil && *field.TypeName == ".google.protobuf.Timestamp" {
+ vanity.SetBoolFieldOption(gogoproto.E_Stdtime, true)(field)
+ }
- if jsonValue, ok := GetFieldStringExtension(field, ext.E_Json); ok {
- SetStringFieldOption(field, gogoproto.E_Jsontag, jsonValue)
- } else if deprecated {
- SetStringFieldOption(field, gogoproto.E_Jsontag, "-")
- } else {
- SetStringFieldOption(field, gogoproto.E_Jsontag, toCamelCase(*field.Name, false))
- }
+ if goName, ok := GetFieldStringExtension(field, ext.E_Goname); ok {
+ SetStringFieldOption(field, gogoproto.E_Customname, goName)
+ } else if deprecated {
+ SetStringFieldOption(field, gogoproto.E_Customname, "Deprecated"+toCamelCase(*field.Name, true))
+ }
- current := ""
- if v, ok := GetFieldStringExtension(field, gogoproto.E_Moretags); ok {
- current = v
- }
+ if goType, ok := GetFieldStringExtension(field, ext.E_Gotype); ok {
+ SetStringFieldOption(field, gogoproto.E_Customtype, goType)
+ }
- if generateXmlTags {
- if len(current) > 0 {
- current += " "
+ if val, ok := GetFieldBooleanExtension(field, ext.E_DeviceId); ok && val {
+ if *file.Options.GoPackage != "github.com/syncthing/syncthing/lib/protocol" {
+ SetStringFieldOption(field, gogoproto.E_Customtype, "github.com/syncthing/syncthing/lib/protocol.DeviceID")
+ } else {
+ SetStringFieldOption(field, gogoproto.E_Customtype, "DeviceID")
+ }
}
- if xmlValue, ok := GetFieldStringExtension(field, ext.E_Xml); ok {
- current += fmt.Sprintf(`xml:"%s"`, xmlValue)
+
+ if jsonValue, ok := GetFieldStringExtension(field, ext.E_Json); ok {
+ SetStringFieldOption(field, gogoproto.E_Jsontag, jsonValue)
+ } else if deprecated {
+ SetStringFieldOption(field, gogoproto.E_Jsontag, "-")
} else {
- xmlValue = toCamelCase(*field.Name, false)
- // XML dictates element name within the collection, not collection name, so trim plural suffix.
- if field.IsRepeated() {
- if strings.HasSuffix(xmlValue, "ses") {
- // addresses -> address
- xmlValue = strings.TrimSuffix(xmlValue, "es")
- } else {
- // devices -> device
- xmlValue = strings.TrimSuffix(xmlValue, "s")
- }
+ SetStringFieldOption(field, gogoproto.E_Jsontag, toCamelCase(*field.Name, false))
+ }
+
+ current := ""
+ if v, ok := GetFieldStringExtension(field, gogoproto.E_Moretags); ok {
+ current = v
+ }
+
+ if generateXmlTags {
+ if len(current) > 0 {
+ current += " "
}
- if deprecated {
- xmlValue += ",omitempty"
+ if xmlValue, ok := GetFieldStringExtension(field, ext.E_Xml); ok {
+ current += fmt.Sprintf(`xml:"%s"`, xmlValue)
+ } else {
+ xmlValue = toCamelCase(*field.Name, false)
+ // XML dictates element name within the collection, not collection name, so trim plural suffix.
+ if field.IsRepeated() {
+ if strings.HasSuffix(xmlValue, "ses") {
+ // addresses -> address
+ xmlValue = strings.TrimSuffix(xmlValue, "es")
+ } else {
+ // devices -> device
+ xmlValue = strings.TrimSuffix(xmlValue, "s")
+ }
+ }
+ if deprecated {
+ xmlValue += ",omitempty"
+ }
+ current += fmt.Sprintf(`xml:"%s"`, xmlValue)
}
- current += fmt.Sprintf(`xml:"%s"`, xmlValue)
}
- }
- if defaultValue, ok := GetFieldStringExtension(field, ext.E_Default); ok {
- if len(current) > 0 {
- current += " "
+ if defaultValue, ok := GetFieldStringExtension(field, ext.E_Default); ok {
+ if len(current) > 0 {
+ current += " "
+ }
+ current += fmt.Sprintf(`default:"%s"`, defaultValue)
}
- current += fmt.Sprintf(`default:"%s"`, defaultValue)
- }
- if restartValue, ok := GetFieldBooleanExtension(field, ext.E_Restart); ok {
- if len(current) > 0 {
- current += " "
+ if restartValue, ok := GetFieldBooleanExtension(field, ext.E_Restart); ok {
+ if len(current) > 0 {
+ current += " "
+ }
+ current += fmt.Sprintf(`restart:"%t"`, restartValue)
}
- current += fmt.Sprintf(`restart:"%t"`, restartValue)
- }
- SetStringFieldOption(field, gogoproto.E_Moretags, current)
- })
+ SetStringFieldOption(field, gogoproto.E_Moretags, current)
+ })
+ }
}