Code Monkey home page Code Monkey logo

zhukov's Introduction

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

zhukov's People

Contributors

fomkin avatar chicker avatar vovapolu avatar letalvoj avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.