some texts fixed

This commit is contained in:
Sergey Chernov 2023-04-01 17:27:16 +01:00
parent 641188e92b
commit 6ae2e9f885
5 changed files with 19 additions and 15 deletions

View File

@ -32,7 +32,7 @@ used automatically when serializing integers. It is slightly more sophisticated
### - 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
many aspets, it has a clear disadvantages: it uses more space, and it reveals inner data structure to the world. It is
possible to unpack such formats with zero information about inner structure.
Bipack does not store field names, so it is not possible to unpack or interpret it without knowledge of the data
@ -100,7 +100,7 @@ This __field annontation__ allows to store __integer fields__ of any size more c
## @FixedSize(size)
Use it with fixed-size collections (like hashes, keys, etc) to not to keep collection size in the packed binary. It saves at least one byte.
Use it with fixed-size collections (like hashes, keys, etc.) to not keep collection size in the packed binary. It saves at least one byte.
## @Fixed

View File

@ -5,7 +5,7 @@ This library contains a `Bipack` binary format serializer, see [net.sergeych.bip
# Package net.sergeych.bipack
Bipack ais 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.
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.
- [BipackEncoder] to serializes anything to bipack format.
- [BipackDecoder] deserializes from bipack back.

View File

@ -53,7 +53,7 @@ fun bytesToLong(b: ByteArray): Long {
}
fun bytesToInt(b: ByteArray): Int {
var result: Int = 0
var result = 0
for (i in 0 until 4) {
result = result shl 8
result = result or (b[i].toInt() and 0xFF)
@ -62,7 +62,7 @@ fun bytesToInt(b: ByteArray): Int {
}
fun bytesToShort(b: ByteArray): Short {
var result: Int = 0
var result = 0
for (i in 0 until 2) {
result = result shl 8
result = result or (b[i].toInt() and 0xFF)
@ -85,7 +85,7 @@ private val hexDigits = "0123456789ABCDEF"
fun Long.encodeToHex(length: Int = 0): String {
var result = ""
var value = this
var end = if( value >= 0 ) 0L else -1L
val end = if( value >= 0 ) 0L else -1L
// if (value < 0) throw IllegalArgumentException("cant convert to hex negative (ambiguous)")
do {
result = hexDigits[(value and 0x0f).toInt()] + result
@ -98,12 +98,16 @@ fun Long.encodeToHex(length: Int = 0): String {
fun Int.encodeToHex(length: Int = 0) = (toLong() and 0xFFFFffff).encodeToHex(length)
@Suppress("unused")
fun UInt.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
@Suppress("unused")
fun Byte.encodeToHex(length: Int = 0) = (toLong() and 0xFF).encodeToHex(length)
@Suppress("unused")
fun UByte.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
@Suppress("unused")
fun ULong.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
fun ByteArray.encodeToHex(separator: String = " "): String = joinToString(separator) { it.toUByte().encodeToHex(2) }
@Suppress("unused")
fun Collection<Byte>.encodeToHex(separator: String = " "): String = joinToString(separator) { it.toUByte().encodeToHex(2) }
fun ByteArray.toDump(wide: Boolean = false): String = toDumpLines(wide).joinToString("\n")
@ -168,6 +172,7 @@ fun ByteArray.toDumpLines(wide: Boolean = false): List<String> {
return lines
}
@Suppress("unused")
fun String.decodeHex(): ByteArray {
val source = this.trim().uppercase()
val result = arrayListOf<Byte>()
@ -197,4 +202,5 @@ fun ByteArray.flipSelf() {
}
}
@Suppress("unused")
fun ByteArray.flip(): ByteArray = copyOf().also { it.flipSelf() }

View File

@ -2,10 +2,8 @@
package net.sergeych.bintools
import net.sergeych.bintools.*
/**
* Smart variable-length long encoding tools, async. It gives byte-size gain from 64 bits numbers
* Smart variable-length long encoding tools, async. It gives byte-size gain from 64 bits numbers,
* so it is very useful when encoding big numbers or at least very bui long values. In other cases
* [Varint] works faster, and extra bits it uses does not play
*

View File

@ -3,8 +3,8 @@ package net.sergeych.bipack
import kotlinx.serialization.SerialInfo
/**
* If this annotation is presented in some @Serializable class defition, its instances
* will be serialized with leadinf number of fields. This allows to extend class later
* If this annotation is presented in some @Serializable class definition, its instances
* will be serialized with leading number of fields. This allows to extend class later
* providing new parameters __to the end of the class__ and _with default values__.
*
* Whe deserializing such instances from previous version binaries, the new parameters
@ -39,9 +39,9 @@ annotation class Framed
annotation class CrcProtected
/**
* Allow marking data fields as being serialized as usnsigned (applyable also to signed fields lite Int, Long and
* Short, if you are shure they will not be negative). As unsigned types are not cully supported by kotlinx.serialization
* it is the conly way to tell the serialized to use more compact unsigned variable length encoding.
* 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.
*/
@SerialInfo
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
@ -51,7 +51,7 @@ annotation class Unsigned
* Fixed size collection of a given size. __Use it only with collections!__
*
* Use it with collection of fixed size, to read/write exact number of items (for example, bytes),
* like hash digest, key bits and so on. Does not stores/loades the collection
* like hash digest, key bits and so on. Does not store/load the collection
* size what reduces 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