trait Codec[L, H, +CF <: CodecFormat] extends Mapping[L, H]
A Mapping between low-level values of type L
and high-level values of type H
. Low level values are
formatted as CF
.
The mapping consists of a pair of functions, one to decode (L => H
), and one to encode (H => L
)
Decoding can fail, and this is represented as a result of type DecodeResult.
A codec also contains optional meta-data on the schema
of the high-level value, as well as an instance
of the format (which determines the media type of the low-level value).
Codec instances are used as implicit values, and are looked up when defining endpoint inputs/outputs. Depending on a particular endpoint input/output, it might require a codec which uses a specific format, or a specific low-level value.
Codec instances can be derived basing on other values (e.g. such as json encoders/decoders when integrating with json libraries). Or, they can be defined by hand for custom types, usually customising an existing, simpler codec.
Codecs can be chained with Mappings using the map
function. Codecs are also Mappings, meaning that
mappings can be re-used.
- L
The type of the low-level value.
- H
The type of the high-level value.
- CF
The format of encoded values. Corresponds to the media type.
- Self Type
- Codec[L, H, CF]
- Annotations
- @implicitNotFound("""Cannot find a codec between types: ${L} and ${H}, formatted as: ${CF}.
Did you define a codec for: ${H}?
Did you import the codecs for: ${CF}?
""")
- Alphabetic
- By Inheritance
- Codec
- Mapping
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def decode(l: L): DecodeResult[H]
- calls
rawDecode
- catches any exceptions that might occur, converting them to decode failures - validates the result- calls
rawDecode
- catches any exceptions that might occur, converting them to decode failures - validates the result- Definition Classes
- Mapping
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def format[CF2 <: CodecFormat](f: CF2): Codec[L, H, CF2]
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[HH](f: (H) => HH)(g: (HH) => H): Codec[L, HH, CF]
- def map[HH](codec: Mapping[H, HH]): Codec[L, HH, CF]
- def mapDecode[HH](f: (H) => DecodeResult[HH])(g: (HH) => H): Codec[L, HH, CF]
- def modifySchema(modify: (Schema[H]) => Schema[H]): Codec[L, H, CF]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def schema(s2: Option[Schema[H]]): Codec[L, H, CF]
- def schema(s2: Schema[H]): Codec[L, H, CF]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def validate(v: Validator[H]): Codec[L, H, CF]
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()