Storing multiple messages in one protocol buffer binary file

后端 未结 4 1565
花落未央
花落未央 2020-12-05 12:27

I have repeating messages which I want to store in a single file. Currently I have to wrap this repeating message in another message. Is there a way around this?

<         


        
4条回答
  •  有刺的猬
    2020-12-05 13:14

    I was just working on this problem and ended up going with Parquet. Parquet works perfectly for storing a bunch of Protobuf messages in a file and makes it easier to work with them later on.

    This bit of code will create the Parquet file:

    Path path = new Path("/tmp/mydata.parq");
    CompressionCodecName codecName = CompressionCodecName.SNAPPY;
    int blockSize = 134217728;
    int pageSize = 1048576;
    boolean enableDictionary = true;
    boolean validating = false;
    
    ProtoParquetWriter writer
        = new ProtoParquetWriter<>(
            path,
            Box.class,
            codecName,
            blockSize,
            pageSize,
            enableDictionary,
            validating
        );
    
    for (Message message : messages) {
        writer.write(message);
    }
    
    writer.close();
    

    It might not suit your use case but I thought that it was worth a mention here.

提交回复
热议问题