Package-level declarations

Bipack is a common kotlinx serializer that works pretty much like any other kotlinx.serialization format. You just mark your class as @Serializable and it does the rest.

There are also special annotation to fine tune the format: Extendable, Framed, CrcProtected for classes and Unsigned for integer data fields.

Types

Link copied to clipboard
class BipackDecoder(val input: DataSource, var elementsCount: Int = 0, val isCollection: Boolean = false, val hasFixedSize: Boolean = false) : AbstractDecoder

Decode BiPack format. Note that it relies on DataSource so can throw DataSource.EndOfData excpetion. Specific frames when used can throw InvalidFrameException and its derivatives.e

Link copied to clipboard
class BipackEncoder(val output: DataSink) : AbstractEncoder
Link copied to clipboard
@SerialInfo
annotation class CrcProtected

Allow to CRC-protect structures (we suppose to use it with classes only). After the data block its CRC32 will be written and checked. It is memory-wise: it calculates CRC on the fly without buffering the data. If used with Framed and Extendable the extra data is protected too.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
@SerialInfo
annotation class Extendable

To be used with kotlinx.serialization.Serializable. Allows serialized classes to be extended by adding members with default initializers to the end of the constructor list.

Link copied to clipboard
annotation class Fixed

Fixed-size number, big-endian. Could be used only with field of following types:

Link copied to clipboard
annotation class FixedSize(val size: Int)

Fixed size collection of a given size. Use it only with collections!

Link copied to clipboard
@SerialInfo
annotation class Framed

Serializable classes annotated as Framed will have leading checked mark as CRC32 of its name (uses @SerialName internally). On deserializing, if frame will not match the expected name, the InvalidFrameException will be thrown.

Link copied to clipboard
open class InvalidFrameException(reason: String) : Exception
Link copied to clipboard
class InvalidFrameHeaderException(reason: String = "Frame header does not match") : InvalidFrameException
Link copied to clipboard
Link copied to clipboard
annotation class Unsigned

Allow marking data fields as being serialized as unsigned (applicable also to signed fields lite Int, Long and Short, if you are sure they will not be negative). As unsigned types are not cully supported by kotlinx.serialization it is the only way to tell the serialized to use more compact unsigned variable length encoding.

Link copied to clipboard

Functions

Link copied to clipboard
inline fun <T> ByteArray.decodeFromBipack(): T
inline fun <T> UByteArray.decodeFromBipack(): T
Link copied to clipboard
inline fun <T> toBipackByteArray(value: T): ByteArray
Link copied to clipboard
inline fun <T> toBipackUByteArray(value: T): UByteArray