{"id":15288002,"url":"https://github.com/scalpel-software/cbor","last_synced_at":"2025-04-13T05:34:25.212Z","repository":{"id":47090219,"uuid":"198307497","full_name":"scalpel-software/cbor","owner":"scalpel-software","description":"Concise Binary Object Representation (RFC 7049)","archived":false,"fork":false,"pushed_at":"2023-02-14T19:34:55.000Z","size":25,"stargazers_count":25,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-01T15:43:41.125Z","etag":null,"topics":["cbor","decoding","elixir","encoding"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/scalpel-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2019-07-22T21:55:15.000Z","updated_at":"2024-08-21T15:36:24.000Z","dependencies_parsed_at":"2024-06-19T06:18:10.012Z","dependency_job_id":"125e4940-5fe2-4740-89aa-0d7c38c406a7","html_url":"https://github.com/scalpel-software/cbor","commit_stats":{"total_commits":16,"total_committers":4,"mean_commits":4.0,"dds":0.1875,"last_synced_commit":"753b6e516d68f56e856490bfcd840a317f9786bd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalpel-software%2Fcbor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalpel-software%2Fcbor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalpel-software%2Fcbor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalpel-software%2Fcbor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scalpel-software","download_url":"https://codeload.github.com/scalpel-software/cbor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219846912,"owners_count":16556420,"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":["cbor","decoding","elixir","encoding"],"created_at":"2024-09-30T15:43:43.870Z","updated_at":"2024-10-14T19:04:07.235Z","avatar_url":"https://github.com/scalpel-software.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CBOR\n\n[![Module Version](https://img.shields.io/hexpm/v/cbor.svg)](https://hex.pm/packages/cbor)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/cbor/)\n[![Total Download](https://img.shields.io/hexpm/dt/cbor.svg)](https://hex.pm/packages/cbor)\n[![License](https://img.shields.io/hexpm/l/cbor.svg)](https://github.com/scalpel-software/cbor/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/scalpel-software/cbor.svg)](https://github.com/scalpel-software/cbor/commits/master)\n\nImplementation of RFC 7049 [CBOR](http://cbor.io) (Concise Binary\nObject Representation) for Elixir.\n\nThis is a fork of [excbor](https://github.com/cabo/excbor) which modernizes\nthe codebase, and makes decisions on handling data types that the original library had punted on.\n\n## Migrating from the previous version\n\nThis library is a fork of the no longer maintained excbor project.\n\nFor those migrating from previous versions of this library there are breaking changes that you should be aware of.\n\nThe module `Cbor` has been renamed to `CBOR`.\n\nCBOR.decode will return a three item tuple of the form `{:ok, decoded, rest}`, instead of returning the decoded object. In the wild there are APIs that concat CBOR objects together. The `rest` variable includes any leftover information from the decoding operation in case you need to decode multiple objects.\n\nAtoms will be encoded/decoded as strings, except for the special case of `:__undefined__` which has no direct translation to elixir but has semantic meaning in CBOR.\n\nElixir/Erlang does not have a concept of infinity, negative infinity or NaN. In order to encode or decode these values we will return a struct of the form `%CBOR.Tag{tag: :float, value: (:inf|:\"-inf\"|:nan)}`\n\nIf you want to encode a raw binary value, you can use the `CBOR.Tag` struct with a tag of `:bytes` and the binary as the `:value` field.\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:cbor, \"~\u003e 1.0.0\"}\n  ]\nend\n```\n\n## Usage\n\nThis library follows the standard API for CBOR libraries by exposing two methods\non the CBOR module `CBOR.encode/1` and `CBOR.decode/1`.\n\n### Encoding\n\n```elixir\niex(1)\u003e CBOR.encode([1, [2, 3]])\n\u003c\u003c130, 1, 130, 2, 3\u003e\u003e\n```\n\n### Decoding\n\n```elixir\niex(2)\u003e CBOR.decode(\u003c\u003c130, 1, 130, 2, 3\u003e\u003e)\n{:ok, [1, [2, 3]], \"\"}\n```\n\n## Design Notes\n\nGiven that Elixir has more available data types than are supported in CBOR, decisions were made so that encoding complex data structures succeed without throwing errors. My thoughts are collected below so you can understand why encoding and decoding of a value does not necessarily return exactly the same value.\n\n### Atoms\n\nThe only atoms that will be directly encoded are `true`, `false` `nil` and `__undefined__`. Every other atom will be converted to a string before being encoded. We surround undefined with double underscores so that you only encode an undefined value when you clearly intend to do so.\n\n### Keyword List, MapSet, Range, Tuple\n\nAll of the above data structures are converted to Lists before being encoded. This ensures that there is no data lost when encoding and decoding.\n\n### NaiveDateTime\n\nNaiveDateTime will be treated as if they are UTC.\n\n### Special Values\n\nElixir and erlang have no concept of infinity, negative infinity and NaN. If you want to encode those values, we have a special struct `CBOR.Tag` which you can use to represent those values.\n\n```elixir\n%CBOR.Tag{tag: :float, value: :inf}\n\n%CBOR.Tag{tag: :float, value: :\"-inf\"}\n\n%CBOR.Tag{tag: :float, value: :nan}\n```\n\n`CBOR.Tag` is also useful if you want to extend `CBOR` for internal applications\n\n## Custom Encoding\n\nIf you want to encode something that is not supported out of the box you can implement the `CBOR.Encoder` protocol for the module. You only have to implement a single `CBOR.Encoder.encode_into/2` function. An example for encoding a Money struct is given below.\n\n```elixir\ndefimpl CBOR.Encoder, for: Money do\n  def encode_into(money, acc) do\n    money |\u003e Money.to_string() |\u003e CBOR.Encoder.encode_into(acc)\n  end\nend\n```\n\n### Documentation\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/cbor](https://hexdocs.pm/cbor).\n\n\n## Copyright and License\n\nCopyright (c) 2019 Thomas Cioppettini\n\nThis work is free. You can redistribute it and/or modify it under the\nterms of the MIT License. See the [LICENSE.md](./LICENSE.md) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalpel-software%2Fcbor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscalpel-software%2Fcbor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalpel-software%2Fcbor/lists"}