From b7784fec18fb55ab625452fb2efa3856edec2205 Mon Sep 17 00:00:00 2001 From: sergeych Date: Thu, 28 Sep 2023 18:03:47 +0100 Subject: [PATCH] 0.0.3 release: docs, foxed dump formatting --- README.md | 27 +++++++------------ build.gradle.kts | 3 ++- .../net.sergeych.bintools/simple_codecs.kt | 4 +-- src/commonTest/kotlin/bintools/TestTools.kt | 19 +++++++++++++ 4 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 src/commonTest/kotlin/bintools/TestTools.kt diff --git a/README.md b/README.md index 31b4c55..cb20ed9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.gradle.kts b/build.gradle.kts index d76d14f..aad9230 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 diff --git a/src/commonMain/kotlin/net.sergeych.bintools/simple_codecs.kt b/src/commonMain/kotlin/net.sergeych.bintools/simple_codecs.kt index b7e6878..e7c076a 100644 --- a/src/commonMain/kotlin/net.sergeych.bintools/simple_codecs.kt +++ b/src/commonMain/kotlin/net.sergeych.bintools/simple_codecs.kt @@ -118,7 +118,7 @@ fun ByteArray.toDumpLines(wide: Boolean = false): List { 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 { 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)) diff --git a/src/commonTest/kotlin/bintools/TestTools.kt b/src/commonTest/kotlin/bintools/TestTools.kt new file mode 100644 index 0000000..3eff5b2 --- /dev/null +++ b/src/commonTest/kotlin/bintools/TestTools.kt @@ -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()) + } + } +} \ No newline at end of file