activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r832900 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs
Date Wed, 04 Nov 2009 23:17:12 GMT
Author: tabish
Date: Wed Nov  4 23:17:11 2009
New Revision: 832900

URL: http://svn.apache.org/viewvc?rev=832900&view=rev
Log:
* PrimitiveMap.cs: 

Add methods for marshaling and unmarshaling a PrimitiveMap directly via a Stream object. 
This allows the resultant data to be compressed, encrypted or otherwise encoded without the
PrimitiveMap needing to know about any of that.

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs?rev=832900&r1=832899&r2=832900&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs Wed Nov
 4 23:17:11 2009
@@ -294,6 +294,24 @@
 			return answer;
 		}
 
+		/// <summary>
+		/// Unmarshals a PrimitiveMap directly from a Stream object.  This 
+		/// allows for clients to read PrimitiveMaps from Compressed or other
+		/// wise encoded streams without this class needing to know about it.
+		/// </summary>
+		/// <param name="source">
+		/// A <see cref="Stream"/>
+		/// </param>
+		/// <returns>
+		/// A <see cref="PrimitiveMap"/>
+		/// </returns>
+		public static PrimitiveMap Unmarshal(Stream source)
+		{
+			PrimitiveMap answer = new PrimitiveMap();
+			answer.dictionary = UnmarshalPrimitiveMap(source);
+			return answer;
+		}
+
 		public byte[] Marshal()
 		{
 			lock(dictionary.SyncRoot)
@@ -303,6 +321,23 @@
 		}
 
 		/// <summary>
+		/// Marshals a PrimitiveMap directly to a Stream object.  This
+		/// allows a client to write a PrimitiveMap in a compressed or 
+		/// otherwise encoded form without this class needing to know 
+		/// about it.
+		/// </summary>
+		/// <param name="destination">
+		/// A <see cref="Stream"/>
+		/// </param>
+		public void Marshal(Stream destination)
+		{
+			lock(dictionary.SyncRoot)
+			{
+				MarshalPrimitiveMap(dictionary, destination);
+			}
+		}
+				
+		/// <summary>
 		/// Marshals the primitive type map to a byte array
 		/// </summary>
 		public static byte[] MarshalPrimitiveMap(IDictionary map)
@@ -321,6 +356,17 @@
 			return memoryStream.GetBuffer();
 		}
 
+		public static void MarshalPrimitiveMap(IDictionary map, Stream stream)
+		{
+			if(map != null)
+			{
+				lock(map.SyncRoot)
+				{
+					MarshalPrimitiveMap(map, new EndianBinaryWriter(stream));
+				}
+			}
+		}		
+		
 		public static void MarshalPrimitiveMap(IDictionary map, BinaryWriter dataOut)
 		{
 			if(map == null)
@@ -357,6 +403,11 @@
 				return UnmarshalPrimitiveMap(new EndianBinaryReader(new MemoryStream(data)));
 			}
 		}
+		
+		public static IDictionary UnmarshalPrimitiveMap(Stream source)
+		{
+			return UnmarshalPrimitiveMap(new EndianBinaryReader(source));
+		}		
 
 		public static IDictionary UnmarshalPrimitiveMap(BinaryReader dataIn)
 		{



Mime
View raw message