{"id":25842754,"url":"https://github.com/nir3x/variantvector","last_synced_at":"2025-03-01T06:31:49.977Z","repository":{"id":218320511,"uuid":"746122853","full_name":"NIR3X/variantvector","owner":"NIR3X","description":"Variant Vector Serialization/Deserialization (Go)","archived":false,"fork":false,"pushed_at":"2024-02-16T04:14:02.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T18:52:06.560Z","etag":null,"topics":["coding","data-decoding","data-deserialization","data-encoding","data-packing","data-serialization","data-unpacking","decoding","deserialization","encoding","go","golang","packing","serialization","unpacking","variant-vector"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NIR3X.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}},"created_at":"2024-01-21T05:44:47.000Z","updated_at":"2024-01-21T08:01:49.000Z","dependencies_parsed_at":"2024-02-12T22:47:31.053Z","dependency_job_id":null,"html_url":"https://github.com/NIR3X/variantvector","commit_stats":null,"previous_names":["nir3x/variantvector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NIR3X%2Fvariantvector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NIR3X%2Fvariantvector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NIR3X%2Fvariantvector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NIR3X%2Fvariantvector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NIR3X","download_url":"https://codeload.github.com/NIR3X/variantvector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241329448,"owners_count":19944982,"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":["coding","data-decoding","data-deserialization","data-encoding","data-packing","data-serialization","data-unpacking","decoding","deserialization","encoding","go","golang","packing","serialization","unpacking","variant-vector"],"created_at":"2025-03-01T06:31:35.530Z","updated_at":"2025-03-01T06:31:49.964Z","avatar_url":"https://github.com/NIR3X.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Variant Vector Serialization/Deserialization (Go)\n\nThis Go implementation provides a mechanism for serializing and deserializing a variant vector (`variantvector.Type`). The variant vector can hold elements of different types, including `uint64`, `string`, and `[]uint8`.\n\n## Serialization (Packing)\n\n### `varsizedIntPack` Function\nEncodes a `uint64` value using a variable-sized integer encoding and appends the encoded bytes to a slice.\n\n### `Pack` Function\nPacks a `variantvector.Type` into a slice of bytes.\n- The size of the variant vector is packed first using `varsizedIntPack`.\n- For each variant in the slice:\n  - The variant index is packed.\n  - Depending on the variant index, the corresponding value is packed (either `uint64`, `string`, or `[]uint8`).\n\n## Deserialization (Unpacking)\n\n### `varsizedIntUnpack` Function\nDecodes a variable-sized integer from a byte slice and updates the offset.\nReturns the decoded value and the updated offset.\n\n### `Unpack` Function\nUnpacks a byte slice into a `variantvector.Type`.\n- Reads the size of the variant vector using `varsizedIntUnpack`.\n- Iterates over the elements in the slice:\n  - Reads the variant index using `varsizedIntUnpack`.\n  - Based on the variant index, reads and adds the corresponding value to the variant vector.\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/NIR3X/variantvector\"\n)\n\nfunc main() {\n\t// Creating a variant vector\n\tv := variantvector.Type{\n\t\tuint64(1),\n\t\t\"Hello\",\n\t\t[]uint8{0x01, 0x02, 0x03},\n\t}\n\n\t// Packing the variant vector\n\tpacked, err := variantvector.Pack(v)\n\tif err != nil {\n\t\tfmt.Println(\"Error packing:\", err)\n\t\treturn\n\t}\n\n\t// Displaying the packed bytes\n\tfmt.Print(\"Packed Bytes: \")\n\tfor _, b := range packed {\n\t\tfmt.Printf(\"%02x \", b)\n\t}\n\tfmt.Println()\n\n\t// Unpacking the bytes\n\tunpacked, err := variantvector.Unpack(packed)\n\tif err != nil {\n\t\tfmt.Println(\"Error unpacking:\", err)\n\t\treturn\n\t}\n\n\t// Displaying the unpacked values\n\tfmt.Println(\"Unpacked Values:\")\n\tfor _, variant := range unpacked {\n\t\tswitch v := variant.(type) {\n\t\tcase uint64:\n\t\t\tfmt.Println(\"uint64:\", v)\n\t\tcase string:\n\t\t\tfmt.Println(\"string:\", v)\n\t\tcase []uint8:\n\t\t\tfmt.Print(\"[]uint8: \")\n\t\t\tfor _, b := range v {\n\t\t\t\tfmt.Printf(\"%02x \", b)\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\t}\n}\n```\n\n## Dependencies\n\n* This code requires the `varsizedint` package for encoding and decoding variable-sized integers.\n\n## Notes\n\n* The `variantvector.Type` is used to represent a variant vector.\n* Error handling is done using the `error` type.\n* Ensure that dependencies are correctly imported for the code to work as intended.\n\n## License\n\n[![GNU AGPLv3 Image](https://www.gnu.org/graphics/agplv3-155x51.png)](https://www.gnu.org/licenses/agpl-3.0.html)\n\nThis program is Free Software: You can use, study share and improve it at your\nwill. Specifically you can redistribute and/or modify it under the terms of the\n[GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) as\npublished by the Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir3x%2Fvariantvector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnir3x%2Fvariantvector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir3x%2Fvariantvector/lists"}