SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::io::{Read};
  2.  
  3. const CHUNK_SIZE: u32 = 5000;
  4.  
  5. // Decoder takes data from a Readable source en decodes it
  6. struct Decoder<R: Read> {
  7.     input: R
  8. }
  9.  
  10. impl<R: Read> Decoder<R> {
  11.     pub fn new(src: R) -> Self {
  12.         Self {
  13.             input: src
  14.         }
  15.     }
  16. }
  17.  
  18.  
  19. pub struct LasZipDecompressor<R: Read> {
  20.     input: R,
  21.     decoder: Decoder<&mut R>,
  22.     chunk_points_read: u32,
  23. }
  24.  
  25. impl<R: Read> LasZipDecompressor<R>  {
  26.  
  27.     pub fn new(mut source: R) -> Self  {
  28.      Self {
  29.             // source is moved into input
  30.             input: source,
  31.             // how to borrow input and not source
  32.             decoder: Decoder::new(&mut source),
  33.             chunk_points_read: 0,
  34.         }
  35.     }
  36.    
  37.     pub fn decompress_one(&mut self, out: &mut[u8]) {
  38.         if self.chunk_points_read == 0 {
  39.            self.reset_decoder();
  40.         }
  41.        
  42.         // decoder.foo(&mut out);
  43.         self.chunk_points_read += 1;
  44.         if self.chunk_points_read == CHUNK_SIZE {
  45.             self.chunk_points_read =  0;
  46.         }
  47.        
  48.     }
  49.    
  50.     fn reset_decoder(&mut self) {
  51.         self.decoder = Decoder::new(&mut self.input);
  52.     }
  53.    
  54. }
  55.  
  56. fn main() {
  57.     let laszip = LasZipDecompressor::new(std::io::Cursor::new(Vec::<u8>::new()));
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top