ByteDecoder

org.sigilaris.core.codec.byte.ByteDecoder
See theByteDecoder companion object
trait ByteDecoder[A]

Type class for decoding byte sequences to Scala values.

ByteDecoder is the inverse of ByteEncoder, reconstructing typed values from deterministic byte representations.

Decoding returns Either[DecodeFailure, DecodeResult[A]]:

  • Left(failure): decoding failed with error message
  • Right(result): successfully decoded value with remaining bytes

The remainder allows sequential decoding of multiple values from a single byte sequence.

Attributes

See also

ByteEncoder for the encoding operation

ByteCodec for bidirectional encoding/decoding

types.md for detailed decoding rules per type

Companion
object
Source
ByteDecoder.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def decode(bytes: ByteVector): Either[DecodeFailure, DecodeResult[A]]

Decodes bytes to a value.

Decodes bytes to a value.

Value parameters

bytes

the byte sequence to decode

Attributes

Returns

Either failure or decoded value with remainder

Source
ByteDecoder.scala

Concrete methods

def emap[B](f: A => Either[DecodeFailure, B]): ByteDecoder[B]

Creates a new decoder with validation.

Creates a new decoder with validation.

Value parameters

f

function that may fail with DecodeFailure

Attributes

Returns

new decoder for type B

Example
 val positiveDecoder = ByteDecoder[Long].emap { n =>
   Either.cond(n > 0, n, DecodeFailure("Must be positive"))
 }
Source
ByteDecoder.scala
def flatMap[B](f: A => ByteDecoder[B]): ByteDecoder[B]

Creates a new decoder by chaining decoders.

Creates a new decoder by chaining decoders.

Value parameters

f

function that creates a decoder based on decoded value

Attributes

Returns

new decoder for type B

Source
ByteDecoder.scala
def map[B](f: A => B): ByteDecoder[B]

Creates a new decoder by transforming the decoded value.

Creates a new decoder by transforming the decoded value.

Value parameters

f

function to transform decoded value

Attributes

Returns

new decoder for type B

Source
ByteDecoder.scala
def widen[AA >: A]: ByteDecoder[AA]

Widens the decoder to a supertype.

Widens the decoder to a supertype.

Type parameters

AA

the supertype

Attributes

Returns

a decoder for the wider type

Source
ByteDecoder.scala