{"id":13413797,"url":"https://github.com/glycerine/bambam","last_synced_at":"2025-03-22T18:33:08.081Z","repository":{"id":20861660,"uuid":"24148492","full_name":"glycerine/bambam","owner":"glycerine","description":"auto-generate capnproto schema from your golang source files. Depends on go-capnproto-1.0 at https://github.com/glycerine/go-capnproto","archived":false,"fork":false,"pushed_at":"2016-10-07T18:28:00.000Z","size":132,"stargazers_count":65,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T13:51:24.376Z","etag":null,"topics":[],"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/glycerine.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}},"created_at":"2014-09-17T14:39:12.000Z","updated_at":"2024-02-27T07:49:29.000Z","dependencies_parsed_at":"2022-08-21T07:40:19.232Z","dependency_job_id":null,"html_url":"https://github.com/glycerine/bambam","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glycerine%2Fbambam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glycerine%2Fbambam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glycerine%2Fbambam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glycerine%2Fbambam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glycerine","download_url":"https://codeload.github.com/glycerine/bambam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245003167,"owners_count":20545575,"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-07-30T20:01:49.553Z","updated_at":"2025-03-22T18:33:07.742Z","avatar_url":"https://github.com/glycerine.png","language":"Go","readme":"bambam: auto-generate capnproto schema from your golang source files.\n======\n\nAdding [capnproto serialization](https://github.com/glycerine/go-capnproto) to an existing Go project used to mean writing a lot of boilerplate.\n\nNot anymore.\n\nGiven a set of golang (Go) source files, bambam will generate a [capnproto](http://kentonv.github.io/capnproto/) schema. Even better: bambam will also generate translation functions to readily convert between your golang structs and the new capnproto structs.\n\nprereqs\n-------\n\nYou'll need a recent (up-to-date) version of go-capnproto. If you installed go-capnproto before, you'll want to update it [\u003e= f9f239fc7f5ad9611cf4e88b10080a4b47c3951d  / 16 Nov 2014].\n\n[Capnproto](http://kentonv.github.io/capnproto/) and [go-capnproto](https://github.com/glycerine/go-capnproto) should both be installed and on your PATH.\n\nto install: *run make*. This lets us record the git commit in LASTGITCOMMITHASH to provide accurate version info. Otherwise you'll get an 'undefined: LASTGITCOMMITHASH' failure.\n--------\n~~~\n# be sure go-capnproto and capnpc are installed first.\n\n$ go get -t github.com/glycerine/bambam  # the -t pulls in the test dependencies.\n\n# ignore the initial compile error about 'undefined: LASTGITCOMMITHASH'. `make` will fix that.\n$ cd $GOPATH/src/github.com/glycerine/bambam\n$ make  # runs tests, build if all successful\n$ go install\n~~~\n\n\nuse\n---------\n\n~~~\nuse: bambam -o outdir -p package myGoSourceFile.go myGoSourceFile2.go ...\n     # Bambam makes it easy to use Capnproto serialization[1] from Go.\n     # Bambam reads .go files and writes a .capnp schema and Go bindings.\n     # options:\n     #   -o=\"odir\" specifies the directory to write to (created if need be).\n     #   -p=\"main\" specifies the package header to write (e.g. main, mypkg).\n     #   -X exports private fields of Go structs. Default only maps public fields.\n     #   -version   shows build version with git commit hash\n     #   -OVERWRITE modify .go files in-place, adding capid tags (write to -o dir by default).\n     # required: at least one .go source file for struct definitions. Must be last, after options.\n     #\n     # [1] https://github.com/glycerine/go-capnproto \n~~~\n\ndemo\n-----\n\nSee rw.go.txt. To see all the files compiled together in one project: (a) comment out the defer in the rw_test.go file; (b) run `go test`; (c) then `cd testdir_*` and look at the sample project files there. (d). run `go build` in the testdir_ to rebuild the binary. Notice that you will need all three .go files to successfully build. The two .capnp files should be kept so you can read your data from any capnp-supported language. Here's what is what in that example directory:\n\n~~~\nrw.go             # your original go source file (in this test)\ntranslateCapn.go  # generated by bambam after reading rw.go\nschema.capnp      # generated by bambam after reading rw.go\nschema.capnp.go   # generated by `capnpc -ogo schema.capnp` \u003c- you have to do this yourself or in your Makefile.\ngo.capnp          # always necessary boilerplate to let capnpc work, just copy it from bambam/go.capnp to your build dir.\n~~~\n\nexample:\n\n~~~\njaten@c03:~/go/src/github.com/glycerine/bambam:master$ cd testdir_884497362/\njaten@c03:~/go/src/github.com/glycerine/bambam/testdir_884497362:master$ go build\njaten@c03:~/go/src/github.com/glycerine/bambam/testdir_884497362:master$ ls\ngo.capnp  rw.go  rw.go.txt  schema.capnp  schema.capnp.go  testdir_884497362  translateCapn.go\njaten@c03:~/go/src/github.com/glycerine/bambam/testdir_884497362:master$ ./testdir_884497362\nLoad() data matched Saved() data.\njaten@c03:~/go/src/github.com/glycerine/bambam/testdir_884497362:master$ # run was successful\n~~~\n\nHere is what it looks like to use the Save()/Load() methods. You end up with a Save() and Load() function for each of your structs. Simple.\n\n~~~\npackage main\n\nimport (\n    \"bytes\"\n)\n\n//\n// By default bambam will add the `capid` tags\n// to a copy of your source in the output directory.\n// Use bambam -OVERWRITE to modify files directly in-place.\n// The capid tags control the @0, @1, field numbering \n// in the generated capnproto schema. If you change\n// your go structs, the capid tags let your schema\n// stay backwards compatible with prior serializations.\n//\ntype MyStruct struct {\n\tHello    []string  `capid:\"0\"`\n\tWorld    []int     `capid:\"1\"`\n}\n\nfunc main() {\n\n\trw := MyStruct{\n\t\tHello:    []string{\"one\", \"two\", \"three\"},\n\t\tWorld:    []int{1, 2, 3},\n\t}\n\n    // any io.ReadWriter will work here (os.File, etc)\n\tvar o bytes.Buffer\n\n\trw.Save(\u0026o)\n    // now we have saved!\n\n\n    rw2 := \u0026MyStruct{}\n\trw2.Load(\u0026o)\n    // now we have restored!\n\n}\n\n~~~\n\nwhat Go types does bambam recognize?\n----------------------------------------\n\nSupported: structs, slices, and primitive/scalar types are supported. Structs that contain structs are supported. You have both slices of scalars (e.g. `[]int`) and slices of structs (e.g. `[]MyStruct`) available.\n\nWe handle `[][]T`, but not `[][][]T`, where `T` is a struct or primitive type. The need for triply nested slices is expected to be rare. Interpose a struct after two slices if you need to go deeper.\n\nCurrently unsupported (pull requests welcome): Go maps.  \n\nAlso: pointers to structs to be serialized work, but pointers in the inner-most struct do not. This is not a big limitation, as it is rarely meaningful to pass a pointer value to a different process.\n\n\ncapid tags on go structs\n--------------------------\n\nWhen you run `bambam`, it will generate a modified copy of your go source files in the output directory.\n\nThese new versions include capid tags on all public fields of structs. You should inspect the copy of the source file in the output directory, and then replace your original source with the tagged version.  You can also manually add capid tags to fields, if you need to manually specify a field number (e.g. you are matching an pre-existing capnproto definition).\n\nIf you are feeling especially bold, `bambam -OVERWRITE my.go` will replace my.go with the capid tagged version. For safety, only do this on backed-up and version controlled source files.\n\nBy default only public fields (with a Capital first letter in their name) are tagged. The -X flag ignores the public/private distinction, and tags all fields.\n\nThe capid tags allow the capnproto schema evolution to function properly as you add new fields to structs. If you don't include the capid tags, your serialization code won't be backwards compatible as you change your structs.\n\nDeleting fields from your go structs isn't (currently) particularly well-supported. We could potentially allow fields to be // commented out in the go source and yet still parse the comments and use that parse to keep the schema correct, but that's not a trivial bit of work.\n\nexample of capid annotion use\n~~~\ntype Job struct { \n   C int `capid:\"2\"`  // we added C later, thus it is numbered higher.\n   A int `capid:\"0\"`\n   B int `capid:\"1\"` \n}\n~~~\n\nother tags\n----------\n\nAlso available tags: `capid:\"skip\"` or `capid:\"-1\"` (any negative number): this field will be skipped and not serialized or written to the schema.\n\n~~~\n// capname:\"Counter\"\ntype number struct {\n   A int\n}\n~~~\n\nThe above struct will be mapped into capnproto as:\n\n~~~\nstruct Counter {\n  a @0: Int64;\n}\n~~~\n\nWithout the `// capname:\"Counter\"` comment, you would get:\n\n~~~\nstruct NumberCapn {\n  a @0: Int64;\n}\n~~~\n\nExplanation: Using a `// capname:\"newName\"` comment on the line right before a struct definition will cause `bambam` to use 'newName' as the name for the corresponding struct in the capnproto schema. Otherwise the corresponding struct will simply uppercase the first letter of the orignal Go struct, and append \"Capn\". For example: a Go struct called `number` would induce a parallel generated capnp struct called `NumberCapn`.\n\nwindows build script\n---------------------------\nsee `build.cmd`. Thanks to Klaus Post (http://klauspost.com) for contributing this.\n\n-----\n-----\n\nCopyright (c) 2015, Jason E. Aten, Ph.D.\n\n","funding_links":[],"categories":["Serialization","序列化","安全领域相关库","Relational Databases","\u003cspan id=\"序列化-serialization\"\u003e序列化 Serialization\u003c/span\u003e"],"sub_categories":["HTTP Clients","Advanced Console UIs","HTTP客户端","高級控制台界面","查询语","高级控制台界面","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglycerine%2Fbambam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglycerine%2Fbambam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglycerine%2Fbambam/lists"}