scodec.internal
Document{}
Represents the ability to create a Cipher
for encryption or decryption.
Used in conjunction with encrypted.
- Companion
- object
Codec that supports the binary structure tag ++ value
where the tag
identifies the encoding/decoding of
the value.
To build an instance of this codec, call discriminated and specify the tag type via the by
method. Then
call one more more of the case combinators on this class.
The most general case combinators are caseO
and caseP
.
In addition to a tag, the caseO
combinator is defined by providing a mapping from
A
to Option[R]
, a mapping from R
to A
, and a Codec[R]
. The case is used for encoding if the
mapping from A
to Option[R]
returns a Some
and it is used for decoding upon matching the tag value.
The caseP
combinators work the same but take a PartialFunction[A, R]
instead of an A => Option[R]
.
If R
is a subtype of A
, then the mapping from R
to A
can be omitted. Hence, the
subcaseO
and subcaseP
constrain R
to being a subtype of A
and do not take a R => A
function.
Finally, the least generic case combinators are the typecase
combinators which add further constraints
to the subcase*
combinators. Specifically, the typecase operators omit the A => Option[R]
or
PartialFunction[A, R]
in favor of doing subtype checks. For example, the following codec is a Codec[AnyVal]
that encodes a 0 if passed a Boolean
and a 1 if passed an Int
:
{{{
discriminated[AnyVal].by(uint8).typecase(0, bool).typecase(1, int32)
}}}
Often, the values are size-delimited -- that is, there is a size
field after the tag
field and beforethe
valuefield. To support this, use the
framingmethod to provide a transformation to each value codec. For example,
framing(new CodecTransformation { def apply[X](c: Codec[X]) = variableSizeBytes(uint8, c) })`.
- Value Params
- by
codec that encodec/decodes the tag value
- cases
cases, ordered from highest priority to lowest priority, that handle subsets of
A
- See also
discriminated
Represents the ability to create a "checksum" for use with fixedSizeSignature and variableSizeSignature.
Represents the ability to create a Signer for use with fixedSizeSignature and variableSizeSignature.
Type members
Classlikes
Provides methods to create a "checksum codec" (encodes a bit-range to a bit-checksum and decodes bits to a bit-range).
Indicates a checksum over bits
did not match the expected value.