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: about 1 year 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 (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T02:12:36.000Z (about 1 year ago)
- Last Synced: 2025-04-01T03:22:35.194Z (about 1 year ago)
- Topics: adapter, codec, encoder-decoder, messaging, scala, scala3
- Language: Scala
- Homepage: http://projects.hnaderi.dev/named-codec/
- Size: 179 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
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

[](https://index.scala-lang.org/hnaderi/named-codec/named-codec)
[](https://javadoc.io/doc/dev.hnaderi/named-codec-docs_3)
[](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 })
```