ScalavroScala 數(shù)據(jù)序列化
Scalavro 是一個(gè)使用反射技術(shù)實(shí)現(xiàn)的 Avro 庫(kù)。
Avro是一個(gè)數(shù)據(jù)序列化系統(tǒng),設(shè)計(jì)用于支持大 批量數(shù)據(jù)交換的應(yīng)用。它的主要特點(diǎn)有:支持二進(jìn)制序列化方式,可以便捷,快速地處理大量數(shù)據(jù);動(dòng)態(tài)語(yǔ)言友好,Avro提供的機(jī)制使動(dòng)態(tài)語(yǔ)言可以方便地處理 Avro數(shù)據(jù)。
示例代碼:
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評(píng)論
圖片
表情
