{"id":15292754,"url":"https://github.com/stalomeow/protocmd","last_synced_at":"2025-10-07T04:32:49.792Z","repository":{"id":210186591,"uuid":"724924167","full_name":"stalomeow/protocmd","owner":"stalomeow","description":"Deprecated. Use protolinker instead.","archived":true,"fork":false,"pushed_at":"2023-12-01T08:12:00.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-23T00:31:57.925Z","etag":null,"topics":["golang","protobuf","unity"],"latest_commit_sha":null,"homepage":"","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/stalomeow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-29T04:12:55.000Z","updated_at":"2024-02-04T11:13:22.000Z","dependencies_parsed_at":"2023-12-01T09:27:37.993Z","dependency_job_id":"cb10476a-0ecc-45a0-90f8-d3ccc614ed05","html_url":"https://github.com/stalomeow/protocmd","commit_stats":null,"previous_names":["stalomeow/protocmd"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stalomeow/protocmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalomeow%2Fprotocmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalomeow%2Fprotocmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalomeow%2Fprotocmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalomeow%2Fprotocmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stalomeow","download_url":"https://codeload.github.com/stalomeow/protocmd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalomeow%2Fprotocmd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278722718,"owners_count":26034460,"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-07T02:00:06.786Z","response_time":59,"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":["golang","protobuf","unity"],"created_at":"2024-09-30T16:26:31.936Z","updated_at":"2025-10-07T04:32:49.525Z","avatar_url":"https://github.com/stalomeow.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protocmd\n\nThis project provides an easy way to manage a mapping between uint16 ids (CmdId/MsgId) and protobuf Messages, primarily used for encoding and decoding binary network packets. Currently, it supports Go and Unity (C#).\n\nThis project is comprised of two components:\n\n- Runtime library for Go: This provides the ability to create a protobuf Message using a predefined uint16 id.\n\n- Code generator: The `protoc-gen-cmd` tool is a compiler plugin to protoc, the protocol buffer compiler. It generates code that maps ids to messages and vice versa.\n\nThe runtime library for Unity is [github.com/stalomeow/Protobuf-Unity](https://github.com/stalomeow/Protobuf-Unity).\n\n## Code Generation\n\n### Installation\n\n```\ngo install github.com/stalomeow/protocmd/protoc-gen-cmd@latest\n```\n\n### Configuration\n\nCreate a YAML file to configure the mapping between messages and ids.\n\n``` yaml\n# format:\n# message-full-name: uint16-cmd-id\n\n# First Group\nprotocmd.examples.TestReq: 1010\nprotocmd.examples.TestRsp: 1011\n\n# Second Group\nprotocmd.examples.TestRsp.TransformInfo: 2010\n# protocmd.examples.Vector3: 2055\n```\n\n### Generate Go code\n\nOptions:\n\n- `lang`: Output language. Must be `go` here.\n- `config`: The configuration file name. The default value is `cmd.yaml`.\n- Options used by `protoc-gen-go` are also supported.\n\nExample:\n\n```\nprotoc --cmd_out=go --cmd_opt=lang=go,module=github.com/stalomeow/protocmd/examples/go protos/*.proto -I=protos\n```\n\n### Generate C# code\n\nOptions:\n\n- `lang`: Output language. Must be `csharp` here.\n- `config`: The configuration file name. The default value is `cmd.yaml`.\n- [`base_namespace`](https://protobuf.dev/reference/csharp/csharp-generated/#compiler_options): When this option is specified, the generator creates a directory hierarchy for generated source code corresponding to the namespaces of the generated classes, using the value of the option to indicate which part of the namespace should be considered as the \"base\" for the output directory.\n- `msg_helpers_name`: The name of a generated class (`msg_helpers`) holding all messages that have cmdIds. The default value is `MessageHelpers`.\n- `msg_helpers_ns`: The namespace of `msg_helpers`. If `base_namespace` is specified, the default value is `base_namespace`; otherwise, it is empty.\n\nExample:\n\n```\nprotoc --cmd_out=unity --cmd_opt=lang=csharp,base_namespace=Examples.CSharp protos/*.proto -I=protos\n```\n\n## Runtime Usage\n\n[Examples](/examples/)\n\n### Go\n\n```\ngo get github.com/stalomeow/protocmd/protoc-gen-cmd\n```\n\n``` go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/stalomeow/protocmd\"\n    \"github.com/stalomeow/protocmd/examples/go/protos\" // load all generated protos\n    \"google.golang.org/protobuf/proto\"\n)\n\nfunc main() {\n    cmdId := protos.TestReq_CmdId\n\n    buf, err := proto.Marshal(\u0026protos.TestReq{Uid: \"123321\"})\n    if err != nil {\n        fmt.Printf(\"Error %v\", err)\n        return\n    }\n\n    // Create message by cmdId\n    msg, err := protocmd.NewMessageByCmdId(cmdId)\n    if err != nil {\n        fmt.Printf(\"Error %v\", err)\n        return\n    }\n    err = proto.Unmarshal(buf, msg)\n    if err != nil {\n        fmt.Printf(\"Error %v\", err)\n        return\n    }\n\n    // Get cmdId and name\n    fmt.Printf(\"Cmd (id: %v, name: %s)\\n\", msg.CmdId(), msg.CmdName())\n    fmt.Println(msg.(*protos.TestReq))\n}\n```\n\n### Unity\n\nImport [github.com/stalomeow/Protobuf-Unity](https://github.com/stalomeow/Protobuf-Unity) package.\n\n``` c#\nusing Examples.CSharp.Protos;\nusing Examples.CSharp;\nusing Google.Protobuf;\nusing UnityEngine;\n\npublic class Example : MonoBehaviour\n{\n    public static MessageHelpers Helpers = new();\n\n    private void Start()\n    {\n        byte[] bytes = new TestReq() { Uid = \"123321\" }.ToByteArray();\n\n        // Create message by cmdId\n        MessageParser parser = Helpers.GetMessageParserByCmdId(TestReq.CmdId);\n        ICmdMessage msg = parser.ParseFrom(bytes) as ICmdMessage;\n\n        // Get cmdId and name\n        print(msg.CmdId);\n        print(msg.CmdName);\n        print((TestReq)msg);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalomeow%2Fprotocmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstalomeow%2Fprotocmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalomeow%2Fprotocmd/lists"}