Scala数据序列化:Scalavro

jopen 10年前

Scalavro 是一个使用反射技术实现的 Avro 库。

Avro是一个数据序列化系统,设计用于支持大 批量数据交换的应用。它的主要特点有:支持二进制序列化方式,可以便捷,快速地处理大量数据;动态语言友好,Avro提供的机制使动态语言可以方便地处理 Avro数据。

Apache Avro ™ is a data serialization system.

Avro provides:

  • Rich data structures.
  • A compact, fast, binary data format.
  • A container file, to store persistent data.
  • Remote procedure call (RPC).
  • Simple integration with dynamic languages. Code generation is not required to read or write data files nor to use or implement RPC protocols. Code generation as an optional optimization, only worth implementing for statically typed languages.

示例代码:

import com.gensler.scalavro.types.AvroType  import scala.util.{ Try, Success, Failure }    // obtaining an instance of AvroType  val intSeqType = AvroType[Seq[Int]]    // obtaining an Avro schema for a given AvroType  intSeqType.schema    // obtaining an AvroTypeIO object for a given AvroType (via the `io` method)  val io: AvroTypeIO[Seq[Int]] = intSeqType.io    // binary I/O  io.write(Seq(1, 2, 3), outputStream)  val Sucess(readResult) = io read inputStream    // json I/O  val json = io writeJson Seq(1, 2, 3) // [1,2,3]  val Success(readResult) = io readJson json

项目主页:http://www.open-open.com/lib/view/home/1385260701432