scodec

Codec

trait Codec[A] extends GenCodec[A, A]

Supports encoding a value of type A to a BitVector and decoding a BitVector to a value of A.

Not every value of A can be encoded to a bit vector and similarly, not every bit vector can be decoded to a value of type A. Hence, both encode and decode return either an error or the result. Furthermore, decode returns the remaining bits in the bit vector that it did not use in decoding.

Note: the decode function can be lifted to a state action via StateT[String \/ ?, BitVector, A]. This type alias and associated constructor is provided by DecodingContext.

Self Type
Codec[A]
Source
Codec.scala
Linear Supertypes
GenCodec[A, A], Decoder[A], Encoder[A], AnyRef, Any
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Grouped
  2. Alphabetic
  3. By inheritance
Inherited
  1. Codec
  2. GenCodec
  3. Decoder
  4. Encoder
  5. AnyRef
  6. Any
Implicitly
  1. by ValueCodecEnrichedWithHListSupport
  2. by HListCodecEnrichedWithHListSupport
  3. by any2stringadd
  4. by StringFormat
  5. by Ensuring
  6. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def decode(bits: BitVector): \/[String, (BitVector, A)]

    Attempts to decode a value of type A from the specified bit vector.

    Attempts to decode a value of type A from the specified bit vector.

    bits

    bits to decode

    returns

    error if value could not be decoded or the remaining bits and the decoded value

    Definition Classes
    Decoder
  2. abstract def encode(value: A): \/[String, BitVector]

    Attempts to encode the specified value in to a bit vector.

    Attempts to encode the specified value in to a bit vector.

    value

    value to encode

    Definition Classes
    Encoder

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from Codec[A] to any2stringadd[Codec[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Codec[A], B)

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ArrowAssoc[Codec[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. def :+[B, LB <: HList](codec: Codec[B])(implicit prepend: shapeless.ops.hlist.Prepend.Aux[A, ::[B, HNil], LB], init: Aux[LB, A], last: Aux[LB, B]): Codec[LB]

    When called on a Codec[L] for some L <: HList, returns a new codec that encodes/decodes the HList L followed by a B.

    When called on a Codec[L] for some L <: HList, returns a new codec that encodes/decodes the HList L followed by a B. That is, this operator is a codec-level HList append operation.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  6. def ::[B](codecB: Codec[B]): Codec[::[B, ::[A, HNil]]]

    When called on a Codec[A] where A is not a subytpe of HList, creates a new codec that encodes/decodes an HList of B :: A :: HNil.

    When called on a Codec[A] where A is not a subytpe of HList, creates a new codec that encodes/decodes an HList of B :: A :: HNil. For example,

    uint8 :: utf8

    has type Codec[Int :: String :: HNil]. uint8 :: utf8 }}}

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  7. def ::[B](codec: Codec[B]): Codec[::[B, A]]

    When called on a Codec[L] for some L <: HList, returns a new codec representing Codec[B :: L].

    When called on a Codec[L] for some L <: HList, returns a new codec representing Codec[B :: L]. That is, this operator is a codec-level HList prepend operation.

    codec

    codec to prepend

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  8. def :::[K <: HList, KL <: HList, KLen <: Nat](k: Codec[K])(implicit prepend: shapeless.ops.hlist.Prepend.Aux[K, A, KL], lengthK: Aux[K, KLen], split: Aux[KL, KLen, (K, A)]): Codec[KL]

    When called on a Codec[L] for some L <: HList, returns a new codec the encodes/decodes the HList K followed by the HList L.

    When called on a Codec[L] for some L <: HList, returns a new codec the encodes/decodes the HList K followed by the HList L.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  9. def :~>:[B](codecB: Codec[B])(implicit arg0: Monoid[B]): Codec[::[A, HNil]]

    When called on a Codec[A], returns a new codec that encodes/decodes B :: A :: HNil.

    When called on a Codec[A], returns a new codec that encodes/decodes B :: A :: HNil. HList equivalent of ~>.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  10. def :~>:[B](codec: Codec[B])(implicit arg0: Monoid[B]): Codec[A]

    When called on a Codec[L] for some L <: HList, returns a new codec that encodes/decodes B :: L but only returns L.

    When called on a Codec[L] for some L <: HList, returns a new codec that encodes/decodes B :: L but only returns L. HList equivalent of ~>.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  11. final def <~[B](codecB: Codec[B])(implicit arg0: Monoid[B]): Codec[A]

    Creates a Codec[A] that: encodes an A followed by the zero element of the Monoid of B; decodes an A followed by a B and discards the decoded B.

    Creates a Codec[A] that: encodes an A followed by the zero element of the Monoid of B; decodes an A followed by a B and discards the decoded B.

    Operator alias of dropRight.

  12. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  13. def >>:~[L <: HList](f: (A) ⇒ Codec[L]): Codec[::[A, L]]

    Creates a new codec that encodes/decodes an HList type of A :: L given a function A => Codec[L].

    Creates a new codec that encodes/decodes an HList type of A :: L given a function A => Codec[L]. This allows later parts of an HList codec to be dependent on earlier values. Operator alias for flatPrepend.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  14. final def >>~[B](f: (A) ⇒ Codec[B]): Codec[(A, B)]

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A.

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A. Operator alias for flatZip.

  15. final def as[B](implicit as: CodecAsAux[B, A]): Codec[B]

    Returns a new codec that encodes/decodes a value of type B by using an isomorphism between A and B.

    Returns a new codec that encodes/decodes a value of type B by using an isomorphism between A and B.

    The isomorphism is provided by the implicit CodecAsAux instance.

    Typically used when B is a case class and A is an HList with the same shape as the elements of B.

  16. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  17. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def compact: Codec[A]

    Converts this codec to a new codec that compacts the encoded bit vector before returning it.

    Converts this codec to a new codec that compacts the encoded bit vector before returning it.

    Definition Classes
    CodecGenCodecEncoder
  19. final def complete: Codec[A]

    Converts this codec to a new codec that fails decoding if there are remaining bits.

    Converts this codec to a new codec that fails decoding if there are remaining bits.

    Definition Classes
    CodecGenCodecDecoder
  20. def contramap[C](f: (C) ⇒ A): GenCodec[C, A]

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => A.

    Converts this GenCodec to a GenCodec[C, B] using the supplied C => A.

    Definition Classes
    GenCodecEncoder
  21. final def decodeValidValue(bits: BitVector): A

    Decodes a value of type A from the specified bit vector and discards any remaining bits, throwing an IllegalArgumentException if an error occurs.

    Decodes a value of type A from the specified bit vector and discards any remaining bits, throwing an IllegalArgumentException if an error occurs.

    bits

    bits to decode

    returns

    the decoded value

    Definition Classes
    Decoder
    Exceptions thrown
    IllegalArgumentException

    if a decoding error occurs

  22. final def decodeValue(bits: BitVector): \/[String, A]

    Attempts to decode a value of type A from the specified bit vector and discards any remaining bits.

    Attempts to decode a value of type A from the specified bit vector and discards any remaining bits.

    bits

    bits to decode

    returns

    error if value could not be decoded or the decoded value

    Definition Classes
    Decoder
  23. final def dropLeft[B](codecB: Codec[B])(implicit ma: Monoid[A]): Codec[B]

    Creates a Codec[B] that: encodes the zero element of the Monoid of A followed by a B; decodes an A followed by a B and discards the decoded A.

  24. final def dropRight[B](codecB: Codec[B])(implicit arg0: Monoid[B]): Codec[A]

    Creates a Codec[A] that: encodes an A followed by the zero element of the Monoid of B; decodes an A followed by a B and discards the decoded B.

  25. def dropUnits[M <: HList](implicit fltr: Aux[A, Unit, M], ru: ReUnit[A, M]): Codec[M]

    Creates a new codec with all unit values filtered out.

    Creates a new codec with all unit values filtered out.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  26. final def encodeValid(value: A): BitVector

    Encodes the specified value in to a bit vector, throwing an IllegalArgumentException if encoding fails.

    Encodes the specified value in to a bit vector, throwing an IllegalArgumentException if encoding fails.

    value

    value to encode

    Definition Classes
    Encoder
    Exceptions thrown
    IllegalArgumentException

    upon encoding failure

  27. def ensuring(cond: (Codec[A]) ⇒ Boolean, msg: ⇒ Any): Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to Ensuring[Codec[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  28. def ensuring(cond: (Codec[A]) ⇒ Boolean): Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to Ensuring[Codec[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  29. def ensuring(cond: Boolean, msg: ⇒ Any): Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to Ensuring[Codec[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  30. def ensuring(cond: Boolean): Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to Ensuring[Codec[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  31. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  32. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  33. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. def flatMap[B](f: (A) ⇒ Decoder[B]): Decoder[B]

    Converts this decoder to a Decoder[B] using the supplied A => Decoder[B].

    Converts this decoder to a Decoder[B] using the supplied A => Decoder[B].

    Definition Classes
    Decoder
  35. def flatPrepend[L <: HList](f: (A) ⇒ Codec[L]): Codec[::[A, L]]

    Creates a new codec that encodes/decodes an HList type of A :: L given a function A => Codec[L].

    Creates a new codec that encodes/decodes an HList type of A :: L given a function A => Codec[L]. This allows later parts of an HList codec to be dependent on earlier values.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  36. final def flatZip[B](f: (A) ⇒ Codec[B]): Codec[(A, B)]

    Returns a new codec that encodes/decodes a value of type (A, B) where the codec of B is dependent on A.

  37. def flatZipHList[B](f: (A) ⇒ Codec[B]): Codec[::[A, ::[B, HNil]]]

    Creates a new codec that encodes/decodes an HList type of A :: B :: HNil given a function A => Codec[B].

    Creates a new codec that encodes/decodes an HList type of A :: B :: HNil given a function A => Codec[B]. If B is an HList type, consider using flatPrepend instead, which avoids nested HLists. This is the direct HList equivalent of flatZip.

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  38. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from Codec[A] to StringFormat[Codec[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  39. final def fuse[AA <: A, BB >: A](implicit ev: =:=[BB, AA]): Codec[BB]

    Converts this generalized codec in to a non-generalized codec assuming A and B are the same type.

    Converts this generalized codec in to a non-generalized codec assuming A and B are the same type.

    Definition Classes
    GenCodec
  40. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  41. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  42. final def hlist: Codec[::[A, HNil]]

    Lifts this codec in to a codec of a singleton hlist.

  43. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  44. def map[C](f: (A) ⇒ C): GenCodec[A, C]

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => C.

    Converts this GenCodec to a GenCodec[A, C] using the supplied B => C.

    Definition Classes
    GenCodecDecoder
  45. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  46. final def notify(): Unit

    Definition Classes
    AnyRef
  47. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  48. final def pairedWith[B](codecB: Codec[B]): Codec[(A, B)]

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

  49. def pcontramap[B](f: (B) ⇒ Option[A]): Encoder[B]

    Converts this encoder to an Encoder[B] using the supplied partial function from B to A.

    Converts this encoder to an Encoder[B] using the supplied partial function from B to A. The encoding will fail for any B that f maps to None.

    Definition Classes
    Encoder
  50. def polyxmap[B](p: Poly, q: Poly)(implicit aToB: Aux[p.type, ::[A, HNil], B], bToA: Aux[q.type, ::[B, HNil], A]): Codec[B]

    Polymorphic function version of xmap.

    Polymorphic function version of xmap.

    When called on a Codec[A] where A is not a subytpe of HList, returns a new codec that's the result of xmapping with p and q, using p to convert from A to B and using q to convert from B to A.

    p

    polymorphic function that converts from A to B

    q

    polymorphic function that converts from B to A

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  51. def polyxmap[M <: HList](p: Poly, q: Poly)(implicit lToM: Aux[p.type, A, M], mToL: Aux[q.type, M, A]): Codec[M]

    Polymorphic function version of xmap.

    Polymorphic function version of xmap.

    When called on a Codec[L] for some L <: HList, returns a new codec that's the result of xmapping with p and q, using p to convert from L to M and using q to convert from M to L.

    p

    polymorphic function that converts from L to M

    q

    polymorphic function that converts from M to L

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  52. def polyxmap1[B](p: Poly)(implicit aToB: Aux[p.type, ::[A, HNil], B], bToA: Aux[p.type, ::[B, HNil], A]): Codec[B]

    Polymorphic function version of xmap that uses a single polymorphic function in both directions.

    Polymorphic function version of xmap that uses a single polymorphic function in both directions.

    When called on a Codec[A] where A is not a subytpe of HList, returns a new codec that's the result of xmapping with p for both forward and reverse directions.

    p

    polymorphic function that converts from A to B and from B to A

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  53. def polyxmap1[M <: HList](p: Poly)(implicit m: Aux[p.type, A, M], m2: Aux[p.type, M, A]): Codec[M]

    Polymorphic function version of xmap that uses a single polymorphic function in both directions.

    Polymorphic function version of xmap that uses a single polymorphic function in both directions.

    When called on a Codec[L] for some L <: HList, returns a new codec that's the result of xmapping with p for both forward and reverse directions.

    p

    polymorphic function that converts from L to M and from M to L

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Definition Classes
    HListCodecEnrichedWithHListSupport
  54. final def pxmap[B](f: (A) ⇒ B, g: (B) ⇒ Option[A]): Codec[B]

    Maps to a codec of type B, where there is a partial function from B to A.

    Maps to a codec of type B, where there is a partial function from B to A. The encoding will fail for any B that g maps to None.

  55. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  56. def toString(): String

    Definition Classes
    AnyRef → Any
  57. final def unit(zero: A): Codec[Unit]

    Converts this to a Codec[Unit] that encodes using the specified zero value and decodes a unit value when this codec decodes an A successfully.

  58. final def unitM(implicit ma: Monoid[A]): Codec[Unit]

    Converts this to a Codec[Unit] that encodes using the zero value of the implicitly available Monoid[A] and decodes a unit value when this codec decodes an A successfully.

  59. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  60. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  61. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  62. final def withToString(str: String): Codec[A]

    Creates a new codec that is functionally equivalent to this codec but returns the specified string from toString.

  63. final def xmap[B](f: (A) ⇒ B, g: (B) ⇒ A): Codec[B]

    Maps to a codec of type B using two total functions, A => B and B => A.

  64. final def ~[B](codecB: Codec[B]): Codec[(A, B)]

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Creates a Codec[(A, B)] that first encodes/decodes an A followed by a B.

    Operator alias for pairedWith.

  65. final def ~>[B](codecB: Codec[B])(implicit ma: Monoid[A]): Codec[B]

    Creates a Codec[B] that: encodes the zero element of the Monoid of A followed by a B; decodes an A followed by a B and discards the decoded A.

    Creates a Codec[B] that: encodes the zero element of the Monoid of A followed by a B; decodes an A followed by a B and discards the decoded A.

    Operator alias of dropLeft.

  66. def [B](y: B): (Codec[A], B)

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ArrowAssoc[Codec[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. val self: Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to ValueCodecEnrichedWithHListSupport[A] performed by method ValueCodecEnrichedWithHListSupport in scodec.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (codec: ValueCodecEnrichedWithHListSupport[A]).self
    Definition Classes
    ValueCodecEnrichedWithHListSupport
  2. val self: Codec[A]

    Implicit information
    This member is added by an implicit conversion from Codec[A] to HListCodecEnrichedWithHListSupport[A] performed by method HListCodecEnrichedWithHListSupport in scodec. This conversion will take place only if A is a subclass of HList (A <: HList).
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (codec: HListCodecEnrichedWithHListSupport[A]).self
    Definition Classes
    HListCodecEnrichedWithHListSupport

Inherited from GenCodec[A, A]

Inherited from Decoder[A]

Inherited from Encoder[A]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion ValueCodecEnrichedWithHListSupport from Codec[A] to ValueCodecEnrichedWithHListSupport[A]

Inherited by implicit conversion HListCodecEnrichedWithHListSupport from Codec[A] to HListCodecEnrichedWithHListSupport[A]

Inherited by implicit conversion any2stringadd from Codec[A] to any2stringadd[Codec[A]]

Inherited by implicit conversion StringFormat from Codec[A] to StringFormat[Codec[A]]

Inherited by implicit conversion Ensuring from Codec[A] to Ensuring[Codec[A]]

Inherited by implicit conversion ArrowAssoc from Codec[A] to ArrowAssoc[Codec[A]]

Primary Members

Basic Combinators

Tuple Support

HList Support

Ungrouped