Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

NetSerializer - A Fast, Simple Serializer for .NET

Rate me:
Please Sign up or sign in to vote.
4.87/5 (29 votes)
14 Sep 2012MPL13 min read 97.4K   107  
NetSerializer - A fast, simple serializer for .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using NetSerializer;

namespace Test
{
	class MemStreamTest : IMemStreamTest
	{
		MessageBase[] m_received;
		MemoryStream m_stream;

		public string Framework { get { return "NetSerializer"; } }

		public void Prepare(int numMessages)
		{
			m_received = new MessageBase[numMessages];
			m_stream = new MemoryStream();
		}

		public long Serialize(MessageBase[] msgs)
		{
			int numMessages = msgs.Length;

			m_stream.Position = 0;

			foreach (var msg in msgs)
				Serializer.Serialize(m_stream, msg);

			m_stream.Flush();

			return m_stream.Position;
		}

		public MessageBase[] Deserialize()
		{
			int numMessages = m_received.Length;

			m_stream.Position = 0;

			for (int i = 0; i < numMessages; ++i)
				m_received[i] = (MessageBase)Serializer.Deserialize(m_stream);

			return m_received;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Mozilla Public License 1.1 (MPL 1.1)


Written By
Finland Finland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions