{"id":37022015,"url":"https://github.com/enriquerodbe/borsh4s","last_synced_at":"2026-01-14T02:37:19.550Z","repository":{"id":39987350,"uuid":"471104739","full_name":"enriquerodbe/borsh4s","owner":"enriquerodbe","description":"Scala implementation of Borsh serialization format","archived":false,"fork":false,"pushed_at":"2025-12-18T18:14:02.000Z","size":214,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-21T20:59:50.743Z","etag":null,"topics":["binary","borsh","scala","serialization"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/enriquerodbe.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-17T18:50:45.000Z","updated_at":"2025-12-18T18:09:40.000Z","dependencies_parsed_at":"2023-02-05T00:16:05.185Z","dependency_job_id":"7ad95a4b-86d5-43ea-8cde-02ae9593327a","html_url":"https://github.com/enriquerodbe/borsh4s","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/enriquerodbe/borsh4s","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enriquerodbe%2Fborsh4s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enriquerodbe%2Fborsh4s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enriquerodbe%2Fborsh4s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enriquerodbe%2Fborsh4s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enriquerodbe","download_url":"https://codeload.github.com/enriquerodbe/borsh4s/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enriquerodbe%2Fborsh4s/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","borsh","scala","serialization"],"created_at":"2026-01-14T02:37:18.968Z","updated_at":"2026-01-14T02:37:19.538Z","avatar_url":"https://github.com/enriquerodbe.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Borsh4s\nScala implementation of [Borsh](https://borsh.io/) serialization format.\n\n## Motivation\nThere are Java and Javascript implementations for Borsh, but both are very inconvenient to use from Scala on JVM and ScalaJS. The Java implementation uses POJOs and reflection (discouraged in Scala ecosystem) which makes interoperability hard. The JS interoperability is even harder because it uses, for example, the class constructor function as the key of a map where schemas must be declared. This adds a lot of boilerplate required for ScalaJS developers to make it work.\n\nThis project aims to be an idiomatic Scala implementation of the Borsh binary serialization format. Cross compiled for Scala on JVM and ScalaJS. Based on type classes and automatic type class derivation, without reflection or any other \"unsafe\" runtime tools.\n\n## Quick start\n\n### Add the dependency\n\n```scala\nlibraryDependencies += \"io.github.enriquerodbe\" %% \"borsh4s\" % \"\u003cversion\u003e\"\n```\n\nFind the latest version in [Releases](https://github.com/enriquerodbe/borsh4s/releases), and remember to use\n`%%%` for ScalaJS.\n\n### Code example\n\n```scala\nimport io.borsh4s.{Borsh4s, given}\n\ncase class MyTestClass(field1: Int, field2: String, nested: NestedClass)\ncase class NestedClass(field1: Boolean, field2: Map[String, Float])\n\nval instance = MyTestClass(2, \"Hello\", NestedClass(true, Map(\"World\" -\u003e 1.5f)))\n    \nval encoded = Borsh4s.encode(instance)\nval decoded = Borsh4s.decode[MyTestClass](encoded)\n    \nassert(Right(instance) == decoded)\n```\n\n## Supported types\n\nBase types:\nBorsh | Scala\n:---:|:---:\n`i8` | `Byte`\n`i16` | `Short`\n`i32` | `Int`\n`i64` | `Long`\n`f32` | `Float`\n`f64` | `Double`\n`()` | `Unit`\n`bool` | `Boolean`\n`String` | `String`\n\n\nFor all supported types `T`, `K`, and `V`:\nBorsh | Scala\n:---:|:---:\n`Option\u003cT\u003e` | `Option[T]`\n`Vec\u003cT\u003e` | `Array[T]`\n`HashSet\u003cT\u003e` | `Set[T]`\n`HashMap\u003cK, V\u003e` | `Map[K, V]`\n\nFor all supported types `T0` ... `TN`\nBorsh | Scala\n:---:|:---:\n`struct Name { field0: T0, ..., fieldN: TN }` | `case class Name(field0: T0, ..., fieldN: TN)`\n`enum Name { T0, ..., TN }` | `enum Name { case T0, ..., case TN }`\n\n## How does it work?\n\nBorsh4s is implemented using the [Type class](https://en.wikipedia.org/wiki/Type_class) pattern and exposes two interfaces:\n\n```scala\ndef encode[T: Encoder: BinarySize](t: T): Array[Byte]\n\ndef decode[T: Decoder](bytes: Array[Byte]): Either[Decoder.Failure, T]\n```\n\nTo encode an instance of `T`, instances of the following type classes must be available in the implicit scope:\n- [`io.borsh4s.Encoder[T]`](src/main/scala/io/borsh4s/Encoder.scala) - Implements the encoding logic.\n- [`io.borsh4s.BinarySize[T]`](src/main/scala/io/borsh4s/BinarySize.scala) - Calculates the total size of the byte array that is going to be created to write the encoded object.\n\nTo decode an instance of `T`, only an instance of [`io.borsh4s.Decoder[T]`](src/main/scala/io/borsh4s/Decoder.scala) is needed, which implements the decoding logic.\n\nInstances of the supported base and collection types as well as automatic derivation for `case class`es are provided out-of-the-box. To make all of them available in the implicit scope, use the following import:\n\n```scala\nimport io.borsh4s.given\n```\n\n### Providing implementations for unsupported types\n\nCustom implementations are not recommended because they may deviate from Borsh\nspecification. However, this project doesn't support all possible Borsh types,\nso some custom implementations might be needed.\n\nIn order to add support for a type `T`, make implementations for the\n`io.borsh4s.Encoder[T]`, `io.borsh4s.BinarySize[T]`, and `io.borsh4s.Decoder[T]` type classes and make sure\nthey are in the implicit scope of any `io.borsh4s.Borsh4s.encode` and\n`io.borsh4s.Borsh4s.decode` calls.\n\nNotice that these type classes use `java.nio.ByteBuffer` which is mutable. Make\nsure that any custom implementation moves the position of this buffer exactly\nas the size of the type being read/written requires, otherwise it will break the\nwhole decoding/encoding process. Find examples in `io.borsh4s.instances.Encoders`\nand `io.borsh4s.instances.Decoders`.\n\n## Developing\n\n### Requirements\n\n- [sbt](https://www.scala-sbt.org/)\n- JDK to build for the JVM\n- Node.js to build for ScalaJS\n\nThe exact versions being used for these dependencies are defined in the\n[`.tool-versions`](.tool-versions) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenriquerodbe%2Fborsh4s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenriquerodbe%2Fborsh4s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenriquerodbe%2Fborsh4s/lists"}