{"id":20800862,"url":"https://github.com/mcxross/kotlinx-serialization-bcs","last_synced_at":"2026-01-12T08:47:21.628Z","repository":{"id":198642145,"uuid":"700823190","full_name":"mcxross/kotlinx-serialization-bcs","owner":"mcxross","description":"Kotlin Multiplatform implementation of the Binary Canonical Serialization (BCS) format","archived":false,"fork":false,"pushed_at":"2024-07-08T00:53:29.000Z","size":160,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-17T18:16:05.423Z","etag":null,"topics":["aptos","bcs","crypto","rust","sui"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/mcxross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2023-10-05T11:16:55.000Z","updated_at":"2024-07-08T00:53:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"6879d9ae-178b-47a2-af80-d270e179dccb","html_url":"https://github.com/mcxross/kotlinx-serialization-bcs","commit_stats":null,"previous_names":["mcxross/kotlinx-serialization-bcs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxross%2Fkotlinx-serialization-bcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxross%2Fkotlinx-serialization-bcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxross%2Fkotlinx-serialization-bcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxross%2Fkotlinx-serialization-bcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcxross","download_url":"https://codeload.github.com/mcxross/kotlinx-serialization-bcs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253595642,"owners_count":21933431,"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":["aptos","bcs","crypto","rust","sui"],"created_at":"2024-11-17T18:16:02.374Z","updated_at":"2026-01-12T08:47:21.623Z","avatar_url":"https://github.com/mcxross.png","language":"Kotlin","funding_links":[],"categories":["Client SDKs \u0026 Libraries"],"sub_categories":["Client Libraries"],"readme":"\u003ch1 align=\"center\"\u003eBCS\u003c/h1\u003e\n\nKotlin Multiplatform implementation of Binary Canonical Serialization (BCS) as an encoding format for\nthe [kotlinx.serialization](https://kotlinlang.org/docs/serialization.html#libraries) library\n\n[![Kotlin Version](https://img.shields.io/badge/Kotlin-1.9.22-B125EA?logo=kotlin)](https://kotlinlang.org)\n[![Maven Central](https://img.shields.io/maven-central/v/xyz.mcxross.bcs/bcs.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/xyz.mcxross.bcs/bcs)\n[![Snapshot](https://img.shields.io/nexus/s/xyz.mcxross.bcs/bcs?server=https%3A%2F%2Fs01.oss.sonatype.org\u0026label=Snapshot)](https://s01.oss.sonatype.org/content/repositories/snapshots/xyz/mcxross/bcs/)\n[![Build](https://github.com/mcxross/kotlinx-serialization-bcs/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/mcxross/kotlinx-serialization-bcs/actions/workflows/build.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\n\n![badge-android](http://img.shields.io/badge/Platform-Android-brightgreen.svg?logo=android)\n![badge-ios](http://img.shields.io/badge/Platform-iOS-orange.svg?logo=apple)\n![badge-js](http://img.shields.io/badge/Platform-NodeJS-yellow.svg?logo=javascript)\n![badge-jvm](http://img.shields.io/badge/Platform-JVM-red.svg?logo=openjdk)\n![badge-linux](http://img.shields.io/badge/Platform-Linux-lightgrey.svg?logo=linux)\n![badge-macos](http://img.shields.io/badge/Platform-macOS-orange.svg?logo=apple)\n![badge-windows](http://img.shields.io/badge/Platform-Windows-blue.svg?logo=windows)\n\n### Table of contents\n\n- [Quick start](#quick-start)\n  - [Installation](#installation)\n    - [Multiplatform](#multiplatform)\n    - [Platform specific (Android, JS, Native, JVM)](#platform-specific-android-js-native-jvm)\n    - [Serialization](#serialization)\n      - [Basic Types](#basic-types)\n      - [User-defined Types](#user-defined-types)\n- [For Rust Developers](#for-rust-developers)\n  - [Parity](#parity)\n- [Reference](#reference)\n- [Contribution](#contribution)\n\n## Quick Start\n\n### Installation\n\n#### Multiplatform\nAdd the `kotlinx-serialization-bcs` dependency to the common sourceSet\n\n```kotlin\nimplementation(\"xyz.mcxross.bcs:bcs:\u003c$bcs_version\u003e\")\n```\n#### Platform specific (Android, JS, Native, JVM)\nAdd the `kotlinx-serialization-bcs` dependency to the Project's dependency block\n\nGeneric:\n\n```kotlin\nimplementation(\"xyz.mcxross.bcs:\u003cbcs-[platform]\u003e:\u003c$bcs_version\u003e\")\n```\nFor example for Android and JS\n\nAndroid:\n\n```kotlin\nimplementation(\"xyz.mcxross.bcs:bcs-android:\u003c$bcs_version\u003e\")\n```\n\nJS:\n\n```kotlin\nimplementation(\"xyz.mcxross.bcs:bcs-js:\u003c$bcs_version\u003e\")\n```\n\n\n#### Serialization\n\n##### Basic Types\n\nFor basic types, simply call the `Bcs.encodeToByteArray()` function with the desired value, and in each case, you will get a `ByteArray` containing the state of this object in the BCS format\n\n- **Triple**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(Triple(listOf(), \"çå∞≠¢õß∂ƒ∫\", Location(x = 3, y = 4)))\n```\n\n- **String**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(\"çå∞≠¢õß∂ƒ∫\")\n```\n\n- **List**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(listOf(1, 2, 3, 4, 5))\n```\n\n- **Map**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(mapOf(\"a\" to 1, \"b\" to 2, \"c\" to 3))\n```\n\n- **Double**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(3.14159265359)\n```\n\n- **Boolean**\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(false)\n```\n\nDeserialization is done by calling the `Bcs.decodeFromByteArray()` function with the **described** type\n\n##### User-defined Types\n\nFor use-defined types, first make a class serializable by annotating it with `@Serializable`\n\n```kotlin\n@Serializable\ndata class Data(\n    val long: Long,\n    val double: Double,\n    val string: String,\n    val boolean: Boolean\n)\n```\n\nYou can now serialize an instance of this class by calling `Bcs.encodeToByteArray()`\n\n```kotlin\nval bcs = Bcs.encodeToByteArray(\n    Data(1_000_000, 3.14159265359, \"çå∞≠¢õß∂ƒ∫\", false)\n)\n```\n\nAs a result, you get a `ByteArray` containing the state of this object in the BCS format\n\nTo deserialize an object from BCS, use the `decodeFromByteArray()` function:\n\n```kotlin\nval obj = Bcs.decodeFromByteArray\u003cData\u003e(byteArrayOf())\n```\n\n**Note**: BCS is not a self-describing format. As such, one must know the message type and layout ahead of time in order\nto deserialize.\n\n## For Rust Developers\n\n### Parity\n\nFor parity with the original Rust BCS implementation, the following type translations are used:\n\n| Rust type | Kotlin Type        |\n|-----------|--------------------|\n| Struct    | Data class         |\n| Tuple     | Pair, Triple, etc. |\n| Unit      | Unit               |\n| Option    | T?                 |\n\n## Reference\n\nBCS specs can be found [here](https://github.com/diem/bcs/#readme)\n\n## Contribution\n\nAll contributions to KMP BCS are welcome. Before opening a PR, please submit an issue detailing the bug or feature. When\nopening a PR, please ensure that your contribution builds on the KMM toolchain, has been linted\nwith `ktfmt \u003cGOOGLE (INTERNAL)\u003e`, and contains tests when applicable. For more information, please see\nthe [contribution guidelines](CONTRIBUTING.md).\n\n## License\n\n    Copyright 2022 McXross\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[maven-central]: https://search.maven.org/artifact/xyz.mcxross/bcs","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcxross%2Fkotlinx-serialization-bcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcxross%2Fkotlinx-serialization-bcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcxross%2Fkotlinx-serialization-bcs/lists"}