Scala數據序列化:Scalavro

jopen 11年前發布 | 42K 次閱讀 Scalavro Scala開發

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.baiduhome.net/lib/view/home/1385260701432

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!