Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trpc-ecosystem/go-fbs
https://github.com/trpc-ecosystem/go-fbs
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/trpc-ecosystem/go-fbs
- Owner: trpc-ecosystem
- License: other
- Created: 2023-08-17T04:07:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-24T11:58:07.000Z (about 1 year ago)
- Last Synced: 2024-09-29T06:47:58.909Z (3 months ago)
- Language: Go
- Size: 99.6 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
English | [中文](README.zh_CN.md)
# fbs
A parser for flatbuffers in Go.
## Getting Started
1. Import `package fbs`:
```go
import "trpc.group/trpc-go/fbs"
```2. Pass in the flatbuffers file list you want to parse. Create a `Parser` and call `ParseFiles`.
```go
filenames := []string{
"./file1.fbs", // Pass in a list of flatbuffers files.
"./file2.fbs",
}
p := fbs.NewParser()
fds, err := p.ParseFiles(filenames...)
fd1 := fds[0] // The parsed result(descriptor) of file1.fbs
fd2 := fds[1] // The parsed result(descriptor) of file2.fbs
```You can access the resulting descriptors from `fbs` and get rich information about every method definition of rpc
services, e.g. method names, input/output type, client/server streaming, etc.The descriptor `SchemaDesc` for every file has the following fields:
```go
// SchemaDesc describes a complete .fbs file.
type SchemaDesc struct {
// Schema stores the root node of the AST.
Schema *ast.SchemaNode
// Name stores the .fbs file name.
Name string
// Namespace of schema will change in the course of processing each decl, these will be stored
// in this slice. Decls of table/struct/enum/union will set their own namespaces to be the last
// namespace in this slice.
// See parseResult.createSchemaDescriptor.
Namespaces []string
// Root stores root_type declaration in flatbuffers file.
Root string
// FileExt stores file_extension declaration in flatbuffers file.
FileExt string
// FileIdent stores file_identifier declaration in flatbuffers file.
FileIdent string
// Attrs stores attributes definitions in flatbuffers file.
Attrs []string
// Includes stores all included file names.
Includes []string
// Dependencies stores all descriptors corresponding to included files.
Dependencies []*SchemaDesc
// Tables stores all table descriptors.
Tables []*TableDesc
// Structs stores all struct descriptors.
Structs []*StructDesc
// Enums stores all enum descriptors.
Enums []*EnumDesc
// Unions stores all union descriptors.
Unions []*UnionDesc
// RPCs stores all rpc service descriptors.
RPCs []*RPCDesc
}
```Through accessing these fields such as `RPCs`, you can get information defined in flatbuffers to get related
work done(e.g. generate stub files for rpc services).## Project Structure
```
.
├── desc.go # Definitions of descriptors for all kinds of node.
├── desc_test.go
├── doc.go
├── docs # Documents of implementation.
├── errors.go # Error handling.
├── errors_test.go
├── fbsfiles # Places .fbs for testing.
├── fbs.y # Hand-written according to the grammar of flatbuffers.
├── fbs.y.go # Generated by fbs.y, used to parse token stream to AST.
├── go.mod
├── go.sum
├── internal
│ └── ast # Stores definitions and constructions of nodes in AST.
├── lexer.go # lexer implementation.
├── lexer_test.go
├── linker.go # linker implementation.
├── linker_test.go
├── parse_result.go # Definition for parsed result.
├── parser.go # parser implementation.
├── parser_test.go
├── reader.go # reader implementation.
├── README.md
└── scope.go # scope implementation.
```Further information see [implementation details](/docs/implementation.md)
## Used in Practice
This project enables trpc-go to have flatbuffers support.