Skip to content

Commit

Permalink
[Enhancement] Add code style of protobuf and thrift (StarRocks#18052)
Browse files Browse the repository at this point in the history
Add code style of protobuf and thrift.

Signed-off-by: imay <buaa.zhaoc@gmail.com>
  • Loading branch information
imay authored Feb 19, 2023
1 parent cf7e689 commit 5732b1f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@
+ [TPC-H Benchmark](./benchmarking/TPC-H_Benchmarking.md)
+ Developers
+ [Contribute to StarRocks](./developers/How_to_Contribute.md)
+ Code Style Guides
+ [protobuf style guides](./developers/code-style-guides/protobuf-guides.md)
+ [thrift style guides](./developers/code-style-guides/thrift-guides.md)
+ [Use the debuginfo file for debugging](./developers/debuginfo.md)
+ Development Environment
+ [IDE Setup](./developers/development-environment/ide-setup.md)
Expand Down
44 changes: 44 additions & 0 deletions docs/developers/code-style-guides/protobuf-guides.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Rules

## Never use required

As the project involving, any fields may become optional. But if it is defined as required, it can not be removed.

So `required` should not be used.

## Never change the ordinal

To be back compatible, the ordinal of the field SHOULD NOT be changed.

# Naming

## file name

The names of messages are all lowercase, with underscores between words.
Files should end in `.proto`.

```
my_message.proto // Good
mymessage.proto // Bad
my_message.pb // Bad
```

## Message Name

Message names start with a capital letter and have a capital letter for each new word, with no underscores, and with `PB` as postfix: MyMessagePB

```protobuf
message MyMessagePB // Good
message MyMessage // Bad
message My_Message_PB // Bad
message myMessagePB // Bad
```

## field name

The names of messages are all lowercase, with underscores between words.

```
optional int64 my_field = 3; // Good
optional int64 myField = 3; // Bad
```
44 changes: 44 additions & 0 deletions docs/developers/code-style-guides/thrift-guides.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Rules

## Never use required

As the project involving, any fields may become optional. But if it is defined as required, it can not be removed.

So `required` should not be used.

## Never change the ordinal

To be back compatible, the ordinal of the field SHOULD NOT be changed.

# Naming

## file name

The names of messages are all lowercase, with underscores between words.
Files should end in `.thrift`.

```
my_struct.thrift // Good
MyStruct.thrift // Bad
my_struct.proto // Bad
```

## struct name

Struct names start with a capital letter `T` and have a capital letter for each new word, with no underscores: TMyStruct

```
struct TMyStruct; // Good
struct MyStruct; // Bad
struct TMy_Struct; // Bad
struct TmyStruct; // Bad
```

## field name

The names of struct members are all lowercase, with underscores between words.

```
1: optional i64 my_field; // Good
1: optional i64 myField; // Bad
```

0 comments on commit 5732b1f

Please sign in to comment.