{"id":17964948,"url":"https://github.com/raphexion/gustav","last_synced_at":"2025-09-25T22:35:13.189Z","repository":{"id":57503941,"uuid":"137389933","full_name":"Raphexion/gustav","owner":"Raphexion","description":"Small helper library for and in Erlang","archived":false,"fork":false,"pushed_at":"2019-04-23T17:40:03.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T20:47:19.291Z","etag":null,"topics":["binary-data","erlang","erlang-library","helpers","serialization"],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/Raphexion.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":"2018-06-14T17:41:21.000Z","updated_at":"2019-04-23T17:40:05.000Z","dependencies_parsed_at":"2022-08-28T02:01:12.889Z","dependency_job_id":null,"html_url":"https://github.com/Raphexion/gustav","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raphexion%2Fgustav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raphexion%2Fgustav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raphexion%2Fgustav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raphexion%2Fgustav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Raphexion","download_url":"https://codeload.github.com/Raphexion/gustav/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247069375,"owners_count":20878561,"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-data","erlang","erlang-library","helpers","serialization"],"created_at":"2024-10-29T12:09:38.679Z","updated_at":"2025-09-25T22:35:13.090Z","avatar_url":"https://github.com/Raphexion.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"gustav\n=====\n\n[![Build Status](https://travis-ci.org/Raphexion/gustav.svg?branch=master)](https://travis-ci.org/Raphexion/gustav)\n[![codecov.io](https://codecov.io/gh/Raphexion/gustav/coverage.svg?branch=master)](https://codecov.io/gh/Raphexion/gustav?branch=master)\n\nA helper library for two use-cases:\n\n1. To help pack-up and un-pack data\n2. To help with writing a udp-server\n\nExamples\n--------\n\nImagine that you have a state `#{a =\u003e 1, b =\u003e 2, c =\u003e 3, d =\u003e 4}`.\nYou need to pack-up this data (serialize) and send it over the wire.\nYour protocol specifies that:\n\n| Variable | Bits in payload |\n|----------|-----------------|\n| a        | 8               |\n| b        | 16              |\n| c        | 32              |\n| d        | 8               |\n\nWhich can be described compactly as `[{a, 8}, {b, 16}, {c, 32}, {d, 8}]`.\n\nWhen using *Gustav*, packing up the dictionary into a binary payload:\n\n```\nDictionary = #{a =\u003e 1, b =\u003e 2, c =\u003e 3, d =\u003e 4},\nPacker = packer(Dictionary),\nPayload = Packer([{a, 8}, {b, 16}, {c, 32}, {d, 8}]),\nPayload.\n\u003c\u003c1:8, 2:16, 3:32, 4:8\u003e\u003e\n```\n\nTo unpack the binary payload is similar.\nWe describe the binary protocol `[{a, 8}, {b, 16}, {c, 32}, {d, 8}]`\nand use a unpacker function.\n\nNormally we only want to unpack the data into an empty map `#{}`.\nHowever, in some cases it is convenient to allow some \"other\" data\nin the map (state).\n\nUsing *Gustav*, to unpacking a binary payload into a dictionary:\n\n```\nPayload = \u003c\u003c1:8, 2:16, 3:32, 4:8\u003e\u003e,\nUnPacker = unpacker(#{}, Payload),\nNewDictionary = UnPacker([{a, 8}, {b, 16}, {c, 32}, {d, 8}]),\nNewDictionary.\n#{a =\u003e 1, b =\u003e 2, c =\u003e 3, d =\u003e 4}\n```\n\nOr if you already have some data you want to preserve `#{q =\u003e 42}`:\n\n```\nOrgDictionary = #{q =\u003e 42}  %% q =\u003e 42 is mapping we want to\nPayload = \u003c\u003c1:8, 2:16, 3:32, 4:8\u003e\u003e,\nUnPacker = unpacker(OrgDictionary, Payload),\nNewDictionary = UnPacker([{a, 8}, {b, 16}, {c, 32}, {d, 8}]),\nNewDictionary.\n#{a =\u003e 1, b =\u003e 2, c =\u003e 3, d =\u003e 4, q =\u003e 42}\n```\n\nBuild\n-----\n\n    $ rebar3 compile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphexion%2Fgustav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphexion%2Fgustav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphexion%2Fgustav/lists"}