zhukov-protobuf


License

License

Categories

Categories

Protobuf Data Data Structures
GroupId

GroupId

com.github.fomkin
ArtifactId

ArtifactId

zhukov-protobuf_2.12
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

zhukov-protobuf
zhukov-protobuf
Project URL

Project URL

https://github.com/fomkin/zhukov
Project Organization

Project Organization

com.github.fomkin
Source Code Management

Source Code Management

https://github.com/fomkin/zhukov

Download zhukov-protobuf_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.fomkin/zhukov-protobuf_2.12/ -->
<dependency>
    <groupId>com.github.fomkin</groupId>
    <artifactId>zhukov-protobuf_2.12</artifactId>
    <version>0.4.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.fomkin/zhukov-protobuf_2.12/
implementation 'com.github.fomkin:zhukov-protobuf_2.12:0.4.0'
// https://jarcasting.com/artifacts/com.github.fomkin/zhukov-protobuf_2.12/
implementation ("com.github.fomkin:zhukov-protobuf_2.12:0.4.0")
'com.github.fomkin:zhukov-protobuf_2.12:jar:0.4.0'
<dependency org="com.github.fomkin" name="zhukov-protobuf_2.12" rev="0.4.0">
  <artifact name="zhukov-protobuf_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.fomkin', module='zhukov-protobuf_2.12', version='0.4.0')
)
libraryDependencies += "com.github.fomkin" % "zhukov-protobuf_2.12" % "0.4.0"
[com.github.fomkin/zhukov-protobuf_2.12 "0.4.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8

Project Modules

There are no modules declared in this project.

Zhukov

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.

Implemented features

  1. Case classes to messages
  2. Default case class parameters
  3. Sealed traits to messages with oneof
  4. Autoderivation
  5. Recursive types

Plan

  1. Polymorphic messages (when the value of the type parameter known only in runtime).
  2. Code generator for .proto files.
  3. gRPC services
  4. Optional code generation from .proto files.

Usage

Autoderivation

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)

Implementing bytes

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)
}

Versions

Version
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.1
0.1.0