https://github.com/nevillelyh/protobuf-generic
Generic protobuf manipulation
https://github.com/nevillelyh/protobuf-generic
json protobuf scala
Last synced: 11 months ago
JSON representation
Generic protobuf manipulation
- Host: GitHub
- URL: https://github.com/nevillelyh/protobuf-generic
- Owner: nevillelyh
- License: apache-2.0
- Created: 2016-10-21T18:40:41.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-05T19:39:46.000Z (over 1 year ago)
- Last Synced: 2024-12-05T20:28:57.395Z (over 1 year ago)
- Topics: json, protobuf, scala
- Language: Scala
- Homepage:
- Size: 479 KB
- Stars: 35
- Watchers: 7
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
protobuf-generic
================
[](https://github.com/nevillelyh/protobuf-generic/actions?query=workflow%3ACI)
[](https://codecov.io/github/nevillelyh/protobuf-generic?branch=master)
[](./LICENSE)
[](https://maven-badges.herokuapp.com/maven-central/me.lyh/protobuf-generic_2.13)
[](https://scala-steward.org)
Manipulate [Protocol Buffers](https://developers.google.com/protocol-buffers/) schemas and records in a generic manner without compiled classes, similar to [Avro](https://avro.apache.org/)'s `GenericRecord`.
# Usage
```scala
import me.lyh.protobuf.generic._
val schema1 = Schema.of[MyRecord] // generic representation of the protobuf schema
val jsonString = schema1.toJson // serialize to JSON
val schema2 = Schema.fromJson(jsonString) // deserialize from JSON
// read protobuf binary without original class
val bytes1: Array[Byte] = // binary MyRecord
val reader = GenericReader.of(schema2)
val record1 = reader.read(bytes1) // generic record, i.e. Map[String, Any]
val jsonRecord = record1.toJson // JSON string
// write protobuf binary without orignal class
val record2 = GenericRecord.fromJson(jsonRecord) // generic record, i.e. Map[String, Any]
val writer = GenericWriter.of(schema2)
val bytes2 = writer.write(record2) // binary MyRecord
```
# License
Copyright 2016 Neville Li.
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0