Question on decoding large data structures
まだ誰も着手していません。
評価
調査の方向性
示されている Rust Ephemeris および Spline Encode/Decode の実装、特に decoder.sequence と peek_header を確認します。要求されている数千件の spline のゼロコピー復号が、割り当てなしでサポートされているかを判断し、推奨されるアプローチを特定します。両方の質問に確立された回答が得られた時点で、issue は解決されます。
索引モデルが issue の本文から書いたものです。
説明
Hi there,
I'm trying to use ASN1 to store a large data set (up to 200 MB or so). This in replacement of a file that is currently packed struct stored as bytes to disk. I was wondering if you had any hints on the best approach to do this.
The data I have is an "ephemeris" which stores several "splines." Before starting the encoding, I do not know how many splines I'll need to encode/decode, but it could be several thousands. The reference file I'm using defines that length up front and then libraries perform a direct access to the correct spline (there's a specific algorithm on how to retrieve the correct spline number from some input information, and then seeking through the file is sufficient to grab the data).
In an attempt to mimic this behavior, I'm trying the following structure:
pub struct Ephemeris<'a> {
pub spline_duration_s: f64,
pub splines: &'a [Spline<'a>], // We can't do SequenceOf<Spline<'a>, N>, because N would be too large to fit on the stack
}
And the following encoding and decoding implementations (the encoding works, but the decoding fails)
impl<'a> Encode for Ephemeris<'a> {
fn encoded_len(&self) -> der::Result<der::Length> {
self.spline_duration_s.encoded_len()?
+ self.splines.iter().fold(Length::new(2), |acc, spline| {
(acc + spline.encoded_len().unwrap()).unwrap()
})
}
fn encode(&self, encoder: &mut der::Encoder<'_>) -> der::Result<()> {
encoder.encode(&self.spline_duration_s)?;
encoder.sequence(Length::new(self.splines.len() as u16), |encoder| {
for spline in self.splines {
encoder.encode(spline)?;
}
Ok(())
})
}
}
impl<'a> Decode<'a> for Ephemeris<'a> {
fn decode(decoder: &mut Decoder<'a>) -> der::Result<Self> {
let spline_duration_s = decoder.decode()?;
let expected_len: u32 = decoder.peek_header().unwrap().length.into();
dbg!(expected_len);
// XXX: how can I point each spline to the input buffer? I can't perform an alloc, nor can I
let mut splines: &'a [Spline<'a>; 1000]; // XXX: How do I even initialize this?
decoder.sequence(|decoder| {
for idx in 0..expected_len {
splines[idx as usize] = decoder.decode()?;
}
Ok(())
});
Ok(Self {
spline_duration_s,
splines,
})
}
}
Question
- Is this a bad approach and if so, what would you recommend instead?
- If this is a reasonable approach, how can I get the
splinesfield to point to the decoded splines?
Appendix
For reference, here is how a spline is defined, where x,y,z are encoded as OctetStrings.
pub struct Spline<'a> {
pub start_epoch: Epoch,
pub end_epoch: Epoch,
/// State information (km)
pub x: &'a [u8],
/// State information (km)
pub y: &'a [u8],
/// State information (km)
pub z: &'a [u8],
Thanks for your help
- 主要言語
- Rust
- スター
- 338
- フォーク
- 188
- 平均マージ
- 4日 6時間
- マージ済み PR(30日)
- 15
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
RustCrypto/formats のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
RustCrypto/formats#2389 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
RustCrypto/formats#2366 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
RustCrypto/formats#2430 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
RustCrypto/formats#2428 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
RustCrypto/formats#2427 · コメント 1 件 ·
RustCrypto/formats の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TheLarkInn/aipm#2413 ·
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
todo:ticket
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
taikoxyz/taiko-mono#22168 · コメント 1 件 ·