some texts fixed
This commit is contained in:
1 parent
641188e92b
commit
6ae2e9f885
5 files changed
+19
-15
No files matched your search
@@ -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() }
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user