{"id":42336764,"url":"https://github.com/alphazero/unum","last_synced_at":"2026-01-27T14:17:40.016Z","repository":{"id":57551888,"uuid":"55437933","full_name":"alphazero/unum","owner":"alphazero","description":"Variable length image integer codec","archived":false,"fork":false,"pushed_at":"2019-07-10T21:55:07.000Z","size":119,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-03T07:24:37.647Z","etag":null,"topics":["encoding","variable-length"],"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/alphazero.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":"2016-04-04T19:13:46.000Z","updated_at":"2022-09-28T21:41:36.000Z","dependencies_parsed_at":"2022-09-26T18:41:38.599Z","dependency_job_id":null,"html_url":"https://github.com/alphazero/unum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alphazero/unum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphazero%2Funum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphazero%2Funum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphazero%2Funum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphazero%2Funum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphazero","download_url":"https://codeload.github.com/alphazero/unum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphazero%2Funum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28814626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["encoding","variable-length"],"created_at":"2026-01-27T14:17:38.889Z","updated_at":"2026-01-27T14:17:40.011Z","avatar_url":"https://github.com/alphazero.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![image](./resources/unum-logo.png)\n\n## about\n\nBased on John Gustafson's **unum** (\"Right Sizing Precision\"), package `unum` provides variable length, tagged value, encoding of numeric values.\n\nThis implementation (as of now) only supports unsigned integers.\n\n## spec\n\n### `general encoding schema`\n\n     byte order:  big-endian\n     tag-bits:    high-order bits of first byte\n     alignment:   byte aligned\n     \n\n-------\n    \n\n#### `UNUM-64`\n\nThe 2-bit tag determines the value-range and physical length of the image:\n\n\n     tag        | bytes | range\n     -----------+-------+------------------------------------------------\n     00         | 1     | uint: (0, 2^6] \n     -----------+-------+------------------------------------------------\n     01         | 2     | uint: (2^6, 2^14] \n     -----------+-------+------------------------------------------------\n     10         | 4     | uint: (2^14, 2^30] \n     -----------+-------+------------------------------------------------\n     11         | 8     | uint: (2^30, 2^62] \n\n**examples**\n\n    uint64 :: 0x3b\n    []byte :: {0x3b}\n\n    uint64 :: 0x3bab\n    []byte :: {0x7b, 0xab}\n\n    uint64 :: 0x32febaab\n    []byte :: {0xb2, 0xfe, 0xba, 0xab}\n\n    uint64 :: 0x197f5d552fe8d5bc\n    []byte :: {0xd9, 0x7f, 0x5d, 0x55, 0x2f, 0xe8, 0xd5, 0xbc}\n\n-------\n\n#### `UNUM-32`\n\nThe 2-bit tag determines the value-range and physical length of the image:\n\n\n     tag        | bytes | range\n     -----------+-------+------------------------------------------------\n     00         | 1     | uint: (0, 2^6] \n     -----------+-------+------------------------------------------------\n     01         | 2     | uint: (2^6, 2^14] \n     -----------+-------+------------------------------------------------\n     10         | 3     | uint: (2^14, 2^22] \n     -----------+-------+------------------------------------------------\n     11         | 4     | uint: (2^22, 2^30] \n\n**examples**\n\n    uint32 :: 0x3b\n    []byte :: {0x3b}\n\n    uint32 :: 0x3bab\n    []byte :: {0x7b, 0xab}\n\n    uint32 :: 0x2a35c4\n    []byte :: {0xaa, 0x35, 0xc4}\n\n    uint32 :: 0x2fe8d5bc\n    []byte :: {0xef, 0xe8, 0xd5, 0xbc}\n\n-------\n    \n#### `UNUM-16`\n\nThe 1-bit tag determines the value-range and physical length of the image:\n\n\n     tag        | bytes | range\n     -----------+-------+------------------------------------------------\n     0          | 1     | uint: (0, 2^7] \n     -----------+-------+------------------------------------------------\n     1          | 2     | uint: (2^7, 2^15] \n\n**examples**\n\n    uint16 :: 0x4b\n    []byte :: {0x4b}\n\n    uint16 :: 0x42fe\n    []byte :: {0xc2, 0xfe}\n\n-------\n\n## usage\n\n**Note**: Examples below use UNUM-64 encoding but the usage pattern is uniformly applicable.\n\n#### `encode`\n\n**using byte array**\n\n\tvar value []uint64 = { .. }         \n    var b []byte = ..           // provided by you\n    \n    // encoding to a byte buffer\n    var offset int\n    for _, v := range values {\n        n, e := unum.EncodeUint(b[offset:], v)\n        if e != nil {\n            /* if e is ErrorBufferOverflow you could resize the buffer here */\n            break\n        }\n        offset += n\n    }\n\n**using io.Writer **\n \n    var w Writer = ..           // provider by you\n    // encoding to a Writer\n\tfor _, v := range values {\n\t\t_, e := unum.WriteUint(w, v)\n\t\tif e != nil {\n\t\t\tlog.Fatalf(\"err - %s - value:%0x\", e.Error(), v)\n\t\t}\n\t}\n\t \n#### `decode`\n\n**using byte array**\n \n    var b []byte = ..           // unum encoded buffer provided by you\n    \n    // decoding from a byte buffer\n    var offset int\n    for {\n        v, n, e := unum.DecodeUint(b[offset:])\n        if e != nil {\n            break \n        }\n        offset += n\n    }\n    \n---\n\n## License \n\n    The MIT License (MIT)\n    \n    Copyright (c) 2016 Joubin Muhammad Houshyar\n    \n    Permission is hereby granted, free of charge, to any person obtaining a copy of\n    this software and associated documentation files (the \"Software\"), to deal in\n    the Software without restriction, including without limitation the rights to\n    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n    the Software, and to permit persons to whom the Software is furnished to do so,\n    subject to the following conditions:\n    \n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n    \n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n    IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphazero%2Funum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphazero%2Funum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphazero%2Funum/lists"}