Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need an API to know when a symbol has been effectively written to the bitstream #2

Open
Yoric opened this issue Jul 27, 2018 · 2 comments

Comments

@Yoric
Copy link

Yoric commented Jul 27, 2018

Whenever we call Codec::compress_symbol, this often does not output bits immediately to the bitstream. However, for compression, knowing when a symbol has effectively been written is often critical (e.g. to insert an inline dictionary, of for streaming purposes).

I'd like an API to know that.

@Yoric
Copy link
Author

Yoric commented Jul 27, 2018

Maybe something along the lines of

struct Coder<W, M> where W: BitWrite, M: Model {
  // ...
}

impl Coder<W, M> where W: BitWrite, M: Model {
  fn new(write: W, model: M) -> Self;
  fn push_symbol(&mut self, symbol: usize) -> impl Future<Item = usize /* symbols written since start */, Error = Error>;
  fn flush(&mut self) -> Result<(W, M, usize /*bytes written*/), (W, M, E)>;
}

with the invariant that a symbol is never partially written.

@Yoric
Copy link
Author

Yoric commented Jul 27, 2018

Actually, a simpler API might be

#[derive(Clone, Debug, Copy, PartialEq, Eq)]
pub struct PendingBytes(pub usize);

impl Codec {
  /// In case of success, return `Ok(pending)`, where `pending` is the number of symbols
  /// that are still pending.
  ///
  /// In other terms, if `PendingBytes.0 == 0`, `symbol` has been written to `output`.
  /// If `PendingBytes.0 == 1`, all the symbols except `symbol` have been written to `output`,
  /// etc.
  fn compress_symbol(&mut self, symbol: usize, output: &mut BitWrite) -> Result<PendingBytes>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant