Zhukov is a library for marshaling Scala types in Google Protocol Buffers format without writing .proto
files. Unlike other Protocol Buffers libraries, Zhukov doesn't depend on com.google.protobuf : protobuf-java
. It means that you can use desirable implementation of byte sequence without conversion from com.google.protobuf.ByteString
. Zhukov has written using pure Scala macros without generic programming. It's fast in compile time and runtime.
- Case classes to messages
- Default case class parameters
- Sealed traits to messages with
oneof
- Autoderivation
- Recursive types
- Polymorphic messages (when the value of the type parameter known only in runtime).
- Code generator for
.proto
files. - gRPC services
- Optional code generation from
.proto
files.
import zhukov.derivation.auto._
import zhukov.{Marshaller, Unmarshaller}
case class SimpleMessage(myNumber: Int = 0, myString: String = "")
val message = SimpleMessage(42, "cow")
Marshaller[SimpleMessage].write(message)
import zhukov.Bytes
import com.google.protobuf.ByteString
implicit object ByteStringBytes extends Bytes[ByteString] {
def empty: ByteString = ByteString.EMPTY
def copyFromArray(bytes: Array[Byte]): ByteString = ByteString.copyFrom(bytes)
def copyFromArray(bytes: Array[Byte], offset: Long, size: Long): ByteString = ByteString.copyFrom(bytes, offset.toInt, size.toInt)
def copyToArray(value: ByteString, array: Array[Byte], sourceOffset: Int, targetOffset: Int, length: Int): Unit = value.copyTo(array, sourceOffset, targetOffset, length)
def wrapArray(bytes: Array[Byte]): ByteString = ByteString.copyFrom(bytes)
def copyBuffer(buffer: ByteBuffer): ByteString = ByteString.copyFrom(buffer)
def toArray(bytes: ByteString): Array[Byte] = bytes.toByteArray
def toBuffer(bytes: ByteString): ByteBuffer = bytes.asReadOnlyByteBuffer()
def get(bytes: ByteString, i: Long): Int = bytes.byteAt(i.toInt)
def size(bytes: ByteString): Long = bytes.size().toLong
def concat(left: ByteString, right: ByteString): ByteString = left.concat(right)
def slice(value: ByteString, start: Long, end: Long): ByteString = value.substring(start.toInt, end.toInt)
}