- Upgraded to scodec-bits 1.1.0
- Added new
bitsRemaining
codec, which decodestrue
if a non-empty vector is encountered. - Fixed bug in
listOfN
/vectorOfN
such that decoding now fails if less thann
elements are decoded. - Added
framing
toCoproductCodecBuilder
, allowing aCodecTransformation
to be applied to all cases. - Added support for deriving recursive case classes and ADTs.
- Added support for
as
combinator onEncoder
andDecoder
. - Added support for packed decimals (
pbcd
,vpbcd
). - Added
sizedList
/sizedVector
codecs, which encode/decode collections of a statically known size. - Fixed bug in
variableSizeBytes
where, if the wrapped codec generates a vector which has a size not evenly divisible by 8, the vector was truncated to next lowest byte boundary.
- Restored support for Android 4.3 and lower.
- Deprecated
DecodingContext
, as it is equal in power toflatMap
onCodec
/Decoder
. - Added
bind
method toDiscriminated
, allowing less boilerplate in creatingDiscriminator
instances. - Fixed bug in
listDelimited
codec. - Minor optimizations, including faster
UUID
codec and upgrade to scodec-bits 1.0.10, which has additional performance improvements.
- Added
xmapc
,exmapc
,narrowc
, andwidenc
methods toCodec
and other types withTransform
instances. These methods are curried versions of their non-curried counterparts, allowing the resulting type to be inferred based on result of first function. For example,bits.xmap[ByteVector](_.bytes, _.bits)
can now be written asbits.xmapc(_.bytes)(_.bits)
. - Added
vint
,vintL
,vlong
, andvlongL
codecs, which encode integers in a variable number of bytes. - Fixed source links in ScalaDoc.
- Upgraded to scodec-bits 1.0.9, shapeless 2.2.4, scala 2.11.7, and scala.js 0.6.4.
- Added support for Scala.js.
- Changed
DiscriminatorCodec#typecase
to take aClassTag
instead of aManfiest
. - Changed
Codec#{upcast,downcast}
to take aTypeable
instance instead of aManifest
, in order to avoid Java reflection. - Changed
withToString
to take its argument by-name, so that string formatting/interpolation only occurs whentoString
is called. - Added
vectorMultiplexed
/listMultiplexed
combinators, for creating aCodec[Vector[A]]
/Codec[List[A]]
from aCodec[A]
and custom multiplexing/demultiplexing logic. - Added
vectorDelimited
/listDelimited
combinators, for creating aCodec[Vector[A]]
/Codec[List[A]]
from aCodec[A]
and a delimiter, expressed as aBitVector
. - Added
cstring
codec, for encoding/decodingUS-ASCII
strings that are terminated by a NUL (0) byte.
- Added
byteAligned
combinator, which right pads aCodec[A]
such that the binary size is always evenly divisible by 8. - Added
decodeValue
back toDecoder
,Codec
, andGenCodec
. - Added
limitedSizeBits
andlimitedSizeBytes
combinators, which behave likefixedSizeBits
/fixedSizeBytes
but perform no padding. - Added support for value codec framing to
DiscriminatorCodec
and auto-generated coproduct codecs. SeeTlvExample
for usage. - Added
fallback
anddiscriminatorFallback
combinators. - Added
variableSizePrefixed{Bits,Bytes}
andvariableSizePrefixed{Bits,Bytes}Long
combinators for working with binary shapes likesize ++ prefix ++ value
wheresize
encodes the length ofvalue
. - The
.as[CaseClass]
syntax now automatically drops unit values from theHList
representation. - Improved support for derived fields in
HList
codecs -- fields which appear in the binary format but should not appear in theHList
type. See ProductExamples.- Added
derive[A].from(f)
syntax onCodec[L]
for someL <: HList
to simplify working with fields whose value are derived from other fields. - Added
consume(f)(g)
syntax onCodec[A]
as an alias for the patternflatPrepend(f).derive[A].from(g)
.
- Added
- Added
filtered
combinator, which allows post-processing of encoded binary and pre-processing of to-be-decoded binary. - Added
checksummed
combinator, which allows simpler checksumming than working with signature codecs.
- Added
string32
,ascii32
, andutf8_32
codecs, which encode a 32-bit 2s complement big endian size field before the string encoding. - Added various combinators for logging results of encoding/decoding --
logBuilder
,logFailuresBuilder
,logSuccessesBuilder
,logToStdOut
, andlogFailuresToStdOut
. - Added
zlib
combinator, which compresses the results of another codec. - Fixed bug where the contents of the scodec-bits jar was included in the scodec-core jar.
- Group id (ivy organization) changed from
org.typelevel
toorg.scodec
. - Upgraded to Shapeless 2.1 and removed the dependency on Scalaz. Users must use Shapeless 2.1.x, as the 2.1 series is not binary compatible with the 2.0 series.
- As a result of the Shapeless 2.1 upgrade, Scala 2.10 users are required to use the Macro Paradise compiler plugin. Scala 2.11 users do not need Macro Paradise. For cross builds, the following SBT setting will add the plugin to only your 2.10 build:
// Shapeless 2.1.0 on Scala 2.10 requires macro paradise
libraryDependencies ++= {
if (scalaBinaryVersion.value startsWith "2.10") Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)) else Nil
}
- Derived codecs now work for arbitrarily complex structures. In previous versions, deriving codecs for some complex types would result in implicit divergence, requiring, for instance, users to manually define implicit codecs for each component type before deriving a product codec. These limitations have been removed.
- Related to the fixes for derivation of complex structures, the
ImplicitCodec
andDerivedCodec
types have been removed in favor ofshapeless.Lazy[Codec[A]]
. If authoring combinators that require implicit codecs, useLazy[Codec[A]]
instead ofCodec[A]
orImplicitCodec[A]
. The same advice holds for implicit encoders and decoders -- useLazy[Encoder[A]]
andLazy[Decoder[A]]
. - All uses of
scalaz.\/
were replaced withscodec.Attempt
, which is isomorphic toErr \/ ?
. See the ScalaDoc forAttempt
for combinators. Some specific notes:- The return type of
encode
has changed fromErr \/ BitVector
toAttempt[BitVector]
. - The return type of
decode
has changed fromErr \/ (BitVector, A)
toAttempt[DecodeResult[A]]
.DecodeResult
is a case class that contains both theA
value as well as the remainderBitVector
. It contains two useful methods,map
andmapRemainder
, which makes it nicer to work with thanTuple2
. - Replace
codec.encodeValid(a)
withcodec.encode(a).require
- Replace
codec.decodeValid(a)
withcodec.decode(a).require
- Replace
codec.decodeValidValue(a)
withcodec.decode(a).require.value
- The return type of
- Scalaz type class instances moved to the
scodec.interop.scalaz
package, in the scodec-scalaz library. This library contains additional conveniences for Scalaz users, like syntax for converting betweenAttempt[A]
andErr \/ A
. In general, you should importscodec.interop.scalaz._
. - Another new interop library is available as of scodec-core 1.7 -- scodec-spire, which provides codecs for unsigned numeric types.
scodec.DecodingContext
is significantly faster. If you previously avoided using it due to performance overhead, retest the new implementation.- Dramatically improved compile time of
dropUnits
- Introduced new
codec.flattenLeftPairs
combinator, which converts aCodec[(((A, B), C, ...)]
to aCodec[A :: B :: C :: ... :: HNil]
- Introduced new combinators for building
Tuple3
throughTuple12
codecs and binding the results to case classes. Callinga ~~ b
wherea: Codec[TupleM[...]]
results in aCodec[TupleN[..., B]]
whereN = M + 1
. The~~
operator differs from~
in that it returns a codec for a tuple of one higher arity than the left hand side codec. And specifically, it returns ascodec.codecs.TupleNCodec
, whereN
is replaced by the arity. To bind aTupleNCodec
to a case class, callwidenAs(Foo.apply, Foo.unapply)
. The advantage of using~~
is that aTupleN
is created directly when decoding, avoiding the nestedTuple2
instances generated by~
. - Introduced a new abstract method on
Encoder
--def sizeBound: SizeBound
, which provides lower and upper bounds on the size of the encoded binary. If a definition forsizeBound
does not apply to a codec, define the method asdef sizeBound = SizeBound.unknown
. The built-combinators have been updated to compute size bounds correctly, even for product and coproduct types.
CoproductCodecBuilder
now supports arbitrary orderings of component types. This is especially useful when creating aCoproductCodecBuilder
for a sealed class, because the order of subtypes in the coproduct representation is chosen by the compiler. See example.- Introduced the
Transform
typeclass, which abstracts the ability toexmap
and provides derived implementations forxmap
,pxmap
,widen
,narrow
, andas
, including Shapeless integration withas
. - Provided instances of
Transform
for bothCodec
andCoproductCodecBuilder
. - Added various combinators to
Codec
:upcast
downcast
toFieldWithContext
- Introduced
KnownDiscriminatorType[D]
mixin. - Modified discriminated coproduct codecs and
DiscriminatorCodec
to raiseKnownDiscriminatorType[D]#UnknownDiscriminator
errors. - Added
scodec.codecs.hlist(l)
combinator for converting anHList
of shapeCodec[X0] :: Codec[X1] :: ... :: Codec[Xn] :: HNil
toCodec[X0 :: X1 :: ... :: Xn :: HNil]
. Also available via syntax enrichment,toCodec
, onHList
s of proper shape.
- Due to diverging implicit errors introduced by 1.4.0, the derived codec support was refactored.
For non-generic uses, the syntax is the same -- call
Codec[Foo]
to auto-derive a codec forFoo
. For generic uses, combinators should be changed to take an implicitImplicitCodec[A]
instead of an implicitCodec[A]
. See the issue for more details on the problem and the PR for more details on the new structure. - Fixed a bug in
ushort8
where it was treating binary as a signedshort8
. - Added
withContext
toCodec
-- this is an alias for"context" | codec
.
- Breaking Change - Changed error type from String to
scodec.Err
.Err
is a non-sealed class, allowing codecs to return custom subtypes describing domain specific errors. This allows dispatching on those domain specific errors. To upgrade, instead of returning a string, wrap the string withErr(str)
. See the PR for details. - Added
Codec.coproduct
, which helps createCoproduct
based codecs. See CoproductsExample. - Added support for automatically deriving codecs, based on
Codec.product
andCodec.coproduct
. See DerivedCodecExamples. - Added
scodec.codecs.implicits
, which provides implicit codecs for primitive values and collections. - Updated
paddedFixedSize{Bits,Bytes}Dependent
combinator for building PKCS5/PKCS7 style padding.
- Added
flatAppend
andflatConcat
toHList
based codecs. - Added
Codec.product
, which automatically generatesHList
based codecs for case classes andHList
types if all component types have implicit codecs available. See ProductsExample. - Added the
toField
combinator toCodec
, allowing creation of Shapeless field codecs from value codecs. That is,toField[K]
onCodec
converts aCodec[A]
to aCodec[FieldType[K, A]]
- Added
variableSize{Bits,Bytes}Long
as alternatives tovariableSize{Bits,Bytes}
, where the size is encoded/decoded via aCodec[Long]
instead of aCodec[Int]
.
- Added support for Shapeless coproduct codecs. See
CoproductCodecTest
for examples. - Added
exmap
toCodec
,emap
toDecoder
andecontramap
toEncoder
- Added
narrow
andwiden
toCodec
- Added ability to lift an
Encoder
to aCodec
viaencodeOnly
and aDecoder
to aCodec
viadecodeOnly
- Added
paddedFixedSize{Bytes,Bits}
combinators - Added numeric codecs for
Short
andByte
- Fixed bug in
constantLenient
where decoding wasn't lenient
- Changed
dropLeft
/~>
anddropRight
/<~
to require aCodec[Unit]
on the dropped side. Previously, the requirement was aCodec[X]
and an implicitly availableMonoid[X]
. To convert aCodec[X]
to aCodec[Unit]
, use theunit
combinator. - Changed size based codecs to use
Long
instead ofInt
sizes.
- Added support for Shapeless coproduct codecs. See
CoproductCodecTest
for examples. - Added
exmap
toCodec
,emap
toDecoder
andecontramap
toEncoder
- Added
narrow
andwiden
toCodec
- Added ability to lift an
Encoder
to aCodec
viaencodeOnly
and aDecoder
to aCodec
viadecodeOnly
- Added
paddedFixedSize{Bytes,Bits}
combinators - Added numeric codecs for
Short
andByte
- Fixed bug in
constantLenient
where decoding wasn't lenient
- Added
fail
combinator - Added
mappedEnum
combinator - Added
vector
andlist
combinators and deprecatedrepeated
- Added
vectorOfN
andlistOfN
combinators for count encoded values - Added
unit
andunitM
combinators to convert aCodec[A]
to aCodec[Unit]
- Added
scodec.codecs.literals._
for implicitly converting literal values to constant codecs. - Added
constantLenient
codec that's equivalent toconstant
but does not validate that the decoded bits equal the constant value - Improved support for
as
method:- Better compiler error message when an implicit
CodecAsAux
is not found - Support for reverse bindings (e.g.,
Codec[Point3D].as[Int :: Int :: Int :: HNil]
) - Support for singleton bindings without having to first lift
Codec[A]
toCodec[A :: HNil]
(e.g.,case class Foo(x: Int); uint8.as[Foo]
)
- Better compiler error message when an implicit
- Added
optional
combinator - Added
withDefault
andwithDefaultValue
combinators - Added
recover
andlookahead
combinators - Added
dropUnits
combinator forHList
codecs, greatly simplifying creation of codecs that have unit values due to use ofconstant
orignore
. For example,(uint8 :: ignore(4) :: uint4 :: ignore(3) :: uint5).dropUnits
results in aCodec[Int :: Int :: Int :: HNil]
- Added support for xmapping polymorphic functions via
polyxmap
andpolyxmap
combinators polyxmap
takes 2 polymorphic functions, forward and reversepolyxmap1
takes 1 polymorphic function that's used in both directions- both combinators work on
HList
codecs and value codecs
- Upgraded to Scalaz 7.1.0
- Published ScalaDoc links in POM so that other projects can link to ScalaDoc
- Upgraded to Shapeless 2
- Added
endiannessDependent
combinator - Used
scodec.bits.ByteOrdering
instead of a boolean for indicating big endian vs little endian - Significant performance improvements
- Upgrade to scodec-bits 1.0.0-RC2
- Added
bits
andbytes
codecs that behave likebits(size)
/bytes(size)
but with no size constraint - Replaced discriminator support with new implementation that is much more general (thanks to Paul C)
- Removed
Codec.{ encode, decode }
overloads that aliasedCodec#{ encode, decode }
- Introduced
encodeValid
,decodeValue
, anddecodeValidValue
methods on both theCodec
class and object - Added new combinators (
lazily
,complete
,compact
) - API docs
- Removed unnecessary dependencies from pom
- Changed group id from com.github.scodec to org.typelevel
- Changed artifact id from scodec to scodec-core
- Deprecated
scodec.{ BitVector, ByteVector }
in favor ofscodec.bits.{ BitVector, ByteVector }
- Deprecated forwarders will be removed in M3
- Reduced public API
- made many types package private
- removed methods from
Codec
companion that existed directly onCodec
- JAR restructuring
- scodec-bits: no dependency JAR containing BitVector, ByteVector, and supporting types
- scodec: dependds on scodec-bits and adds encoding/decoding capabilities
- See scodec-bits for list of improvements to BitVector and ByteVector
- Package restructuring
- scodec.bits package contains BitVector, ByteVector, and supporting types
- scodec package contains main abstractions of encoding/decoding
- scodec.codecs package contains reusable codecs
- Encoder, Decoder, and GenCodec abstractions, which allow simpler transforms if a full Codec is not required