Jump to content
  • Advertisement
Sign in to follow this  

Reading from a MemoryStream

This topic is 2942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! Im trying to make a class from which its possible to read arbitrary types using a generic Read-function. This looks like that:
		generic<typename T>
		void Read(T% in)
		{
			Type^ t = T::typeid;
			if(t->Equals(System::String::typeid))
			{
				in = (T)System::Text::Encoding::ASCII->GetString(m_content, m_readPoint, m_content->Length - m_readPoint);
				m_readPoint += ((String^)in)->Length + 1;
			}
			else
			{
				System::Runtime::Serialization::IFormatter^ fmt = gcnew System::Runtime::Serialization::Formatters::Binary::BinaryFormatter();
				array<unsigned char>^ buffer = gcnew array<unsigned char>(System::Runtime::InteropServices::Marshal::SizeOf(in));
				m_reader->Read(buffer, 0, buffer->Length);
				in = (T)fmt->Deserialize(gcnew System::IO::MemoryStream(buffer));
				m_readPoint += buffer->Length;
			}
		}

There seems to be a problem with that. It works well if i read a System::String but the other types seem not to be right. Deserialize throws an exception that the end of the stream was reached. I found that for a UInt16 the Deserialisation tries to read 53 Bytes from the stream. Whats the reason for that? Greetings Plerion

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!