{"id":23159160,"url":"https://github.com/uptutu/bufp","last_synced_at":"2025-04-04T18:42:06.930Z","repository":{"id":110610590,"uuid":"405052706","full_name":"uptutu/bufp","owner":"uptutu","description":"buffer pool lib","archived":false,"fork":false,"pushed_at":"2021-09-14T06:09:49.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-02-10T03:47:54.571Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uptutu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-09-10T11:10:30.000Z","updated_at":"2021-09-14T06:07:02.000Z","dependencies_parsed_at":"2024-06-20T01:39:09.745Z","dependency_job_id":"65be0b61-12ee-4391-a55a-84dec68564df","html_url":"https://github.com/uptutu/bufp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptutu%2Fbufp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptutu%2Fbufp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptutu%2Fbufp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptutu%2Fbufp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uptutu","download_url":"https://codeload.github.com/uptutu/bufp/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234844,"owners_count":20905852,"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-12-17T22:32:19.351Z","updated_at":"2025-04-04T18:42:06.902Z","avatar_url":"https://github.com/uptutu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bufp\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/uptutu/bufp?style=flat-square)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/uptutu/bufp)](https://github.com/uptutu/bufp)\n[![GoDoc](https://godoc.org/github.com/uptutu/bufp?status.svg)](https://pkg.go.dev/github.com/uptutu/bufp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/uptutu/bufp)](https://goreportcard.com/report/github.com/uptutu/bufp)\n[![Unit-Tests](https://github.com/uptutu/bufp/workflows/Unit-Tests/badge.svg)](https://github.com/uptutu/bufp/actions)\n[![Coverage Status](https://coveralls.io/repos/github/uptutu/bufp/badge.svg?branch=master)](https://coveralls.io/github/uptutu/bufp?branch=master)\n\n💪 Useful utils Buffer Pool for decrease Go GC stress.\n\n## Usage\n\nThe principle of this package is based on `sync.Pool`. A layer of `manager` is wrapped around it for buffer size\nmanagement.\n\n### Install\n\n```bash\n$ go get github.com/uptutu/bufp\n```\n\n### Use\n\n#### Manager\n\nThe manager is a `deque` at the Underlying logic , with each node managing a `sync.pool` of one size\n\npackage has a default global manager managing a 1kib Pool node.\n\n```go\npackage main\n\nimport (\n\t\"github.com/uptutu/bufp/manager\"\n\t\"sync\"\n)\n\nfunc main() {\n\t// Initialize pools of different sizes in Kib unit or Mib unit\n\t// Of cares, you don't have to initialize\n\tmanager.InitKibPools(1, 2, 3, 4)\n\tmanager.InitMibPools(1, 2, 3, 4)\n\n\t// get pool of the size you want from this manager\n\t// _, ok := pool.(*sync.Pool); ok == true\n\tsize := manager.DefaultSize1KiB\n\tpool, ok := manager.Get(size)\n\n\t// here is 2 way to Set diff size pool to manager\n\tp := \u0026sync.Pool{New: func() interface{} { return \u0026bufp.Buffer{bs: make([]byte, 0, 1023)} }}\n\tmanager.Set(1023, p)\n\t// if *sync.Pool is nil then manager will accord your size new a Pool.\n\t// this size will trim to 1024\n\tmanager.Set(1023, nil)\n\t// ok == true\n\tpool, ok := manager.Get(1024)\n\n\t// this is a magic func.\n\t// accord your passing on references size and trim it to find a suit size pool in manager to you\n\t// if no suit pool this will return a nil pointer and false flag\n\t// if you try multi times, manager will new this size pool for you\n\tp, ok = manager.RightOne(sizeYouWant)\n\n\t// this func serve you Service Logic in the lambda func\n\tmanager.Serve(len(\"content\"), func(buf *bufp.Buffer) err {\n\t\tbuf.WriteString(\"content\")\n\t\treturn nil\n\t})\n}\n\n```\n\n#### Buffer\n\n```go\nsize := 1024\nbuffer := bufp.NewBuffer(size)\n\n// append\nbuffer.AppebdByte(byte(oneByteUnit))\nbuffer.AppendString(string(s))\nbuffer.AppendInt(int64(10))\nbuffer.AppentTime(time.Now(), \"2021-2-21 15:30:23\")\nbuffer.AppendUint(uint64(10))\nbuffer.AppendBool(false)\nbuffer.AppendFloat(3.1415, 10)\nbuffer.Write([]byte(\"content\"))\nbuffer.WriteByte('c')\nbuffer.WriteString(\"string\")\n\nbuffer.TrimNewline()\n\n// get buffer content\nbuffer.Len()\nbuffer.Cap()\nbuffer.Bytes()\nbuffer.String()\n\n```\n\n### Pool\n\nthis package has a default 1kib size buffer global pool named simplePool.\n\n```go\nsize := 2014\n// New: return *bufp.Buffer\npool := bufp.NewPool(size) // *sync.Pool\n\nsimplePool := bufp.Pool()\n// this buffer default was 1kib size buffer\nbuffer := simplePool.Get()\n// easy way get this default 1kib buffer\nbuffer := Get()\n// easy way put buffer to simplePool\nbufp.Put(buffer)\n\n// you can change the default 1 kib buffer size by this func\nbufp.Set(\u0026sync.Pool{New:func (){return \u0026bufp.Buffer{bs: make([]byte, 0, sizeYouWant)}}})\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptutu%2Fbufp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuptutu%2Fbufp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptutu%2Fbufp/lists"}