Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hnaderi/named-codec
Scala3 codec adapter that separates types and payloads
https://github.com/hnaderi/named-codec
adapter codec encoder-decoder messaging scala scala3
Last synced: 3 months ago
JSON representation
Scala3 codec adapter that separates types and payloads
- Host: GitHub
- URL: https://github.com/hnaderi/named-codec
- Owner: hnaderi
- License: apache-2.0
- Created: 2022-08-12T10:26:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T01:07:32.000Z (3 months ago)
- Last Synced: 2024-10-29T02:18:53.349Z (3 months ago)
- Topics: adapter, codec, encoder-decoder, messaging, scala, scala3
- Language: Scala
- Homepage: http://projects.hnaderi.dev/named-codec/
- Size: 132 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# named-codec
Scala3 codec adapter that separates types and payloads[![named-codec-core Scala version support](https://index.scala-lang.org/hnaderi/named-codec/named-codec/latest.svg?style=flat-square)](https://index.scala-lang.org/hnaderi/named-codec/named-codec)
[![javadoc](https://javadoc.io/badge2/dev.hnaderi/named-codec-docs_3/scaladoc.svg?style=flat-square)](https://javadoc.io/doc/dev.hnaderi/named-codec-docs_3)
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)this is a tiny utility library that provides a simple codec adapter,
that helps with creating codec that encode/decode type name separately.This is mostly helpful in messaging applications, where payload and message types are separated;
or for scenarios that you need to store a separate type name to enable type filtering.### Usage
This library is currently available for Scala binary version 3.3 on both JVM, JS and native.
To use the latest version, include the following in your `build.sbt`:
```scala
libraryDependencies ++= Seq(
"dev.hnaderi" %% "named-codec" % "@VERSION@"
)// or circe module directly
libraryDependencies ++= Seq(
"dev.hnaderi" %% "named-codec-circe" % "@VERSION@"
)
``````scala
enum Data {
case A
case B(i: Int)
case C(s: String, i: Int)
}import io.circe.generic.auto.*
import dev.hnaderi.namedcodec.*val codec = CirceAdapter.of[Data]
codec.encode(Data.C("string", 101))
// EncodedMessage(name = "C", data = { "s": "string", i: 101 })
```