0.0.3 release: docs, foxed dump formatting

This commit is contained in:
Sergey Chernov 2023-09-28 18:03:47 +01:00
parent ee20bfdee7
commit b7784fec18
4 changed files with 33 additions and 20 deletions

View File

@ -1,9 +1,6 @@
# Binary tools and BiPack serializer
> beta version
Multiplatform binary tools collection, including portable serialization of the compact and fast [Bipack] format, that
works well also in the browser and in native targets.
Multiplatform binary tools collection, including portable serialization of the compact and fast [Bipack] format, and many useful tools to work with binary data, like CRC family checksums, dumps, etc. It works well also in the browser and in native targets.
# Usage
@ -18,14 +15,12 @@ repositories {
And add dependecy to the proper place in yuor project like this:
```
```kotlin
dependencies {
// ...
implementation("net.sergeych:mp_bintools:0.0.2-SNAPSHOT")
implementation("net.sergeych:mp_bintools:0.0.3")
}
```
Use your desired version.
TODO: specify maven: how?
# Bipack
@ -35,9 +30,9 @@ Bipack is a compact and efficient binary serialization library (and format) was
### Allow easy unpacking existing binary structures
Yuo describe your structure as `@Serializable` classes, and - voila, bipack decodes and encodes it for you!
Yuo describe your structure as `@Serializable` classes, and - voila, bipack decodes and encodes it for you! We aim to make it really easy to convert data from other binary formats by adding more format annotations
### - be as compact as possible
### Be as compact as possible
For this reason it is a binary notation, it uses binary form for decimal numbers and can use variery of encoding for
integers:
@ -52,7 +47,7 @@ See `object Varint`.
Variable-length compact encoding for signed and unsigned integers use as few bytes as possible to encode integers. It is
used automatically when serializing integers. It is slightly more sophisticated than straight `Varint`.
### - do not reveal information about stored data
### Do not reveal information about stored data
Many extendable formats, like JSON, BSON, BOSS and may others are keeping data in key-value pairs. While it is good in
many aspets, it has a clear disadvantages: it uses more space, and it reveals inner data structure to the world. It is
@ -68,20 +63,18 @@ backward compatibility with already serialzied data or using volumous boilerplat
versioning.
Not to waste space and reveal more information that needed Bipack allows extending classes marked as [@Extendable] to be
extended with more data _appended to the end of list of fields with required defaul values_. For such classes Bipack
stores number of actually serialized fields and atuomatically uses default values for non-serialized ones when unpacking
extended with more data _appended to the end of list of fields with required defaul values_. For such classes, Bipack stores the number of actually serialized fields and atuomatically uses default values for non-serialized ones when unpacking
old data.
### - protect data with framing and CRC
### Protect data with framing and CRC
When needed, serialization lobrary allow to store/check CRC32 tag of the structure name with `@Framed` (can be overriden
as usual with `@SerialName`), or be followed with CRC32 of the serialized binary data, that will be checked on
deserialization, using `@CrcProtected`. This allows to check the data consistency out of the box and only where needed.
deserialization, using `@CrcProtected`. This allows checking the data consistency out of the box and only where needed.
# Usage
Use kotlinx serializatino as usual. There are following Bipack-specific annotation at your service. All class
annotations could be combined.
Use kotlinx serializatino as usual. There are the following Bipack-specific annotations at your disposal (can be combined):
## @Extendable

View File

@ -8,7 +8,7 @@ plugins {
val serialization_version = "1.3.4"
group = "net.sergeych"
version = "0.0.3-SNAPSHOT"
version = "0.0.3"
repositories {
mavenCentral()
@ -74,6 +74,7 @@ kotlin {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("net.sergeych:mp_stools:1.4.1")
}
}
val jvmMain by getting

View File

@ -118,7 +118,7 @@ fun ByteArray.toDumpLines(wide: Boolean = false): List<String> {
fun dumpChars(_from: Int): String {
var from = _from
val b = StringBuilder(22)
val b = StringBuilder()
b.append('|')
val max: Int = kotlin.math.min(size, from + lineSize)
@ -162,7 +162,7 @@ fun ByteArray.toDumpLines(wide: Boolean = false): List<String> {
if (line != null) {
val l = size
var fill = lineSize - l % lineSize
if( fill > lineSize/2 ) line.append(" ")
if( fill > lineSize/2 && fill < lineSize ) line.append(" ")
if (fill < lineSize) while (fill-- > 0) line.append(" ")
val index = l - l % lineSize
line.append(dumpChars(if (index < l) index else l - lineSize))

View File

@ -0,0 +1,19 @@
package bintools
import net.sergeych.bintools.toDump
import kotlin.test.Test
class TestTools {
@Test
fun testDump() {
// val src =
// "MfsmHUExZpb3xd0X8FVj2MSOxc1dRd-93i3zkmJVhgWH0r8p0Agtg6lc9_TB6srlXJF4MOWT3a_Cfy87W3FTKRzdCdsAEDOBkSL-JANDey4"
// .decodeBase64Url()
// println(src.toDump())
var res = byteArrayOf(0)
for( i in 1..100) {
res += byteArrayOf(i.toByte())
println(res.toDump())
}
}
}