protols/sample/simple.proto
2025-03-19 01:03:04 +05:30

73 lines
1.7 KiB
Protocol Buffer

syntax = "proto3";
package com.book;
import "google/protobuf/any.proto";
// This is a book represeted by some comments that we like to address in the
// review
message Book {
// This is a multi line comment on the field name
// Of a message called Book
int64 isbn = 1;
string title = 2;
Author author = 3;
google.protobuf.Any data = 4;
BookState state = 5;
// # Author is a author of a book
// Usage is as follow:
// ```rust
// println!("hello world")
// ```
message Author {
string name = 1;
int64 age = 2;
}
enum BookState {
UNSPECIFIED = 0;
HARD_COVER = 1;
SOFT_COVER = 2;
}
}
// This is a comment on message
message GetBookRequest {
// This is a sigle line comment on the field of a message
int64 isbn = 1;
}
message GotoBookRequest { bool flag = 1; }
message GetBookViaAuthor { Book.Author author = 1; }
// It is a BookService Implementation
service BookService {
// This is GetBook RPC that takes a book request
// and returns a Book, simple and sweet
rpc GetBook(GetBookRequest) returns (Book) {}
rpc GetBookAuthor(GetBookRequest) returns (Book.Author) {}
rpc GetBooksViaAuthor(GetBookViaAuthor) returns (stream Book) {}
rpc GetGreatestBook(stream GetBookRequest) returns (Book) {}
rpc GetBooks(stream GetBookRequest) returns (stream Book) {}
}
message BookStore {
reserved 1;
Book book = 5;
string name = 2;
map<int64, string> books = 3;
EnumSample sample = 4;
}
// These are enum options representing some operation in the proto
// these are meant to be ony called from one place,
// Note: Please set only to started or running
enum EnumSample {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}