proto-api


License

License

MIT
GroupId

GroupId

io.github.zero-deps
ArtifactId

ArtifactId

proto-api_2.13
Last Version

Last Version

2.0.4.gdde2aab
Release Date

Release Date

Type

Type

jar
Description

Description

proto-api
proto-api
Project URL

Project URL

https://github.com/zero-deps/proto
Project Organization

Project Organization

io.github.zero-deps
Source Code Management

Source Code Management

https://github.com/zero-deps/proto

Download proto-api_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.zero-deps/proto-api_2.13/ -->
<dependency>
    <groupId>io.github.zero-deps</groupId>
    <artifactId>proto-api_2.13</artifactId>
    <version>2.0.4.gdde2aab</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.zero-deps/proto-api_2.13/
implementation 'io.github.zero-deps:proto-api_2.13:2.0.4.gdde2aab'
// https://jarcasting.com/artifacts/io.github.zero-deps/proto-api_2.13/
implementation ("io.github.zero-deps:proto-api_2.13:2.0.4.gdde2aab")
'io.github.zero-deps:proto-api_2.13:jar:2.0.4.gdde2aab'
<dependency org="io.github.zero-deps" name="proto-api_2.13" rev="2.0.4.gdde2aab">
  <artifact name="proto-api_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.zero-deps', module='proto-api_2.13', version='2.0.4.gdde2aab')
)
libraryDependencies += "io.github.zero-deps" % "proto-api_2.13" % "2.0.4.gdde2aab"
[io.github.zero-deps/proto-api_2.13 "2.0.4.gdde2aab"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.5
com.google.protobuf : protobuf-java jar 3.15.2

Project Modules

There are no modules declared in this project.

proto

version chat test cloc

Lightweight and fast serialization library for Scala 2/3 based on Protocol Buffers with macros magic.

Motivation

Serialization library for Scala that can be used either for long term store models and short term models. With easy to migrate possibility.

  • Lightweight
  • Fast
  • Protocol Buffers compatible
  • No .proto files
  • No model convertation
  • Type safe
  • Serialization/deserialization without changes in models
  • Possibility to use specific types in model

Install

Add dependency:

libraryDependencies += "io.github.zero-deps" %% "proto" % "latest.integration"

Dependency as a git-submodule is also supported.

Benchmark

data library score
data decode java 44079.139
data decode jackson 176941.468
data decode jsoniter-scala 483788.001
data decode boopickle 2885610.648
data decode scalapb 3270691.564
data decode proto 3383845.458
data library score
data encode java 220444.268
data encode jackson 431318.803
data encode kryo-macros 991944.758
data encode jsoniter-scala 1054650.233
data encode boopickle 1520834.519
data encode proto 3186951.441
data encode scalapb 3628779.864
data library score
msg decode jsoniter-scala 3486552.303
msg decode scalapb 4898257.671
msg decode proto 5825174.170
data library score
msg encode jsoniter-scala 6372602.760
msg encode proto 6487748.959
msg encode scalapb 9202135.451

environment

2.8 GHz Quadro-Core Intel Core i7
16 GB 2133 MHz LPDDR3
Java 15.0.1
Scala 2.13.5

run benchmark

sbt
project benchmark
jmh:run -i 2 -wi 1 -f1 -t1

Usage

You can pick one of the way how to define field number:

  • with annotation @proto.N and use caseCodecAuto
  • explicitly specify nums caseCodecNums(Symbol("field1")->1, Symbol("field2")->2)
  • field numbers by index caseCodecIdx

You can use annotation @proto.RestrictedN to restrict usage of specified field numbers. Can be used with classes or traits.

import scala.collection.immutable.TreeMap
import proto.{encode, decode, N}
import proto.{caseCodecIdx, caseCodecNums, caseCodecAuto}

final case class VectorClock(versions: TreeMap[String, Long])
@RestrictedN(3,4)
final case class Equipment(@N(1) id: String, @N(2) tpe: String)
final case class Car(id: String, color: Int, equipment: List[Equipment], vc: VectorClock)

implicit val tuple2Codec = caseCodecIdx[Tuple2[String, Long]] //codec for TreeMap[String, Long]

implicit val vectorClockCodec = caseCodecIdx[VectorClock]
implicit val equipmentCodec = caseCodecAuto[Equipment]
implicit val carCodec = caseCodecNums[Car]('id->1, 'color->4, 'equipment->2, 'vc->3)

val vc = VectorClock(versions=TreeMap.empty)
val equipment = List(Equipment(id="1", tpe="123"), Equipment(id="2", tpe="456"))
val car = Car(id="1", color=16416882, equipment=equipment, vc=vc)
//encode
val bytes: Array[Byte] = encode(car)
//decode
val car2: Car = decode[Car](bytes)

More examples in testing.scala

Publishing

sbt +publishSigned
open https://oss.sonatype.org/#stagingRepositories
io.github.zero-deps

Versions

Version
2.0.4.gdde2aab