{"id":16686988,"url":"https://github.com/paralin/protods","last_synced_at":"2025-07-06T15:08:12.696Z","repository":{"id":152080580,"uuid":"130106314","full_name":"paralin/protods","owner":"paralin","description":"Use any backing datastructure or datastore for complex Protobuf structures.","archived":false,"fork":false,"pushed_at":"2018-04-19T01:42:31.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-19T09:51:21.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/paralin.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":"2018-04-18T18:36:43.000Z","updated_at":"2023-03-16T19:27:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"edab8c4c-93a4-45c2-9ff5-62870656a4ac","html_url":"https://github.com/paralin/protods","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/paralin/protods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Fprotods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Fprotods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Fprotods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Fprotods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paralin","download_url":"https://codeload.github.com/paralin/protods/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Fprotods/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261560130,"owners_count":23177323,"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","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":[],"created_at":"2024-10-12T15:07:27.574Z","updated_at":"2025-07-06T15:08:12.678Z","avatar_url":"https://github.com/paralin.png","language":"Go","readme":"# Protobuf Datastructures\n\n\u003e Use any backing datastructure or datastore for complex Protobuf structures.\n\n## Introduction\n\nAllows developers to represent Protobuf objects with different data-structures. protods:\n\n - Generates interface types for Protobufs including field setters.\n - Declares common interfaces for various types of compatible backing data-structures.\n - Generates struct types binding generated protobuf structures to the backing data-structures.\n\nExamples include:\n\n - Use a ctrie to allow efficient concurrent snapshotting of protobuf objects.\n - Use a key/value store to lazy-load protobufs from storage.\n - Load data from a Redis key/value store on-demand.\n \nNote: this project is in the early development phase.\n \n## Getting Started\n\nTo start getting a feel for how `protods` structures work, let's set up a simple project (under examples/getting-started).\n\nFirst, fetch some dependencies:\n\n```bash\ngo get -v github.com/golang/protobuf/protoc-gen-go\ngo get -v github.com/square/goprotowrap/cmd/protowrap\ngo get -v github.com/paralin/protods/cmd/protods\n```\n\nCreate a protobuf structure:\n\n```proto\n// Hello is a hello message.\nmessage Hello {\n  // Subject is the subject of the Hello message.\n  string subject = 1;\n}\n```\n\nGenerate the go code:\n\n```bash\nprotoc --go_out=. ./getting-started.proto\n```\n\nGenerate the protods code:\n\n```bash\n# Generate setters for all getters, interfaces for all types.\nprotods generate itypes getting-started.proto\n```\n \n## Code Generation Walkthrough\n\nThe \"protods\" tool is used to generate code depending on the desired output.\n\n```proto\nmessage Example {\n   string str_field = 1;\n   double num_field = 2;\n   Example ex_field = 3;\n   map\u003cstring, Example\u003e map_field = 4;\n}\n```\n\nMost modes of operation require generating the proto interface type:\n\n```go\ntype IStringExampleMap interface {\n\tGet(key string) IExample\n    Set(key string, val IExample)\n    ForEach(cb func(key string, val IExample) bool) bool\n}\n\ntype IExample interface {\n   GetStrField() string\n   SetStrField(string)\n   GetNumField() float64\n   SetNumField(float64)\n   GetExField() IExample\n   SetExField(IExample)\n   // NewExField builds a new IObject of the same type as the parent.\n   // For example, the generated New for proto types will return a proto type.\n   NewExField() IExample\n   NewMapField() IStringExampleMap\n   GetMapField() IStringExampleMap\n   // SetMapField sometimes requires a specific map type.\n   // The proto generated types will use the given value if it is a map[]\n   // Otherwise, they will clear the underlying map and copy the values with ForEach.\n   SetMapField(IStringExampleMap)\n}\n```\n\nThe default generated Proto types implement half of the equation, the getters (GetStrField).\n\nTo make the generated Go message types compatible with the generated interfaces, setters are necessary:\n\n```go\nfunc (m *Example) SetStrField(val string) {\n\tif m != nil {\n\t\tm.StrField = val\n\t}\n}\n```\n\nNow, an alternative data-structure might also satisfy `IExample`:\n\n```go\n// KeyValueExample is interchangeable at runtime with the proto object.\n// This is because both implement the IExample type.\ntype KeyValueExample struct {\n\tm map[string]interface{}\n}\n\n// NewKeyValueExample returns a new IExample with a map backing it.\nfunc NewKeyValueExample() IExample {\n\treturn \u0026KeyValueExample{m: make(map[string]interface{})}\n}\n\n// SetStrField sets the string field on the object.\nfunc (m *KeyValueExample) SetStrField(val string) {\n\tif m != nil {\n\t\tm.m[\"str_field\"] = val\n\t}\n}\n\n// GetStrField gets the string field from the object.\nfunc (m *KeyValueExample) GetStrField() string {\n\tif m == nil {\n\t\treturn \"\"\n    }\n\n\tval, ok := m.m[\"str_field\"]\n\tif !ok {\n\t\treturn \"\"\n\t}\n    \n\treturn val.(string)\n}\n```\n\nThese are just examples of the types of structures that can be generated by the `protods` tool.\n\n## Types of Backing Stores\n\nThis section describes the implemented types of backing stores for proto objects.\n\n### Key/Value Store\n\nA key/value store satisfies the following interface:\n\n```go\n// KeyValue contains values for a protobuf in a K/V store.\n// Keys are generated using the field name.\ntype KeyValue interface {\n\t// Set stores the value for the key.\t\n\tSet(key string, value interface{})\n\t// Get returns the value for the key.\n\tGet(key string) (bool, interface{})\n\t// Delete removes the value for the key.\n\tDelete(key string)\n}\n```\n\nGiven a key-value backed object:\n\n```\nmessage Upper {\n\tstring id = 1;\n\tLower lower = 2;\n\tmap\u003cstring, Lower\u003e lower_kv = 3;\n}\n\nmessage Lower {\n\tstring value = 1;\n}\n```\n\nThe generated Key/Value backed code will generate keys like:\n\n - `upper.GetLower().GetValue()` -\u003e `store.Get(\"/lower/value\")`\n - `upper.GetLowerKv().Get(\"test\").GetValue()` -\u003e `store.Get(\"/lower_kv/test/value\")`\n - `upper.GetId()` -\u003e `store.Get(\"/id\")`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparalin%2Fprotods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparalin%2Fprotods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparalin%2Fprotods/lists"}