{"id":17033072,"url":"https://github.com/nokute78/go-bit","last_synced_at":"2025-04-12T12:51:11.143Z","repository":{"id":47620784,"uuid":"186947940","full_name":"nokute78/go-bit","owner":"nokute78","description":"A library to read/write bits array like binary.Read/Write.","archived":false,"fork":false,"pushed_at":"2022-08-20T23:49:28.000Z","size":123,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T07:36:15.600Z","etag":null,"topics":["binary","bit","endian","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nokute78.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":"2019-05-16T03:57:11.000Z","updated_at":"2024-04-14T07:34:03.000Z","dependencies_parsed_at":"2022-09-26T19:34:51.902Z","dependency_job_id":null,"html_url":"https://github.com/nokute78/go-bit","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokute78%2Fgo-bit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokute78%2Fgo-bit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokute78%2Fgo-bit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokute78%2Fgo-bit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nokute78","download_url":"https://codeload.github.com/nokute78/go-bit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571348,"owners_count":21126516,"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":["binary","bit","endian","go","golang"],"created_at":"2024-10-14T08:32:16.733Z","updated_at":"2025-04-12T12:51:11.109Z","avatar_url":"https://github.com/nokute78.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-bit\n![Go](https://github.com/nokute78/go-bit/workflows/Go/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nokute78/go-bit)](https://goreportcard.com/report/github.com/nokute78/go-bit)\n[![Go Reference](https://pkg.go.dev/badge/github.com/nokute78/go-bit/v2.svg)](https://pkg.go.dev/github.com/nokute78/go-bit/v2)\n\nA library to read/write bits from a byte slice.\n\n## Installation\n\n```\ngo get -u github.com/nokute78/go-bit/v2\n```\n\n**CAUTION**: `github.com/nokute78/go-bit/pkg/bit/v2` will be deprecated.\nPlease use `github.com/nokute78/go-bit/v2`.\n\n## Usage\n\nThe package supports `binary.Read` like API.\n\nIt is an example to decode TCP header. (Big Endian)\n\n1. Save below code as tcp.go.\n2. `go mod init go-bit-example`\n3. `go mod tidy`\n4. `go run tcp.go`\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"github.com/nokute78/go-bit/v2\"\n)\n\nfunc main() {\n\ttype TcpHeader struct {\n\t\tSrcPort    uint16\n\t\tDstPort    uint16\n\t\tSeqNo      uint32\n\t\tAckNo      uint32\n\t\tHeaderLen  [4]bit.Bit\n\t\tReserved   [3]bit.Bit `bit:\"skip\"`\n\t\tNS         bit.Bit\n\t\tCWR        bit.Bit\n\t\tECE        bit.Bit\n\t\tURG        bit.Bit\n\t\tACK        bit.Bit\n\t\tPSH        bit.Bit\n\t\tRST        bit.Bit\n\t\tSYN        bit.Bit\n\t\tFIN        bit.Bit\n\t\tWinSize    uint16\n\t\tCheckSum   uint16\n\t\tEmePointer uint16\n\t}\n\n\ts := TcpHeader{}\n\n\tbr := bytes.NewReader([]byte{0xd8, 0x65, 0x01, 0xbb, 0x4b, 0xe0, 0x76, 0xcd, 0x48, 0xc8, 0x70, 0x8f, 0x50, 0x10, 0x10,\n\t\t0x18, 0x0e, 0xc1, 0x00, 0x00})\n\n\tif err := bit.Read(br, binary.BigEndian, \u0026s); err != nil {\n\t\tfmt.Printf(\"error:%s\", err)\n\t}\n\n\tfmt.Printf(\"src=%d dst=%d\\n\", s.SrcPort, s.DstPort)\n\tfmt.Printf(\"SeqNo=%d AckNo=%d\\n\", s.SeqNo, s.AckNo)\n\tfmt.Printf(\"HeaderLen(raw)=%v\\n\", s.HeaderLen)\n\tfmt.Printf(\"Ack=%t\\n\", s.ACK)\n}\n```\n\n## Struct Tag\n\nThe package supports struct tags.\n\n|Tag|Description|\n|---|-----------|\n|`` `bit:\"skip\"` ``|Ignore the field. Offset is updated by the size of the field. It is useful for reserved field.|\n|`` `bit:\"-\"` `` |Ignore the field. Offset is not updated.|\n|`` `bit:\"BE\"` ``|Decode the field as big endian. It is useful for mixed endian data.|\n|`` `bit:\"LE\"` ``|Decode the field as little endian. It is useful for mixed endian data.|\n\n## Tool\n* [readbit](v2/cmd/readbit/README.md)\n\n## Document\n\nhttps://pkg.go.dev/github.com/nokute78/go-bit/v2\n\n## Old Document\n\nhttps://godoc.org/github.com/nokute78/go-bit/pkg/bit\n\n## License\n\n[Apache License v2.0](https://www.apache.org/licenses/LICENSE-2.0)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnokute78%2Fgo-bit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnokute78%2Fgo-bit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnokute78%2Fgo-bit/lists"}