From 8c139c6328cbdedf042d62c91eb0b63b4aa53c3c Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 7 Jun 2025 08:46:18 +0200 Subject: [PATCH 1/3] docs: updated conventions to hold nested messages and enums --- CONVENTIONS.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index bb6df78..72e53b8 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -1,4 +1,4 @@ -# Naming Conventions +# Conventions This document outlines the required naming conventions for Protocol Buffers (Protobuf) files, messages, services, and folder structures. @@ -17,12 +17,72 @@ message HelloWorld { int64 value_two = 2; } ``` + +> Don't nest messages within messages. + +*Don't* + +```protobuf +message A { + message B { + int64 b = 1; + } + + message C { + int64 c = 1; + } + + B b = 1; + C c = 2; +} +``` + +*Do* + +```protobuf + +message B { + int64 b = 1; +} + +message C { + int64 c = 1; +} + +message A { + B b = 1; + C c = 2; +} +``` +--- + +### Enum + +> [_In proto3, the first value defined in an enum definition must have the value zero and should have the name ENUM_TYPE_NAME_UNSPECIFIED or ENUM_TYPE_NAME_UNKNOWN_](https://protobuf.dev/programming-guides/proto3/#enum-default) + +In our case we just name it `UNKNOWN` + +``` +enum Variant { + UNKNOWN = 0; + PRIMITIVE = 1; + TYPE = 2; + OBJECT = 3; + DATATYPE = 4; + ARRAY = 5; + ERROR = 6; + NODE = 7; +} +``` + +Nesting for Enums is allowed + --- ## Services For service names, use PascalCase for both the service and RPC method names. Each service definition should clearly describe the action it performs. -### Example: +### Example: ```protobuf message PingRequest { @@ -43,7 +103,7 @@ To maintain an organized file structure, each service should have its own folder The file of a service should always contain the service name as its prefix. This is to make it possible to have duplicate file names without a build error! ### Folder Structure Example: -```ascii-tree +```ascii-tree . ├── service_one (folder) │ ├── service_one.file_one.proto (file) @@ -70,4 +130,4 @@ option ruby_package = "Tucana::Shared"; package shared; import "google/protobuf/struct.proto"; -``` \ No newline at end of file +``` From 6fb94bcc79e330f10c915db2fa1fbb4dd0eb9576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20G=C3=B6tz?= <52959657+raphael-goetz@users.noreply.github.com> Date: Sat, 7 Jun 2025 16:26:16 +0200 Subject: [PATCH 2/3] Update CONVENTIONS.md --- CONVENTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 72e53b8..7857452 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -75,7 +75,7 @@ enum Variant { } ``` -Nesting for Enums is allowed +Nesting for Enums is recomended due to Enum value scoping rules. --- ## Services From efe9f9ab06a6c52f8172a20d81c085fdda873391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20G=C3=B6tz?= <52959657+raphael-goetz@users.noreply.github.com> Date: Sat, 7 Jun 2025 16:29:23 +0200 Subject: [PATCH 3/3] Update CONVENTIONS.md Co-authored-by: Niklas van Schrick --- CONVENTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 7857452..84055f4 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -18,7 +18,7 @@ message HelloWorld { } ``` -> Don't nest messages within messages. +Don't nest messages within messages. *Don't*