• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

你可以代表谷歌的协议缓冲区格式CSV数据

用户头像
it1352
帮助1

问题说明

我最近发现了协议缓冲区,并想知道他们是否可以应用到我的具体问题。

I've recently found out about protocol buffers and was wondering if they could be applied to my specific problem.

基本上,我有我需要一些CSV数据转换为更紧凑的格式存储一些文件有几个演出。

Basically I have some CSV data that I need to convert to a more compact format for storage as some of the files are several gig.

在CSV每个字段都有一个报头,并且只有两种类型,字符串和小数(因为有时有很多的显著数字和我需要处理所有的数字一样的方法)。但是,每个文件都将有各自不同领域的列名。

Each field in the CSV has a header, and there are only two types, strings and decimals (because sometimes there are alot of significant digits and I need to handle all numbers the same way). But each file will have different column names for each field.

除了捕捉我需要能够在保存之前额外的信息添加到该文件中的原始CSV数据。而我希望让受处理不同的文件版本这个未来的证明。

As well as capturing the original CSV data I need to be able to add extra information to the file before saving. And I was hoping to make this future proof by handling different file versions.

那么,是不是可以用协议缓冲区来捕获数据的随机命名的列的随机数,就像一个CSV文件?

So, is it possible to use protocol buffers to capture a random number of randomly named columns of data, like a CSV file?

正确答案

#1

那么,它肯定表示的。喜欢的东西:

Well, it's certainly representable. Something like:

message CsvFile {
    repeated CsvHeader header = 1;
    repeated CsvRow row = 2;
}

message CsvHeader {
    require string name = 1;
    require ColumnType type = 2;
}

enum ColumnType {
    DECIMAL = 1;
    STRING = 2;
}

message CsvRow {
    repeated CsvValue value = 1;
}

// Note that the column is implicit based on position within row    
message CsvValue {
    optional string string_value = 1;
    optional Decimal decimal_value = 2;
}

message Decimal {
    // However you want to represent it (there are various options here)
}

我不知道有多少好处它会提供,你要知道...你当然可以添加更多的信息(添加到CsvFile消息)和未来打样是在正常PB的方式。 - 只添加可选字段等等

I'm not sure how much benefit it will provide, mind you... You can certainly add more information (add to the CsvFile message) and future proofing is in the "normal PB way" - only add optional fields, etc.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfigia
系列文章
更多 icon
同类精品
更多 icon
继续加载