WrongCollectionSize exception added and more docs

This commit is contained in:
Sergey Chernov 2023-03-31 21:14:02 +01:00
parent ba6bf7eb37
commit 5b8df2ff20
2 changed files with 11 additions and 3 deletions

View File

@ -63,7 +63,7 @@ class BipackEncoder(val output: DataSink) : AbstractEncoder() {
if (fixedSize < 0)
encodeUInt(collectionSize.toUInt())
else if (collectionSize != fixedSize) {
throw IllegalArgumentException("collection size is $collectionSize while fixed size of $fixedSize is required")
throw WrongCollectionSize("collection size is $collectionSize while fixed size of $fixedSize is required")
}
return this
}

View File

@ -44,16 +44,24 @@ annotation class CrcProtected
* it is the conly way to tell the serialized to use more compact unsigned variable length encoding.
*/
@SerialInfo
@Target(AnnotationTarget.FIELD,AnnotationTarget.PROPERTY)
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
annotation class Unsigned
/**
* Use it with collection of fixed size, like hash digest, key bits and so on, by not storing collection
* size. It effectively reduced packed size to at least one byte. depending on the actual
* collection size. As for nowonly collection types (e.g. ByteArray, List<T>m etc) are supported.
* Note that if the actual collection size differs from [size], [BipackEncoder] will throw
* [WrongCollectionSize] while encoding it.
*/
@SerialInfo
@Target(AnnotationTarget.FIELD,AnnotationTarget.PROPERTY)
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
annotation class FixedSize(val size: Int)
open class InvalidFrameException(reason: String) : Exception(reason)
class InvalidFrameHeaderException(reason: String = "Frame header does not match") : InvalidFrameException(reason)
class InvalidFrameCRCException : InvalidFrameException("Checksum CRC32 failed")
class WrongCollectionSize(reason: String) : Exception(reason)