{"id":19870596,"url":"https://github.com/yycoder/protobuf-thrift","last_synced_at":"2025-10-16T11:03:42.145Z","repository":{"id":46058839,"uuid":"363885350","full_name":"YYCoder/protobuf-thrift","owner":"YYCoder","description":"protobuf  idl to thrift, and vice versa","archived":false,"fork":false,"pushed_at":"2024-02-02T15:08:00.000Z","size":306,"stargazers_count":58,"open_issues_count":1,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T08:46:31.754Z","etag":null,"topics":["ast","code-generation","go","golang","pb-thrift","protobuf","protobuf-thrift","protocol-buffers","thrift"],"latest_commit_sha":null,"homepage":"https://pb-thrift.markeyyuan.monster/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YYCoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-03T09:55:20.000Z","updated_at":"2025-03-20T05:20:27.000Z","dependencies_parsed_at":"2024-06-19T00:21:20.487Z","dependency_job_id":"fabfe53d-e49f-49fc-b483-01d5eb89daa8","html_url":"https://github.com/YYCoder/protobuf-thrift","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/YYCoder/protobuf-thrift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YYCoder%2Fprotobuf-thrift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YYCoder%2Fprotobuf-thrift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YYCoder%2Fprotobuf-thrift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YYCoder%2Fprotobuf-thrift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YYCoder","download_url":"https://codeload.github.com/YYCoder/protobuf-thrift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YYCoder%2Fprotobuf-thrift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279181442,"owners_count":26120961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","code-generation","go","golang","pb-thrift","protobuf","protobuf-thrift","protocol-buffers","thrift"],"created_at":"2024-11-12T16:09:30.205Z","updated_at":"2025-10-16T11:03:42.109Z","avatar_url":"https://github.com/YYCoder.png","language":"Go","readme":"# protobuf-thrift\nLittle cli utility for lazy guy😉 ~ Transforming protobuf idl to thrift, and vice versa.\n\n[![YYCoder](https://circleci.com/gh/YYCoder/protobuf-thrift.svg?style=svg)](https://app.circleci.com/pipelines/github/YYCoder/protobuf-thrift)\n[![GoDoc](https://pkg.go.dev/badge/github.com/YYCoder/protobuf-thrift)](https://pkg.go.dev/github.com/YYCoder/protobuf-thrift)\n[![goreportcard](https://goreportcard.com/badge/github.com/yycoder/protobuf-thrift)](https://goreportcard.com/report/github.com/yycoder/protobuf-thrift)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\u003e [IDL](https://en.wikipedia.org/wiki/IDL)(Interface description language), which is a descriptive language used to define data types and interfaces in a way that is independent of the programming language or operating system/processor platform.\n\n[中文文档](./docs/cn.md)\n\nFeel free to try out our [web interface](https://pb-thrift.markeyyuan.monster/), and of course, both languages specification as below, if there are any questions, don't hesitate to open an issue, and PRs are welcome too.\n\n* [thrift](https://thrift.apache.org/docs/idl.html)\n\n* [protobuf](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec)\n\n## Install\n### Use as a executable\n1. first git clone this repo, `git clone github.com/YYCoder/protobuf-thrift`\n\n2. make, the executable will be compiled to `./exe` folder\n\n### Use as a library\n1. go get this in your go module, `go get github.com/YYCoder/protobuf-thrift`\n\n2. import package from `github.com/YYCoder/protobuf-thrift`\n\n\n## Usages\n\n### Basic Usage\nBasic thrift file to protobuf file transform:\n\n```\nprotobuf-thrift -t thrift2proto -i ./path/to/idl.thrift -o ./idl.proto\n```\n\nBasic protobuf file to thrift file transform:\n\n```\nprotobuf-thrift -t proto2thrift -i ./path/to/idl.proto -o ./idl.thrift\n```\n\n### Interactive Usage\nYou can simply run like `protobuf-thrift -t thrift2proto` and then, paste your original idl file to the terminal and press ctrl+D.\n\n![interactive.gif](./docs/2021-08-09%2021_54_20.gif)\n\n\u003e Note that interactive mode can not use **-r** option, as there is no files, only stdin.\n\n### Case Converting\nProtobuf-thrift provides complete case convert feature, thanks to [strcase](https://github.com/iancoleman/strcase), available options already listed in **--help** message.\n\n### Recursive Transforming\nUnder some circumstances, you may want to transform a whole idl repo to another language, we provide you **-r** option to indicate protobuf-thrift to transform all imported files.\n\nThis option is off by default, so you have to specify it explicitly.\n\n```\nprotobuf-thrift -t thrift2proto -i ./path/to/idl.thrift -o ./idl.proto -r 1\n```\n\n\n## Options\n\n![](./docs/usage.jpeg)\n\n## Notice\n\nSince protobuf and thrift have many different syntaxes, we can only transform syntaxes that have same meaning, e.g. protobuf message =\u003e thrift struct, protobuf enum =\u003e thrift enum.\n\nWe hope you don't have to worry about protobuf-thrift do sth unexpected, so we **strongly recommend you to read the following document** to get a grasp of what it will do for specific syntaxes.\n\n### Basic Types\nHere is a list of basic type conversion rules:\n\n|[protobuf type](https://developers.google.com/protocol-buffers/docs/proto3#scalar)|[thrift type](https://thrift.apache.org/docs/types.html#base-types)|\n|:--:|:--:|\n|uint32|-|\n|uint64|-|\n|sint32|-|\n|sint64|-|\n|fixed32|-|\n|fixed64|-|\n|sfixed32|-|\n|sfixed64|-|\n|-|i16|\n|int32|i32|\n|int64|i64|\n|float|double|\n|double|double|\n|bool|bool|\n|string|string|\n|bytes|-|\n|-|byte|\n\n### Enum\nProtobuf and thrift both have `enum` declaration syntax and basically same grammar, only to note that:\n\n\u003e **Proto3 enum declaration's first element must be zero, so if thrift enum with non-zero first element transform to protobuf, protobut-thrift will automatically generate a zero element for you.**\n\nfor example, if thrift enum like this:\n\n```thrift\nenum Status {\n    StatusUnreviewed = 1 // first non-zero element\n    StatusOnline = 2\n    StatusRejected = 3\n    StatusOffline = 4\n}\n```\n\nwill be transformed to:\n\n```protobuf\nenum Status {\n    Status_Unknown = 0;\n    Status_Unreviewed = 1; // first non-zero element\n    Status_Online = 2;\n    Status_Rejected = 3;\n    Status_Offline = 4;\n}\n```\n\n### Service\nProtobuf and thrift both have same `service` declaration syntax, but there are several differences:\n\n1. **oneway**: only thrift support, which means function will not wait for response. so during thrift-to-pb transformation, this keyword will be ignored.\n\n2. **throws**: only thrift support, which specified what kind of exceptions can be thrown by the function. this keyword will be ignored, too, in thrift-to-pb mode.\n\n3. **arguments**: \n    * thrift supports multiple arguments for one function, but protobuf only supports one, so it will ignore all the arguments other than the first one in thrift-to-pb transformation.\n\n    * thrift functions support `void` return type, but protobuf doesn't, so it will leave the return type blank in thrift-to-pb mode.\n    \n    * currently, only support basic type and identifier for function/rpc request and response type, might be implemented in the future.\n\n### Options || Annotation\nBoth language support this feature, but they have different syntax to apply it, since the meaning for them are language-bound, we decide to ignore this between transformations.\n\n### Message || Struct\nThrift `struct` and protobuf `message` are very similar, but still have some differences:\n\n1. **set type**: only thrift support, it will be transformed to `repeated` field in protobuf just like thrift `list`.\n\n2. **optional**: thrift and proto2 support, it will be ignored in thrift-to-pb mode if protobuf syntax is proto3\n\n3. **required**: thrift and proto2 support, since it's highly not recommend to mark field as `required`, currently it will be ignored, if you have any questions about this, please open an issue.\n\n4. **map type**: as protobuf [language-specification](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#map_field) mentioned, protobuf only support basic type as key type, but thrift support any [FieldType](https://thrift.apache.org/docs/idl.html) as map key type, for simplicity, currently only support basic type and identifier as map key and value\n\n\n### Import || Include\nAs [language-specification](https://developers.google.com/protocol-buffers/docs/proto#importing_definitions) mentioned, protobuf import paths are relative to protoc command's working directory or using -I/--proto_path specified path, and can not include relative paths prefix, such as `./XXX.proto`, we are not able to detect the correct path for current file both in thrift-to-pb mode and pb-to-thrift mode, since it's dynamic.\n\nSo, you have to manually check whether the generated path is correct.\n\n### Constant || Const\nCurrently not supported.\n\n### Package || Namespace\nThrift `namespace` value will be used for protobuf `package`, the NamespaceScope will be ignored in thrift-to-pb mode.\n\nIn pb-to-thrift mode, generated `namespace` will use `*` as NamespaceScope.\n\n### Nested Types\nProtobuf supports [nested types](https://developers.google.com/protocol-buffers/docs/proto#nested) within message, but thrift does not, so protobuf-thrift will prefix nested field name with outer message name to work around this. for example:\n\n```protobuf\nmessage GroupMsgTaskQueryExpress {\n    enum QueryOp {\n        Unknown = 0;\n        GT = 1;\n    }\n    message TimeRange {\n        int32 range_start = 1;\n        int32 range_end = 2;\n    }\n    QueryOp express_op = 1;\n    int32 op_int = 2;\n    TimeRange time_op = 3;\n    int32 next_op_int = 4;\n}\n```\n\nwill transform to:\n\n```thrift\nstruct GroupMsgTaskQueryExpress {\n    1: GroupMsgTaskQueryExpressQueryOp ExpressOp\n    2: i32 OpInt\n    3: GroupMsgTaskQueryExpressTimeRange TimeOp\n    4: i32 NextOpInt\n}\nenum GroupMsgTaskQueryExpressQueryOp {\n    Unknown = 0\n    GT = 1\n}\nstruct GroupMsgTaskQueryExpressTimeRange {\n    1: i32 RangeStart\n    2: i32 RangeEnd\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyycoder%2Fprotobuf-thrift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyycoder%2Fprotobuf-thrift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyycoder%2Fprotobuf-thrift/lists"}