{"id":21035232,"url":"https://github.com/l-briand/obor","last_synced_at":"2025-05-15T13:33:23.393Z","repository":{"id":57737559,"uuid":"289461298","full_name":"L-Briand/obor","owner":"L-Briand","description":"A CBOR serializer implemented with kotlinx-serialization","archived":false,"fork":false,"pushed_at":"2024-10-24T14:16:01.000Z","size":479,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T10:37:29.072Z","etag":null,"topics":["cbor","kotlin","kotlinx-serialization"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L-Briand.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":"2020-08-22T09:48:11.000Z","updated_at":"2025-03-31T05:24:48.000Z","dependencies_parsed_at":"2024-08-28T14:25:49.121Z","dependency_job_id":"1fa53e4b-8abc-4172-9c20-5fe25c8fe039","html_url":"https://github.com/L-Briand/obor","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fobor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fobor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fobor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fobor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L-Briand","download_url":"https://codeload.github.com/L-Briand/obor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254349686,"owners_count":22056395,"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","kotlin","kotlinx-serialization"],"created_at":"2024-11-19T13:14:07.350Z","updated_at":"2025-05-15T13:33:18.636Z","avatar_url":"https://github.com/L-Briand.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OBOR\n\nAn implementation of the serial format [CBOR](https://cbor.io/) with Kotlin multiplatform and jetbrains\nkotlinx-serialization api.\n\n# Usage\n\nYou can find obor library on maven central.\n\nFor Jvm:\n\n```kotlin\ndependencies {\n    implementation(\"org.jetbrains.kotlinx:kotlinx-serialization-core:x.y.z\")\n    implementation(\"net.orandja.obor:obor:2.1.3\")\n}\n```\n\nFor multiplatform:\n\n```kotlin\nkotlin {\n    ...\n    sourceSets {\n        getByName(\"commonMain\") {\n            dependencies {\n                implementation(\"org.jetbrains.kotlinx:kotlinx-serialization-core:x.y.z\")\n                implementation(\"net.orandja.obor:obor:2.1.3\")\n            }\n        }\n    }\n}\n```\n\n# Example\n\nIt uses conventionnal encode/decode kotlinx-serialization functions like JSON. You can take a look on how it\nworks [here](https://github.com/Kotlin/kotlinx.serialization#introduction-and-references).\n\n```kotlin\nimport net.orandja.obor.codec.Cbor\nimport kotlinx.serialization.Serializable\n\n@Serializable\ndata class Example(val foo: String, val bar: Int)\n\nfun main() {\n    val example = Example(\"Hello World !\", 42)\n    val encode = Cbor.encodeToHexString(example)\n    assert(encode == \"a263666f6f6d48656c6c6f20576f726c64202163626172182a\")\n    val decode = Cbor.decodeFromHexString\u003cExample\u003e(encode)\n    assert(example == decode)\n}\n```\n\nThe bytes translate to:\n\n```\nA2                               # map(2)\n   63                            # text(3)\n      666F6F                     # \"foo\"\n   6D                            # text(13)\n      48656C6C6F20576F726C642021 # \"Hello World !\"\n   63                            # text(3)\n      626172                     # \"bar\"\n   18 2A                         # unsigned(42)\n```\n\nThe Cbor codec can be configured with :\n\n```kotlin\nval codec = Cbor {\n    ingnoreUnknownKeys = false // Set to true to ignore unknown keys during deserialization  \n}\n```\n\n## Features\n\n- It always uses the least number of bytes to encode something.\n  An Int with a value of less than 24 will be encoded to a single byte.\n  A float32 that can be encoded with a float16 will be encoded as a float16.\n\n\n- Like the `JsonObject`, you can use the [CborObject](src/commonMain/kotlin/net/orandja/obor/data/CborObject.kt) to\n  encode / decode anything. Even structures which are challenging to create with the kotlin language.\n  See [Handle any data structure](readme/cbor_object.md)\n\n\n- By implementing the [Reader](src/commonMain/kotlin/net/orandja/obor/io/Reader.kt)\n  or [Writer](src/commonMain/kotlin/net/orandja/obor/io/Writer.kt) interface, you are able to read and write CBOR from\n  anything. Know how many bytes were read/written. See [Reading and writing to anything](readme/io.md)\n\n\n- There are special\n  serializers (in [CborUnsignedSerializer](src/commonMain/kotlin/net/orandja/obor/serializer/CborUnsignedSerializer.kt))\n  to serialize and deserialize full range of signed and unsigned values. See [Unsigned values](readme/unsigned.md)\n\n\n- Create any tagged CBOR data with the `@CborTag` annotation. See [Creating tagged elements](readme/tags.md)\n\n\n- ByteArray and types looking like `List\u003cByte\u003e` can be written with Major type 2 instead of Major type 4 with\n  `@CborRawBytes` and special serializers. See [Handling MAJOR (type 2) bytes and indefinite bytes](readme/bytes.md)\n\n\n- Indefinite length is handled automatically on deserialization and can be specified on serialization with\n  `@CborIndefinite` or special serializers.\n\n\n- You can compact the serialization of a class to its ordered properties with `@CborTuple`. \u003c/br\u003e\n  `{ a: \"foo\", b: 0 }` -\u003e `[ \"foo\", 0 ]`\n\n\n- You can shrink down the serialization further if a `@CborTuple` is in a list with `@CborTuple.inlineInList`. \u003c/br\u003e\n  `[{ a: \"foo\", b: 0 }, { a: \"bar\", b: 1 }]` -\u003e `[ \"foo\", 0, \"bar\", 1]`\n\n## Annotations\n\n- **[CborTuple](src/commonMain/kotlin/net/orandja/obor/annotations/CborTuple.kt)** A class or object annotated with it\n  will be serialized as an ordered list of its elements.\n\n- **[CborIndefinite](src/commonMain/kotlin/net/orandja/obor/annotations/CborIndefinite.kt)**\n  Indicates to the codec to always use indefinite length encoding when encoding the annotated value. For example:\n    - `class Foo(val a: List\u003cInt\u003e)` -\u003e `Foo(listOf(0,1))` will be serialized to `A16161820001`\n    - `@CborIndefinite class Foo(val a: List\u003cInt\u003e)` -\u003e `Foo(listOf(0,1))` will be serialized to `BF6161820001FF`\n\n- **[CborRawBytes](src/commonMain/kotlin/net/orandja/obor/annotations/CborRawBytes.kt)**\n  When a type looks like a `List\u003cByte\u003e` (`Array\u003cByte\u003e`, `ByteArray`) and is annotated with `@CborRawBytes` It will use\n  the\n  major type 2 (byte string) instead of major type 4 (array).\n    - `class Foo(val a: List\u003cByte\u003e)` -\u003e `Foo(listOf(0, 1))` will be serialized to `A16161820001`\n    - `class Foo(@CborRawBytes val a: List\u003cByte\u003e)` -\u003e `Foo(listOf(0, 1))` will be serialized to `A16161420001`\n\n- **[CborSkip](src/commonMain/kotlin/net/orandja/obor/annotations/CborSkip.kt)** Annotates a field to skip it during\n  serialization and deserialization\n\n- **[CborTag](src/commonMain/kotlin/net/orandja/obor/annotations/CborTag.kt)** Adds a tag to the specified field or\n  class.\n\n## Notice\n\nThe use of `@CborIndefinite` only affects serialization and not deserialization. Unless you use the specific special\nserializers as described in [Handling MAJOR (type 2) bytes and indefinite bytes](readme/bytes.md)\nor [Handling MAJOR (type 3) indefinite string](readme/string.md).\n\nAn indefinite marker will be deserialized like a non-indefinite one. For example `0x9f010203ff` and `0x83010203` can\nboth be\ndeserialized to `listOf(1, 2, 3)`\n\n```kotlin\nassertEquals(\n    Cbor.decodeFromHexString\u003cList\u003cInt\u003e\u003e(\"83010203\"),\n    Cbor.decodeFromHexString\u003cList\u003cInt\u003e\u003e(\"9f010203ff\")\n)\n```\n\n## Further read\n\n- [Handle any data structure](readme/cbor_object.md)\n- [Reading and writing to anything](readme/io.md)\n- [Unsigned values](readme/unsigned.md)\n- [Handling MAJOR (type 2) bytes and indefinite bytes](readme/bytes.md). Speed up serializing/deserializing\n- [Handling MAJOR (type 3) indefinite string](readme/string.md)\n- [Indefinite mark on serialization](readme/indefinite.md)\n- [Creating tagged elements](readme/tags.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Fobor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl-briand%2Fobor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Fobor/lists"}