@@ -12,12 +12,12 @@ use crate::collections::identifiable::Id;
1212use crate :: internal:: Timestamp ;
1313use crate :: profiles:: { DefaultObservationCodec as DefaultCodec , ObservationCodec } ;
1414use byteorder:: { NativeEndian , ReadBytesExt } ;
15- use std:: io:: { self , Write } ;
15+ use std:: io:: { self , BufWriter , Write } ;
1616
1717pub type TimestampedObservations = TimestampedObservationsImpl < DefaultCodec > ;
1818
1919pub struct TimestampedObservationsImpl < C : ObservationCodec > {
20- compressed_timestamped_data : C :: Encoder ,
20+ compressed_timestamped_data : BufWriter < C :: Encoder > ,
2121 sample_types_len : usize ,
2222}
2323
@@ -40,10 +40,10 @@ impl<C: ObservationCodec> TimestampedObservationsImpl<C> {
4040
4141 pub fn try_new ( sample_types_len : usize ) -> io:: Result < Self > {
4242 Ok ( Self {
43- compressed_timestamped_data : C :: new_encoder (
44- Self :: DEFAULT_BUFFER_SIZE ,
45- Self :: MAX_CAPACITY ,
46- ) ? ,
43+ compressed_timestamped_data : BufWriter :: with_capacity (
44+ C :: recommended_input_buf_size ( ) ,
45+ C :: new_encoder ( Self :: DEFAULT_BUFFER_SIZE , Self :: MAX_CAPACITY ) ? ,
46+ ) ,
4747 sample_types_len,
4848 } )
4949 }
@@ -74,8 +74,12 @@ impl<C: ObservationCodec> TimestampedObservationsImpl<C> {
7474 }
7575
7676 pub fn try_into_iter ( self ) -> io:: Result < TimestampedObservationsIterImpl < C > > {
77+ let encoder = self
78+ . compressed_timestamped_data
79+ . into_inner ( )
80+ . map_err ( |e| e. into_error ( ) ) ?;
7781 Ok ( TimestampedObservationsIterImpl {
78- decoder : C :: encoder_into_decoder ( self . compressed_timestamped_data ) ?,
82+ decoder : C :: encoder_into_decoder ( encoder ) ?,
7983 sample_types_len : self . sample_types_len ,
8084 } )
8185 }
0 commit comments