SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.google.protobuf.ByteString
  2.  
  3. object Test {
  4.   def main(args: Array[String]): Unit = {
  5.     import me.lyh.protobuf.generic.proto.Schemas.Optional
  6.     import me.lyh.protobuf.{generic => pg}
  7.  
  8.     val jsonSchema = pg.Schema.of[Optional].toJson
  9.     val bytes = Optional.newBuilder()
  10.       .setStringField("hello world")
  11.       .setBytesField(ByteString.copyFromUtf8("bytes"))
  12.       .setInt32Field(1)
  13.       .setDoubleField(1.0)
  14.       .setBoolField(true)
  15.       .build()
  16.       .toByteArray
  17.  
  18.     // generic reader
  19.     val schema = pg.Schema.fromJson(jsonSchema)
  20.     val reader = pg.GenericReader.of(schema)
  21.     val record = reader.read(bytes)
  22.     println(schema.toJson)
  23.     println(record.get("string_field").asInstanceOf[String])
  24.   }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top