{"id":23191931,"url":"https://github.com/markwinter/unpacket","last_synced_at":"2025-08-18T19:32:35.628Z","repository":{"id":259135131,"uuid":"876406720","full_name":"markwinter/unpacket","owner":"markwinter","description":"Golang struct tags to pack and unpack bytes to structs","archived":false,"fork":false,"pushed_at":"2024-10-30T21:12:35.000Z","size":9,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-06T20:24:35.708Z","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/markwinter.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":"2024-10-21T23:14:13.000Z","updated_at":"2024-11-19T10:17:50.000Z","dependencies_parsed_at":"2024-12-18T12:21:26.138Z","dependency_job_id":"95641c83-d321-4920-8797-658c3ecfa6b0","html_url":"https://github.com/markwinter/unpacket","commit_stats":null,"previous_names":["markwinter/unpacket"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markwinter/unpacket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwinter%2Funpacket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwinter%2Funpacket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwinter%2Funpacket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwinter%2Funpacket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markwinter","download_url":"https://codeload.github.com/markwinter/unpacket/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwinter%2Funpacket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271049279,"owners_count":24691013,"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-08-18T02:00:08.743Z","response_time":89,"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":[],"created_at":"2024-12-18T12:19:27.606Z","updated_at":"2025-08-18T19:32:35.322Z","avatar_url":"https://github.com/markwinter.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unpacket\n\n`Unpacket` provides functionality to unpack and pack byte slices into structs using an `unpacket` struct tag. This was mostly written to simplify\nnetwork protocol parsing e.g. https://github.com/markwinter/go-finproto\n\nThis currently only supports fixed-size packets/fields. Support for the final field to be variable length is incoming.\n\n## Features\n\n- Parse a byte array into a struct.\n- Ability to pack a struct back into a byte array.\n\n## Installation\n\nTo use `Unpacket`\n\n```bash\ngo get github.com/markwinter/unpacket\n```\n\n## Usage\n\nAdd an `unpack` struct tag to your struct fields with `offset` and `length` tag fields.\n\nThe supported fields are variants of `int` `uint` `bool` `time.Duration` `string`\n\n### Unpack a byte slice\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n    \n\t\"github.com/markwinter/unpacket\"\n)\n\ntype EventCode uint8\n\ntype SystemEvent struct {\n\tTimestamp      time.Duration `unpack:\"offset=5,length=6\"`\n\tStockLocate    uint16        `unpack:\"offset=1,length=2\"`\n\tTrackingNumber uint16        `unpack:\"offset=3,length=2\"`\n\tEventCode      EventCode     `unpack:\"offset=11,length=1\"`\n}\n\nfunc main() {\n    data := []byte{83,0,0,0,0,0,162,215,245,12,16,83}\n    \n    systemEvent := \u0026SystemEvent{}\n    err := unpacket.Unpack(data, binary.BigEndian, systemEvent)\n    if err != nil {\n        log.Fatalf(\"failed unpacking data: %w\", err)\n    }\n    \n    fmt.Printf(\"%+v\", systemEvent)\n    // \u0026{Timestamp:11m39.4078628s StockLocate:0 TrackingNumber:0 EventCode:83}\n}\n```\n\n### Pack a struct into a byte slice \n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n    \n\t\"github.com/markwinter/unpacket\"\n)\n\ntype EventCode uint8\n\ntype SystemEvent struct {\n\tTimestamp      time.Duration `unpack:\"offset=5,length=6\"`\n\tStockLocate    uint16        `unpack:\"offset=1,length=2\"`\n\tTrackingNumber uint16        `unpack:\"offset=3,length=2\"`\n\tEventCode      EventCode     `unpack:\"offset=11,length=1\"`\n}\n\nfunc main() {\n    systemEvent := \u0026SystemEvent{\n        // ...   \n    }\n\n    data, err := unpacket.Pack(binary.BigEndian, systemEvent)\n    if err != nil {\n        log.Fatalf(\"failed packing data: %w\", err)\n    }\n    \n    fmt.Printf(\"%+v\", data)\n    // [0 0 0 0 0 0 162 215 245 12 16 83]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkwinter%2Funpacket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkwinter%2Funpacket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkwinter%2Funpacket/lists"}