
Facilitates the serialization and deserialization of objects into byte arrays, supporting binary data protocols. Offers processor options, custom serializers, and deserializers through annotations for greater flexibility.
Bytonio (said Byte on IO) is a library and a KSP processor intended to ease the serialization and deserialization of Kotlin objects into ByteArray, to be used in protocols that use binary data. The goal is to be purely compatible with Kotlin Multiplatform, without using any platform specific library.
Those examples are for a Kotlin Multiplatform module.
Add the KSP plugin:
plugins {
id("com.google.devtools.ksp")
}Add the core library as a dependency:
sourceSets {
commonMain {
dependencies {
api("net.cacheux.bytonio:bytonio-core:<version>")
...
}
}
...
}Add the KSP processor for platforms you want to have their own code generated:
dependencies {
add("kspCommonMainMetadata", "net.cacheux.bytonio:bytonio-processor:<version>")
add("kspJvm", "net.cacheux.bytonio:bytonio-processor:<version>")
add("kspAndroid", "net.cacheux.bytonio:bytonio-processor:<version>")
}For a JVM or Android library, you can add both dependencies like this:
dependencies {
api("net.cacheux.bytonio:bytonio-core:<version>")
ksp("net.cacheux.bytonio:bytonio-processor:<version>")
}bytonio)int, short and byte. Default is int.littleEndian
and bigEndian. Default is bigEndian.Example:
ksp {
arg("bytonio.packageName", "net.cacheux.generated")
arg("bytonio.dataSizeFormat", "short")
arg("bytonio.byteOrder", "littleEndian")
}Classes annotated with @DataObject will have a serializer and a deserializer class created, as
well as extension methods getBinarySize() and toByteArray(), if these are not already
existing for the class.
These classes must have a constructor with one or more arguments with type supported by the
processor : Int, Short, Byte, ByteArray, or another data type which have the @DataObject
annotation.
You can have ignored arguments of any type, annotated with @IgnoreEncoding, but they must have
a default value that will be used during deserialization.
Numeric arguments can be encoded using a different type than the one used in the class, by using
annotations @EncodeAsByte, @EncodeAsShort and @EncodeAsInt.
A class annotated with @DataObject can also have custom serializers and deserializers that will
be used instead of the one generated. This is also a way to have different types for constructor
arguments. Use @Serializer and @Deserializer annotations to specify them.
Bytonio (said Byte on IO) is a library and a KSP processor intended to ease the serialization and deserialization of Kotlin objects into ByteArray, to be used in protocols that use binary data. The goal is to be purely compatible with Kotlin Multiplatform, without using any platform specific library.
Those examples are for a Kotlin Multiplatform module.
Add the KSP plugin:
plugins {
id("com.google.devtools.ksp")
}Add the core library as a dependency:
sourceSets {
commonMain {
dependencies {
api("net.cacheux.bytonio:bytonio-core:<version>")
...
}
}
...
}Add the KSP processor for platforms you want to have their own code generated:
dependencies {
add("kspCommonMainMetadata", "net.cacheux.bytonio:bytonio-processor:<version>")
add("kspJvm", "net.cacheux.bytonio:bytonio-processor:<version>")
add("kspAndroid", "net.cacheux.bytonio:bytonio-processor:<version>")
}For a JVM or Android library, you can add both dependencies like this:
dependencies {
api("net.cacheux.bytonio:bytonio-core:<version>")
ksp("net.cacheux.bytonio:bytonio-processor:<version>")
}bytonio)int, short and byte. Default is int.littleEndian
and bigEndian. Default is bigEndian.Example:
ksp {
arg("bytonio.packageName", "net.cacheux.generated")
arg("bytonio.dataSizeFormat", "short")
arg("bytonio.byteOrder", "littleEndian")
}Classes annotated with @DataObject will have a serializer and a deserializer class created, as
well as extension methods getBinarySize() and toByteArray(), if these are not already
existing for the class.
These classes must have a constructor with one or more arguments with type supported by the
processor : Int, Short, Byte, ByteArray, or another data type which have the @DataObject
annotation.
You can have ignored arguments of any type, annotated with @IgnoreEncoding, but they must have
a default value that will be used during deserialization.
Numeric arguments can be encoded using a different type than the one used in the class, by using
annotations @EncodeAsByte, @EncodeAsShort and @EncodeAsInt.
A class annotated with @DataObject can also have custom serializers and deserializers that will
be used instead of the one generated. This is also a way to have different types for constructor
arguments. Use @Serializer and @Deserializer annotations to specify them.