fn add_to_buf(&mut self) -> Result<usize, VorbisError> {
		assert_eq!(self.buf_pos, self.buf.len(),
			"add_to_buf called when buf still has data");

		let num_channels = self.num_channels as usize;

		while self.buf_pos == self.buf.len() {
			if let Some(ref next_vpos) = self.next_vpos {
				self.vpos = *next_vpos;
			}

			let samples = self.reader.read_dec_packet_itl()?;

			let samples = match samples {
				Some(samples) => samples,
				None => {
					self.next_vpos = None;

					// end of stream
					return Ok(0);
				},
			};

			assert_eq!(samples.len() % num_channels, 0,
				"read sample count not aligned with channel count");

			// unwrap here because value should exist after a read
			let granule = self.reader.get_last_absgp().unwrap() as usize;

			let next_offset = if granule == self.vpos.granule {
				self.vpos.offset + (samples.len() / num_channels)
			} else {
				0
			};

			self.next_vpos = Some(VorbisPos {
				granule: granule,
				offset: next_offset,
			});

			if samples.len() == 0 {
				// sometimes the decoder returns 0 samples. just read again
				continue;
			}

			// safe because 0
			unsafe { self.buf.set_len(0); }

			self.buf.reserve(samples.len());

			assert!(samples.len() <= self.buf.capacity());

			// safe because we have at least this much capacity
			unsafe { self.buf.set_len(samples.len()); }

			self.buf.copy_from_slice(&samples);

			self.buf_pos = 0;
		}

		Ok(self.buf.len())
	}
// return number of samples added, or zero if end of stream
return number of samples added, or zero if end of stream
return number of samples added or zero if end of stream
fn add_to_buf(&mut self) -> Result<usize, VorbisError> {
		assert_eq!(self.buf_pos, self.buf.len(),
			"add_to_buf called when buf still has data");
		let num_channels = self.num_channels as usize;
		while self.buf_pos == self.buf.len() {
			if let Some(ref next_vpos) = self.next_vpos {
				self.vpos = *next_vpos;
			}
			let samples = self.reader.read_dec_packet_itl()?;
			let samples = match samples {
				Some(samples) => samples,
				None => {
					self.next_vpos = None;
					// end of stream
					return Ok(0);
				},
			};
			assert_eq!(samples.len() % num_channels, 0,
				"read sample count not aligned with channel count");
			// unwrap here because value should exist after a read
			let granule = self.reader.get_last_absgp().unwrap() as usize;
			let next_offset = if granule == self.vpos.granule {
				self.vpos.offset + (samples.len() / num_channels)
			} else {
				0
			};
			self.next_vpos = Some(VorbisPos {
				granule: granule,
				offset: next_offset,
			});
			if samples.len() == 0 {
				// sometimes the decoder returns 0 samples. just read again
				continue;
			}
			// safe because 0
			unsafe { self.buf.set_len(0); }
			self.buf.reserve(samples.len());
			assert!(samples.len() <= self.buf.capacity());
			// safe because we have at least this much capacity
			unsafe { self.buf.set_len(samples.len()); }
			self.buf.copy_from_slice(&samples);
			self.buf_pos = 0;
		}
		Ok(self.buf.len())
	}
fn add_to_buf ( & mut self ) -> Result < usize , VorbisError > { assert_eq ! ( self buf_pos self buf len ( ) " " ) ; let num_channels = self . num_channels as usize ; while self . buf_pos == self . buf . len ( ) { if let Some ( ref next_vpos ) = self . next_vpos { self . vpos = * next_vpos ; } let samples = self . reader . read_dec_packet_itl ( ) ? ; let samples = match samples { Some ( samples ) => samples , None => { self . next_vpos = None ; // end of stream return Ok ( 0 ) ; } , } ; assert_eq ! ( samples len ( ) num_channels 0 " " ) ; // unwrap here because value should exist after a read let granule = self . reader . get_last_absgp ( ) . unwrap ( ) as usize ; let next_offset = if granule == self . vpos . granule { self . vpos . offset + ( samples . len ( ) / num_channels ) } else { 0 } ; self . next_vpos = Some ( VorbisPos { granule : granule , offset : next_offset , } ) ; if samples . len ( ) == 0 { // sometimes the decoder returns 0 samples. just read again continue ; } // safe because 0 unsafe { self . buf . set_len ( 0 ) ; } self . buf . reserve ( samples . len ( ) ) ; assert ! ( samples len ( ) self buf capacity ( ) ) ; // safe because we have at least this much capacity unsafe { self . buf . set_len ( samples . len ( ) ) ; } self . buf . copy_from_slice ( & samples ) ; self . buf_pos = 0 ; } Ok ( self . buf . len ( ) ) }
return number of samples added, or zero if end of stream
return number of samples added or zero if end of stream
&mut self
&mut self