-pub(crate) fn read<R: io::Read, T, H: core::ops::Deref>(
- buffer: &mut R,
- custom_reader: H,
-) -> Result<Message<T>, msgs::DecodeError>
-where
+pub(crate) fn read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, custom_reader: H)
+-> Result<Message<T>, (msgs::DecodeError, Option<u16>)> where
+ T: core::fmt::Debug + Type + Writeable,
+ H::Target: CustomMessageReader<CustomMessage = T>,
+{
+ let message_type = <u16 as Readable>::read(buffer).map_err(|e| (e, None))?;
+ do_read(buffer, message_type, custom_reader).map_err(|e| (e, Some(message_type)))
+}
+
+fn do_read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, message_type: u16, custom_reader: H)
+-> Result<Message<T>, msgs::DecodeError> where