summaryrefslogtreecommitdiff
path: root/csharp/src
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src')
-rw-r--r--csharp/src/Glacier2/Application.cs22
-rw-r--r--csharp/src/Glacier2/AssemblyInfo.cs2
-rw-r--r--csharp/src/Glacier2/SessionHelper.cs22
-rw-r--r--csharp/src/Ice/ACM.cs14
-rw-r--r--csharp/src/Ice/AssemblyInfo.cs2
-rw-r--r--csharp/src/Ice/AsyncResult.cs2
-rw-r--r--csharp/src/Ice/BZip2.cs285
-rw-r--r--csharp/src/Ice/BasicStream.cs5409
-rw-r--r--csharp/src/Ice/BatchRequestInterceptor.cs6
-rw-r--r--csharp/src/Ice/BatchRequestQueue.cs23
-rw-r--r--csharp/src/Ice/Buffer.cs28
-rw-r--r--csharp/src/Ice/ByteBuffer.cs2
-rw-r--r--csharp/src/Ice/CollocatedRequestHandler.cs43
-rw-r--r--csharp/src/Ice/CommunicatorI.cs15
-rw-r--r--csharp/src/Ice/ConnectionFactory.cs2
-rw-r--r--csharp/src/Ice/ConnectionI.cs105
-rw-r--r--csharp/src/Ice/DefaultsAndOverrides.cs4
-rw-r--r--csharp/src/Ice/EndpointFactory.cs2
-rw-r--r--csharp/src/Ice/EndpointFactoryManager.cs26
-rw-r--r--csharp/src/Ice/EndpointHostResolver.cs4
-rw-r--r--csharp/src/Ice/EndpointI.cs2
-rw-r--r--csharp/src/Ice/Exception.cs41
-rw-r--r--csharp/src/Ice/IPEndpointI.cs10
-rw-r--r--csharp/src/Ice/ImplicitContextI.cs7
-rw-r--r--csharp/src/Ice/Incoming.cs88
-rw-r--r--csharp/src/Ice/IncomingAsync.cs2
-rw-r--r--csharp/src/Ice/InputStream.cs4029
-rw-r--r--csharp/src/Ice/Instance.cs106
-rw-r--r--csharp/src/Ice/InstrumentationI.cs38
-rw-r--r--csharp/src/Ice/LocatorInfo.cs2
-rw-r--r--csharp/src/Ice/Makefile14
-rw-r--r--csharp/src/Ice/Makefile.mak14
-rw-r--r--csharp/src/Ice/MetricsAdminI.cs26
-rw-r--r--csharp/src/Ice/MetricsObserverI.cs20
-rw-r--r--csharp/src/Ice/Object.cs39
-rw-r--r--csharp/src/Ice/ObjectFactoryManager.cs86
-rw-r--r--csharp/src/Ice/OpaqueEndpointI.cs12
-rw-r--r--csharp/src/Ice/Optional.cs11
-rw-r--r--csharp/src/Ice/OutgoingAsync.cs68
-rw-r--r--csharp/src/Ice/OutputStream.cs2844
-rw-r--r--csharp/src/Ice/Patcher.cs76
-rw-r--r--csharp/src/Ice/PropertyNames.cs21
-rw-r--r--csharp/src/Ice/Protocol.cs14
-rw-r--r--csharp/src/Ice/Proxy.cs46
-rw-r--r--csharp/src/Ice/ProxyFactory.cs51
-rw-r--r--csharp/src/Ice/Reference.cs8
-rw-r--r--csharp/src/Ice/ReferenceFactory.cs4
-rw-r--r--csharp/src/Ice/ResponseHandler.cs4
-rw-r--r--csharp/src/Ice/Stream.cs705
-rw-r--r--csharp/src/Ice/StreamI.cs570
-rw-r--r--csharp/src/Ice/StreamWrapper.cs206
-rw-r--r--csharp/src/Ice/TcpEndpointI.cs6
-rw-r--r--csharp/src/Ice/TraceUtil.cs52
-rw-r--r--csharp/src/Ice/UdpEndpointI.cs10
-rw-r--r--csharp/src/Ice/UnknownSlicedObject.cs12
-rw-r--r--csharp/src/Ice/Util.cs82
-rw-r--r--csharp/src/Ice/ValueFactoryManager.cs45
-rw-r--r--csharp/src/Ice/WSEndpoint.cs12
-rw-r--r--csharp/src/Ice/WSTransceiver.cs2
-rw-r--r--csharp/src/IceBox/AssemblyInfo.cs2
-rw-r--r--csharp/src/IceBox/AssemblyInfoExe.cs2
-rw-r--r--csharp/src/IceBox/Makefile.mak6
-rw-r--r--csharp/src/IceDiscovery/AssemblyInfo.cs2
-rw-r--r--csharp/src/IceGrid/AssemblyInfo.cs2
-rw-r--r--csharp/src/IceGrid/Makefile3
-rw-r--r--csharp/src/IceGrid/Makefile.mak3
-rw-r--r--csharp/src/IceLocatorDiscovery/AssemblyInfo.cs2
-rw-r--r--csharp/src/IcePatch2/AssemblyInfo.cs2
-rw-r--r--csharp/src/IceSSL/AssemblyInfo.cs2
-rw-r--r--csharp/src/IceSSL/EndpointI.cs6
-rw-r--r--csharp/src/IceSSL/RFC2253.cs4
-rw-r--r--csharp/src/IceStorm/AssemblyInfo.cs2
72 files changed, 7955 insertions, 7486 deletions
diff --git a/csharp/src/Glacier2/Application.cs b/csharp/src/Glacier2/Application.cs
index 6af256b8b7c..6b91325a181 100644
--- a/csharp/src/Glacier2/Application.cs
+++ b/csharp/src/Glacier2/Application.cs
@@ -205,26 +205,6 @@ public abstract class Application : Ice.Application
return _adapter;
}
- private class ConnectionCallbackI : Ice.ConnectionCallback
- {
- internal ConnectionCallbackI(Application application)
- {
- _application = application;
- }
-
- public void heartbeat(Ice.Connection con)
- {
-
- }
-
- public void closed(Ice.Connection con)
- {
- _application.sessionDestroyed();
- }
-
- private readonly Application _application;
- }
-
protected override int
doMain(string[] originArgs, Ice.InitializationData initData)
{
@@ -319,7 +299,7 @@ public abstract class Application : Ice.Application
Ice.Connection connection = _router.ice_getCachedConnection();
Debug.Assert(connection != null);
connection.setACM((int)acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
- connection.setCallback(new ConnectionCallbackI(this));
+ connection.setCloseCallback(_ => sessionDestroyed());
}
_category = _router.getCategoryForClient();
status = runWithSession(args);
diff --git a/csharp/src/Glacier2/AssemblyInfo.cs b/csharp/src/Glacier2/AssemblyInfo.cs
index f72487103b8..6cf61188d79 100644
--- a/csharp/src/Glacier2/AssemblyInfo.cs
+++ b/csharp/src/Glacier2/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/Glacier2/SessionHelper.cs b/csharp/src/Glacier2/SessionHelper.cs
index a37ce42d26e..e18531d8008 100644
--- a/csharp/src/Glacier2/SessionHelper.cs
+++ b/csharp/src/Glacier2/SessionHelper.cs
@@ -20,26 +20,6 @@ namespace Glacier2
/// </summary>
public class SessionHelper
{
- private class ConnectionCallbackI : Ice.ConnectionCallback
- {
- internal ConnectionCallbackI(SessionHelper sessionHelper)
- {
- _sessionHelper = sessionHelper;
- }
-
- public void heartbeat(Ice.Connection con)
- {
-
- }
-
- public void closed(Ice.Connection con)
- {
- _sessionHelper.destroy();
- }
-
- private readonly SessionHelper _sessionHelper;
- }
-
/// <summary>
/// Creates a Glacier2 session.
/// </summary>
@@ -320,7 +300,7 @@ public class SessionHelper
Ice.Connection connection = _router.ice_getCachedConnection();
Debug.Assert(connection != null);
connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
- connection.setCallback(new ConnectionCallbackI(this));
+ connection.setCloseCallback(_ => destroy());
}
}
diff --git a/csharp/src/Ice/ACM.cs b/csharp/src/Ice/ACM.cs
index 165e5fff2d2..d10fa846af0 100644
--- a/csharp/src/Ice/ACM.cs
+++ b/csharp/src/Ice/ACM.cs
@@ -34,7 +34,7 @@ namespace IceInternal
else
{
timeoutProperty = prefix + ".Timeout";
- };
+ }
timeout = p.getPropertyAsIntWithDefault(timeoutProperty, dflt.timeout / 1000) * 1000;
@@ -71,7 +71,7 @@ namespace IceInternal
public int timeout;
public Ice.ACMHeartbeat heartbeat;
public Ice.ACMClose close;
- };
+ }
public interface ACMMonitor : TimerTask
{
@@ -81,7 +81,7 @@ namespace IceInternal
ACMMonitor acm(Ice.Optional<int> timeout, Ice.Optional<Ice.ACMClose> c, Ice.Optional<Ice.ACMHeartbeat> h);
Ice.ACM getACM();
- };
+ }
class FactoryACMMonitor : ACMMonitor
{
@@ -95,7 +95,7 @@ namespace IceInternal
public readonly Ice.ConnectionI connection;
public readonly bool remove;
- };
+ }
internal FactoryACMMonitor(Instance instance, ACMConfig config)
{
@@ -269,7 +269,7 @@ namespace IceInternal
private HashSet<Ice.ConnectionI> _connections = new HashSet<Ice.ConnectionI>();
private List<Change> _changes = new List<Change>();
private List<Ice.ConnectionI> _reapedConnections = new List<Ice.ConnectionI>();
- };
+ }
internal class ConnectionACMMonitor : ACMMonitor
{
@@ -352,5 +352,5 @@ namespace IceInternal
readonly private ACMConfig _config;
private Ice.ConnectionI _connection;
- };
-} \ No newline at end of file
+ }
+}
diff --git a/csharp/src/Ice/AssemblyInfo.cs b/csharp/src/Ice/AssemblyInfo.cs
index 7d1c3bd0c92..b6f6c5de69b 100644
--- a/csharp/src/Ice/AssemblyInfo.cs
+++ b/csharp/src/Ice/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/Ice/AsyncResult.cs b/csharp/src/Ice/AsyncResult.cs
index 7d67aa735d2..42e8f78608d 100644
--- a/csharp/src/Ice/AsyncResult.cs
+++ b/csharp/src/Ice/AsyncResult.cs
@@ -552,7 +552,7 @@ namespace IceInternal
_cancellationHandler = null;
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(_completedCallback == null)
{
diff --git a/csharp/src/Ice/BZip2.cs b/csharp/src/Ice/BZip2.cs
new file mode 100644
index 00000000000..09b7eb52d46
--- /dev/null
+++ b/csharp/src/Ice/BZip2.cs
@@ -0,0 +1,285 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+namespace IceInternal
+{
+
+ using System;
+ using System.Diagnostics;
+#if !COMPACT && !SILVERLIGHT
+ using System.Runtime.InteropServices;
+ using System.Runtime.Serialization;
+ using System.Runtime.Serialization.Formatters.Binary;
+#endif
+
+#if !MANAGED && !COMPACT && !SILVERLIGHT
+ internal static class NativeMethods
+ {
+ [DllImport("bzip2.dll")]
+ internal static extern IntPtr BZ2_bzlibVersion();
+
+ [DllImport("bzip2.dll")]
+ internal static extern int BZ2_bzBuffToBuffCompress(byte[] dest,
+ ref int destLen,
+ byte[] source,
+ int sourceLen,
+ int blockSize100k,
+ int verbosity,
+ int workFactor);
+
+ [DllImport("bzip2.dll")]
+ internal static extern int BZ2_bzBuffToBuffDecompress(byte[] dest,
+ ref int destLen,
+ byte[] source,
+ int sourceLen,
+ int small,
+ int verbosity);
+ }
+#endif
+
+ public class BZip2
+ {
+ static BZip2()
+ {
+#if MANAGED || COMPACT || SILVERLIGHT
+ //
+ // Protocol compression is not supported when using managed code.
+ //
+ _bzlibInstalled = false;
+#else
+ //
+ // Simple trick to find out whether bzip2 is installed: Call the BZ2_bzlibVersion() function in the
+ // library. If we get an exception, the library is not available.
+ //
+ _bzlibInstalled = false;
+
+ //
+ // We are setting the library name here because, under Mono, we don't know the exact library name.
+ // In addition, the FileName member of the BadImageFormatException is the empty string, even though
+ // it should provide the name of the library.
+ //
+ string lib = AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono ? "bzip2 library" : "bzip2.dll";
+ try
+ {
+ NativeMethods.BZ2_bzlibVersion();
+ _bzlibInstalled = true;
+ }
+ catch(DllNotFoundException)
+ {
+ // Expected -- bzip2.dll not installed or not in PATH.
+ }
+ catch(EntryPointNotFoundException)
+ {
+ Console.Error.WriteLine("warning: found " + lib + " but entry point BZ2_bzlibVersion is missing.");
+ }
+ catch(BadImageFormatException ex)
+ {
+ if(ex.FileName != null && ex.FileName.Length != 0)
+ {
+ lib = ex.FileName; // Future-proof: we'll do the right thing if the FileName member is non-empty.
+ }
+ Console.Error.Write("warning: " + lib + " could not be loaded (likely due to 32/64-bit mismatch).");
+ if(IntPtr.Size == 8)
+ {
+ Console.Error.Write(" Make sure the directory containing the 64-bit " + lib + " is in your PATH.");
+ }
+ Console.Error.WriteLine();
+ }
+#endif
+ }
+
+#if !MANAGED && !COMPACT && !SILVERLIGHT
+ static string getBZ2Error(int error)
+ {
+ string rc;
+
+ switch(error)
+ {
+ case BZ_SEQUENCE_ERROR:
+ {
+ rc = "BZ_SEQUENCE_ERROR";
+ break;
+ }
+ case BZ_PARAM_ERROR:
+ {
+ rc = "BZ_PARAM_ERROR";
+ break;
+ }
+ case BZ_MEM_ERROR:
+ {
+ rc = "BZ_MEM_ERROR";
+ break;
+ }
+ case BZ_DATA_ERROR:
+ {
+ rc = "BZ_DATA_ERROR";
+ break;
+ }
+ case BZ_DATA_ERROR_MAGIC:
+ {
+ rc = "BZ_DATA_ERROR_MAGIC";
+ break;
+ }
+ case BZ_IO_ERROR:
+ {
+ rc = "BZ_IO_ERROR";
+ break;
+ }
+ case BZ_UNEXPECTED_EOF:
+ {
+ rc = "BZ_UNEXPECTED_EOF";
+ break;
+ }
+ case BZ_OUTBUFF_FULL:
+ {
+ rc = "BZ_OUTBUFF_FULL";
+ break;
+ }
+ case BZ_CONFIG_ERROR:
+ {
+ rc = "BZ_CONFIG_ERROR";
+ break;
+ }
+ default:
+ {
+ rc = "Unknown bzip2 error: " + error;
+ break;
+ }
+ }
+ return rc;
+ }
+#endif
+
+ public static bool supported()
+ {
+ return _bzlibInstalled;
+ }
+
+ public static Buffer compress(Buffer buf, int headerSize, int compressionLevel)
+ {
+ Debug.Assert(supported());
+
+#if MANAGED || COMPACT || SILVERLIGHT
+ return null;
+#else
+ //
+ // Compress the message body, but not the header.
+ //
+ int uncompressedLen = buf.size() - headerSize;
+ byte[] data = buf.b.rawBytes(headerSize, uncompressedLen);
+ int compressedLen = (int)(uncompressedLen * 1.01 + 600);
+ byte[] compressed = new byte[compressedLen];
+
+ int rc = NativeMethods.BZ2_bzBuffToBuffCompress(compressed, ref compressedLen, data, uncompressedLen,
+ compressionLevel, 0, 0);
+ if(rc == BZ_OUTBUFF_FULL)
+ {
+ return null;
+ }
+ else if(rc < 0)
+ {
+ Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffCompress failed");
+ ex.reason = getBZ2Error(rc);
+ throw ex;
+ }
+
+ //
+ // Don't bother if the compressed data is larger than the
+ // uncompressed data.
+ //
+ if(compressedLen >= uncompressedLen)
+ {
+ return null;
+ }
+
+ Buffer r = new Buffer();
+ r.resize(headerSize + 4 + compressedLen, false);
+ r.b.position(0);
+
+ //
+ // Copy the header from the uncompressed stream to the
+ // compressed one.
+ //
+ r.b.put(buf.b.rawBytes(0, headerSize));
+
+ //
+ // Add the size of the uncompressed stream before the
+ // message body.
+ //
+ r.b.putInt(buf.size());
+
+ //
+ // Add the compressed message body.
+ //
+ r.b.put(compressed, 0, compressedLen);
+
+ return r;
+#endif
+ }
+
+ public static Buffer uncompress(Buffer buf, int headerSize, int messageSizeMax)
+ {
+ Debug.Assert(supported());
+
+#if MANAGED || COMPACT || SILVERLIGHT
+ return null;
+#else
+ buf.b.position(headerSize);
+ int uncompressedSize = buf.b.getInt();
+ if(uncompressedSize <= headerSize)
+ {
+ throw new Ice.IllegalMessageSizeException("compressed size <= header size");
+ }
+ if(uncompressedSize > messageSizeMax)
+ {
+ IceInternal.Ex.throwMemoryLimitException(uncompressedSize, messageSizeMax);
+ }
+
+ int compressedLen = buf.size() - headerSize - 4;
+ byte[] compressed = buf.b.rawBytes(headerSize + 4, compressedLen);
+ int uncompressedLen = uncompressedSize - headerSize;
+
+ byte[] uncompressed = new byte[uncompressedLen];
+ int rc = NativeMethods.BZ2_bzBuffToBuffDecompress(uncompressed, ref uncompressedLen, compressed,
+ compressedLen, 0, 0);
+ if(rc < 0)
+ {
+ Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffDecompress failed");
+ ex.reason = getBZ2Error(rc);
+ throw ex;
+ }
+
+ Buffer r = new Buffer();
+ r.resize(uncompressedSize, false);
+
+ //
+ // Copy the header from the compressed buffer to the uncompressed one.
+ //
+ r.b.position(0);
+ r.b.put(buf.b.rawBytes(), 0, headerSize);
+ r.b.put(uncompressed);
+
+ return r;
+#endif
+ }
+
+ private static bool _bzlibInstalled;
+
+ const int BZ_SEQUENCE_ERROR = -1;
+ const int BZ_PARAM_ERROR = -2;
+ const int BZ_MEM_ERROR = -3;
+ const int BZ_DATA_ERROR = -4;
+ const int BZ_DATA_ERROR_MAGIC = -5;
+ const int BZ_IO_ERROR = -6;
+ const int BZ_UNEXPECTED_EOF = -7;
+ const int BZ_OUTBUFF_FULL = -8;
+ const int BZ_CONFIG_ERROR = -9;
+ }
+
+}
diff --git a/csharp/src/Ice/BasicStream.cs b/csharp/src/Ice/BasicStream.cs
deleted file mode 100644
index cb36056533d..00000000000
--- a/csharp/src/Ice/BasicStream.cs
+++ /dev/null
@@ -1,5409 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-namespace IceInternal
-{
-
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Reflection;
-#if !COMPACT && !SILVERLIGHT
- using System.Runtime.InteropServices;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
-#endif
- using System.Threading;
-
-#if !MANAGED && !COMPACT && !SILVERLIGHT
- internal static class NativeMethods
- {
- [DllImport("bzip2.dll")]
- internal static extern IntPtr BZ2_bzlibVersion();
-
- [DllImport("bzip2.dll")]
- internal static extern int BZ2_bzBuffToBuffCompress(byte[] dest,
- ref int destLen,
- byte[] source,
- int sourceLen,
- int blockSize100k,
- int verbosity,
- int workFactor);
-
- [DllImport("bzip2.dll")]
- internal static extern int BZ2_bzBuffToBuffDecompress(byte[] dest,
- ref int destLen,
- byte[] source,
- int sourceLen,
- int small,
- int verbosity);
- }
-#endif
-
- public class BasicStream
- {
-
- static BasicStream()
- {
-#if MANAGED || COMPACT || SILVERLIGHT
- //
- // Protocol compression is not supported when using managed code.
- //
- _bzlibInstalled = false;
-#else
- //
- // Simple trick to find out whether bzip2 is
- // installed: Call the BZ2_bzlibVersion() function in the
- // library. If we get an exception, the library is
- // not available.
- //
- _bzlibInstalled = false;
-
- //
- // We are setting the library name here because, under Mono, we don't know the exact library name.
- // In addition, the FileName member of the BadImageFormatException is the empty string, even though
- // it should provide the name of the library.
- //
- string lib = AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono ? "bzip2 library" : "bzip2.dll";
- try
- {
- NativeMethods.BZ2_bzlibVersion();
- _bzlibInstalled = true;
- }
- catch(DllNotFoundException)
- {
- // Expected -- bzip2.dll not installed or not in PATH.
- }
- catch(EntryPointNotFoundException)
- {
- Console.Error.WriteLine("warning: found " + lib + " but entry point BZ2_bzlibVersion is missing.");
- }
- catch(BadImageFormatException ex)
- {
- if(ex.FileName != null && ex.FileName.Length != 0)
- {
- lib = ex.FileName; // Future-proof: we'll do the right thing if the FileName member is non-empty.
- }
- Console.Error.Write("warning: " + lib + " could not be loaded (likely due to 32/64-bit mismatch).");
- if(IntPtr.Size == 8)
- {
- Console.Error.Write(" Make sure the directory containing the 64-bit " + lib + " is in your PATH.");
- }
- Console.Error.WriteLine();
- }
-#endif
- }
-
- public BasicStream(Instance instance, Ice.EncodingVersion encoding)
- {
- initialize(instance, encoding);
- _buf = new Buffer();
- }
-
- public BasicStream(Instance instance, Ice.EncodingVersion encoding, byte[] data)
- {
- initialize(instance, encoding);
- _buf = new Buffer(data);
- }
-
- private void initialize(Instance instance, Ice.EncodingVersion encoding)
- {
- instance_ = instance;
- _closure = null;
- _encoding = encoding;
-
- _readEncapsStack = null;
- _writeEncapsStack = null;
- _readEncapsCache = null;
- _writeEncapsCache = null;
-
- _sliceObjects = true;
-
- _startSeq = -1;
- }
-
- //
- // This function allows this object to be reused, rather than
- // reallocated.
- //
- public void reset()
- {
- _buf.reset();
- clear();
- }
-
- public void clear()
- {
- if(_readEncapsStack != null)
- {
- Debug.Assert(_readEncapsStack.next == null);
- _readEncapsStack.next = _readEncapsCache;
- _readEncapsCache = _readEncapsStack;
- _readEncapsStack = null;
- _readEncapsCache.reset();
- }
-
- if(_writeEncapsStack != null)
- {
- Debug.Assert(_writeEncapsStack.next == null);
- _writeEncapsStack.next = _writeEncapsCache;
- _writeEncapsCache = _writeEncapsStack;
- _writeEncapsStack = null;
- _writeEncapsCache.reset();
- }
-
- _startSeq = -1;
-
- _sliceObjects = true;
- }
-
- public Instance instance()
- {
- return instance_;
- }
-
- public object closure()
- {
- return _closure;
- }
-
- public object closure(object p)
- {
- object prev = _closure;
- _closure = p;
- return prev;
- }
-
- public void swap(BasicStream other)
- {
- Debug.Assert(instance_ == other.instance_);
-
- Buffer tmpBuf = other._buf;
- other._buf = _buf;
- _buf = tmpBuf;
-
- object tmpClosure = other._closure;
- other._closure = _closure;
- _closure = tmpClosure;
-
- //
- // Swap is never called for BasicStreams that have encapsulations being read/write. However,
- // encapsulations might still be set in case marshalling or un-marshalling failed. We just
- // reset the encapsulations if there are still some set.
- //
- resetEncaps();
- other.resetEncaps();
-
- int tmpStartSeq = other._startSeq;
- other._startSeq = _startSeq;
- _startSeq = tmpStartSeq;
-
- int tmpMinSeqSize = other._minSeqSize;
- other._minSeqSize = _minSeqSize;
- _minSeqSize = tmpMinSeqSize;
- }
-
- public void resetEncaps()
- {
- _readEncapsStack = null;
- _writeEncapsStack = null;
- }
-
- public void resize(int sz, bool reading)
- {
- _buf.resize(sz, reading);
- _buf.b.position(sz);
- }
-
- public Buffer prepareWrite()
- {
- _buf.b.limit(_buf.size());
- _buf.b.position(0);
- return _buf;
- }
-
- public Buffer getBuffer()
- {
- return _buf;
- }
-
- public void startWriteObject(Ice.SlicedData data)
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.startInstance(SliceType.ObjectSlice, data);
- }
-
- public void endWriteObject()
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.endInstance();
- }
-
- public void startReadObject()
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- _readEncapsStack.decoder.startInstance(SliceType.ObjectSlice);
- }
-
- public Ice.SlicedData endReadObject(bool preserve)
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- return _readEncapsStack.decoder.endInstance(preserve);
- }
-
- public void startWriteException(Ice.SlicedData data)
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.startInstance(SliceType.ExceptionSlice, data);
- }
-
- public void endWriteException()
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.endInstance();
- }
-
- public void startReadException()
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- _readEncapsStack.decoder.startInstance(SliceType.ExceptionSlice);
- }
-
- public Ice.SlicedData endReadException(bool preserve)
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- return _readEncapsStack.decoder.endInstance(preserve);
- }
-
- public void startWriteEncaps()
- {
- //
- // If no encoding version is specified, use the current write
- // encapsulation encoding version if there's a current write
- // encapsulation, otherwise, use the stream encoding version.
- //
-
- if(_writeEncapsStack != null)
- {
- startWriteEncaps(_writeEncapsStack.encoding, _writeEncapsStack.format);
- }
- else
- {
- startWriteEncaps(_encoding, Ice.FormatType.DefaultFormat);
- }
- }
-
- public void startWriteEncaps(Ice.EncodingVersion encoding, Ice.FormatType format)
- {
- Protocol.checkSupportedEncoding(encoding);
-
- WriteEncaps curr = _writeEncapsCache;
- if(curr != null)
- {
- curr.reset();
- _writeEncapsCache = _writeEncapsCache.next;
- }
- else
- {
- curr = new WriteEncaps();
- }
- curr.next = _writeEncapsStack;
- _writeEncapsStack = curr;
-
- _writeEncapsStack.format = format;
- _writeEncapsStack.setEncoding(encoding);
- _writeEncapsStack.start = _buf.b.position();
-
- writeInt(0); // Placeholder for the encapsulation length.
- _writeEncapsStack.encoding.write__(this);
- }
-
- public void endWriteEncaps()
- {
- Debug.Assert(_writeEncapsStack != null);
-
- // Size includes size and version.
- int start = _writeEncapsStack.start;
- int sz = _buf.size() - start;
- _buf.b.putInt(start, sz);
-
- WriteEncaps curr = _writeEncapsStack;
- _writeEncapsStack = curr.next;
- curr.next = _writeEncapsCache;
- _writeEncapsCache = curr;
- _writeEncapsCache.reset();
- }
-
- public void endWriteEncapsChecked()
- {
- if(_writeEncapsStack == null)
- {
- throw new Ice.EncapsulationException("not in an encapsulation");
- }
- endWriteEncaps();
- }
-
- public void writeEmptyEncaps(Ice.EncodingVersion encoding)
- {
- Protocol.checkSupportedEncoding(encoding);
- writeInt(6); // Size
- encoding.write__(this);
- }
-
- public void writeEncaps(byte[] v)
- {
- if(v.Length < 6)
- {
- throw new Ice.EncapsulationException();
- }
- expand(v.Length);
- _buf.b.put(v);
- }
-
- public Ice.EncodingVersion getWriteEncoding()
- {
- return _writeEncapsStack != null ? _writeEncapsStack.encoding : _encoding;
- }
-
- public Ice.EncodingVersion startReadEncaps()
- {
- ReadEncaps curr = _readEncapsCache;
- if(curr != null)
- {
- curr.reset();
- _readEncapsCache = _readEncapsCache.next;
- }
- else
- {
- curr = new ReadEncaps();
- }
- curr.next = _readEncapsStack;
- _readEncapsStack = curr;
-
- _readEncapsStack.start = _buf.b.position();
-
- //
- // I don't use readSize() and writeSize() for encapsulations,
- // because when creating an encapsulation, I must know in advance
- // how many bytes the size information will require in the data
- // stream. If I use an Int, it is always 4 bytes. For
- // readSize()/writeSize(), it could be 1 or 5 bytes.
- //
- int sz = readInt();
- if(sz < 6)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- if(sz - 4 > _buf.b.remaining())
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- _readEncapsStack.sz = sz;
-
- Ice.EncodingVersion encoding = new Ice.EncodingVersion();
- encoding.read__(this);
- Protocol.checkSupportedEncoding(encoding); // Make sure the encoding is supported.
- _readEncapsStack.setEncoding(encoding);
-
- return encoding;
- }
-
- public void endReadEncaps()
- {
- Debug.Assert(_readEncapsStack != null);
-
- if(!_readEncapsStack.encoding_1_0)
- {
- skipOpts();
- if(_buf.b.position() != _readEncapsStack.start + _readEncapsStack.sz)
- {
- throw new Ice.EncapsulationException();
- }
- }
- else if(_buf.b.position() != _readEncapsStack.start + _readEncapsStack.sz)
- {
- if(_buf.b.position() + 1 != _readEncapsStack.start + _readEncapsStack.sz)
- {
- throw new Ice.EncapsulationException();
- }
-
- //
- // Ice version < 3.3 had a bug where user exceptions with
- // class members could be encoded with a trailing byte
- // when dispatched with AMD. So we tolerate an extra byte
- // in the encapsulation.
- //
- try
- {
- _buf.b.get();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- ReadEncaps curr = _readEncapsStack;
- _readEncapsStack = curr.next;
- curr.next = _readEncapsCache;
- _readEncapsCache = curr;
- _readEncapsCache.reset();
- }
-
- public Ice.EncodingVersion skipEmptyEncaps()
- {
- int sz = readInt();
- if(sz != 6)
- {
- throw new Ice.EncapsulationException();
- }
-
- Ice.EncodingVersion encoding = new Ice.EncodingVersion();
- encoding.read__(this);
- return encoding;
- }
-
- public void endReadEncapsChecked() // Used by public stream API.
- {
- if(_readEncapsStack == null)
- {
- throw new Ice.EncapsulationException("not in an encapsulation");
- }
- endReadEncaps();
- }
-
- public byte[] readEncaps(out Ice.EncodingVersion encoding)
- {
- int sz = readInt();
- if(sz < 6)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
-
- if(sz - 4 > _buf.b.remaining())
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
-
- encoding = new Ice.EncodingVersion();
- encoding.read__(this);
- _buf.b.position(_buf.b.position() - 6);
-
- byte[] v = new byte[sz];
- try
- {
- _buf.b.get(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.EncodingVersion getReadEncoding()
- {
- return _readEncapsStack != null ? _readEncapsStack.encoding : _encoding;
- }
-
- public int getReadEncapsSize()
- {
- Debug.Assert(_readEncapsStack != null);
- return _readEncapsStack.sz - 6;
- }
-
- public Ice.EncodingVersion skipEncaps()
- {
- int sz = readInt();
- if(sz < 6)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- Ice.EncodingVersion encoding = new Ice.EncodingVersion();
- encoding.read__(this);
- try
- {
- _buf.b.position(_buf.b.position() + sz - 6);
- }
- catch(ArgumentOutOfRangeException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- return encoding;
- }
-
- public void startWriteSlice(string typeId, int compactId, bool last)
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.startSlice(typeId, compactId, last);
- }
-
- public void endWriteSlice()
- {
- Debug.Assert(_writeEncapsStack != null && _writeEncapsStack.encoder != null);
- _writeEncapsStack.encoder.endSlice();
- }
-
- public string startReadSlice() // Returns type ID of next slice
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- return _readEncapsStack.decoder.startSlice();
- }
-
- public void endReadSlice()
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- _readEncapsStack.decoder.endSlice();
- }
-
- public void skipSlice()
- {
- Debug.Assert(_readEncapsStack != null && _readEncapsStack.decoder != null);
- _readEncapsStack.decoder.skipSlice();
- }
-
- public void readPendingObjects()
- {
- if(_readEncapsStack != null && _readEncapsStack.decoder != null)
- {
- _readEncapsStack.decoder.readPendingObjects();
- }
- else if(_readEncapsStack != null ? _readEncapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0))
- {
- //
- // If using the 1.0 encoding and no objects were read, we
- // still read an empty sequence of pending objects if
- // requested (i.e.: if this is called).
- //
- // This is required by the 1.0 encoding, even if no objects
- // are written we do marshal an empty sequence if marshaled
- // data types use classes.
- //
- skipSize();
- }
- }
-
- public void writePendingObjects()
- {
- if(_writeEncapsStack != null && _writeEncapsStack.encoder != null)
- {
- _writeEncapsStack.encoder.writePendingObjects();
- }
- else if(_writeEncapsStack != null ?
- _writeEncapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0))
- {
- //
- // If using the 1.0 encoding and no objects were written, we
- // still write an empty sequence for pending objects if
- // requested (i.e.: if this is called).
- //
- // This is required by the 1.0 encoding, even if no objects
- // are written we do marshal an empty sequence if marshaled
- // data types use classes.
- //
- writeSize(0);
- }
- }
-
- public void writeSize(int v)
- {
- if(v > 254)
- {
- expand(5);
- _buf.b.put((byte)255);
- _buf.b.putInt(v);
- }
- else
- {
- expand(1);
- _buf.b.put((byte)v);
- }
- }
-
- public int readSize()
- {
- try
- {
- //
- // COMPILERFIX: for some reasons _buf.get() doesn't work here on OS X with Mono;
- //
- //byte b = _buf.b.get();
- byte b = readByte();
- if(b == 255)
- {
- int v = _buf.b.getInt();
- if(v < 0)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- return v;
- }
- else
- {
- return b; // byte is unsigned
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public int readAndCheckSeqSize(int minSize)
- {
- int sz = readSize();
-
- if(sz == 0)
- {
- return 0;
- }
-
- //
- // The _startSeq variable points to the start of the sequence for which
- // we expect to read at least _minSeqSize bytes from the stream.
- //
- // If not initialized or if we already read more data than _minSeqSize,
- // we reset _startSeq and _minSeqSize for this sequence (possibly a
- // top-level sequence or enclosed sequence it doesn't really matter).
- //
- // Otherwise, we are reading an enclosed sequence and we have to bump
- // _minSeqSize by the minimum size that this sequence will require on
- // the stream.
- //
- // The goal of this check is to ensure that when we start un-marshalling
- // a new sequence, we check the minimal size of this new sequence against
- // the estimated remaining buffer size. This estimatation is based on
- // the minimum size of the enclosing sequences, it's _minSeqSize.
- //
- if(_startSeq == -1 || _buf.b.position() > (_startSeq + _minSeqSize))
- {
- _startSeq = _buf.b.position();
- _minSeqSize = sz * minSize;
- }
- else
- {
- _minSeqSize += sz * minSize;
- }
-
- //
- // If there isn't enough data to read on the stream for the sequence (and
- // possibly enclosed sequences), something is wrong with the marshalled
- // data: it's claiming having more data that what is possible to read.
- //
- if(_startSeq + _minSeqSize > _buf.size())
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
-
- return sz;
- }
-
- public int startSize()
- {
- int pos = _buf.b.position();
- writeInt(0); // Placeholder for 32-bit size
- return pos;
- }
-
- public void endSize(int pos)
- {
- Debug.Assert(pos >= 0);
- rewriteInt(_buf.b.position() - pos - 4, pos);
- }
-
- public void writeBlob(byte[] v)
- {
- if(v == null)
- {
- return;
- }
- expand(v.Length);
- _buf.b.put(v);
- }
-
- public void readBlob(byte[] v)
- {
- try
- {
- _buf.b.get(v);
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public byte[] readBlob(int sz)
- {
- if(_buf.b.remaining() < sz)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- byte[] v = new byte[sz];
- try
- {
- _buf.b.get(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- // Read/write type and tag for optionals
- public bool writeOpt(int tag, Ice.OptionalFormat format)
- {
- Debug.Assert(_writeEncapsStack != null);
- if(_writeEncapsStack.encoder != null)
- {
- return _writeEncapsStack.encoder.writeOpt(tag, format);
- }
- else
- {
- return writeOptImpl(tag, format);
- }
- }
-
- public bool readOpt(int tag, Ice.OptionalFormat expectedFormat)
- {
- Debug.Assert(_readEncapsStack != null);
- if(_readEncapsStack.decoder != null)
- {
- return _readEncapsStack.decoder.readOpt(tag, expectedFormat);
- }
- else
- {
- return readOptImpl(tag, expectedFormat);
- }
- }
-
- public void writeByte(byte v)
- {
- expand(1);
- _buf.b.put(v);
- }
-
- public void writeByte(int tag, Ice.Optional<byte> v)
- {
- if(v.HasValue)
- {
- writeByte(tag, v.Value);
- }
- }
-
- public void writeByte(int tag, byte v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F1))
- {
- writeByte(v);
- }
- }
-
- public void rewriteByte(byte v, int dest)
- {
- _buf.b.put(dest, v);
- }
-
- public void writeByteSeq(byte[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length);
- _buf.b.put(v);
- }
- }
-
- public void writeByteSeq(int count, IEnumerable<byte> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<byte> value = v as List<byte>;
- if(value != null)
- {
- writeByteSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<byte> value = v as LinkedList<byte>;
- if(value != null)
- {
- writeSize(count);
- expand(count);
- IEnumerator<byte> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.put(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<byte> value = v as Queue<byte>;
- if(value != null)
- {
- writeByteSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<byte> value = v as Stack<byte>;
- if(value != null)
- {
- writeByteSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count);
- foreach(byte b in v)
- {
- _buf.b.put(b);
- }
- }
-
- public void writeByteSeq(int tag, Ice.Optional<byte[]> v)
- {
- if(v.HasValue)
- {
- writeByteSeq(tag, v.Value);
- }
- }
-
- public void writeByteSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<byte>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeByteSeq(count, v.Value);
- }
- }
-
- public void writeByteSeq(int tag, byte[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeByteSeq(v);
- }
- }
-
- public void writeByteSeq(int tag, int count, IEnumerable<byte> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeByteSeq(count, v);
- }
- }
-
- public void writeSerializable(object o)
- {
-#if !COMPACT && !SILVERLIGHT
- if(o == null)
- {
- writeSize(0);
- return;
- }
- try
- {
- StreamWrapper w = new StreamWrapper(this);
- IFormatter f = new BinaryFormatter();
- f.Serialize(w, o);
- w.Close();
- }
- catch(System.Exception ex)
- {
- throw new Ice.MarshalException("cannot serialize object:", ex);
- }
-#else
- throw new Ice.MarshalException("serialization not supported");
-#endif
- }
-
- public byte readByte()
- {
- try
- {
- return _buf.b.get();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<byte> readByte(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F1))
- {
- return new Ice.Optional<byte>(readByte());
- }
- else
- {
- return new Ice.Optional<byte>();
- }
- }
-
- public void readByte(int tag, out bool isset, out byte v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F1))
- {
- v = readByte();
- }
- else
- {
- v = 0;
- }
- }
-
- public byte[] readByteSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(1);
- byte[] v = new byte[sz];
- _buf.b.get(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readByteSeq(out List<byte> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<byte>(readByteSeq());
- }
-
- public void readByteSeq(out LinkedList<byte> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new LinkedList<byte>(readByteSeq());
- }
-
- public void readByteSeq(out Queue<byte> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue is faster than constructing the queue
- // and adding to it one element at a time.
- //
- l = new Queue<byte>(readByteSeq());
- }
-
- public void readByteSeq(out Stack<byte> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- byte[] array = readByteSeq();
- Array.Reverse(array);
- l = new Stack<byte>(array);
- }
-
- public Ice.Optional<byte[]> readByteSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- return new Ice.Optional<byte[]>(readByteSeq());
- }
- else
- {
- return new Ice.Optional<byte[]>();
- }
- }
-
- public void readByteSeq(int tag, out bool isset, out byte[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- v = readByteSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public object readSerializable()
- {
-#if !COMPACT && !SILVERLIGHT
- int sz = readAndCheckSeqSize(1);
- if(sz == 0)
- {
- return null;
- }
- try
- {
- StreamWrapper w = new StreamWrapper(sz, this);
- IFormatter f = new BinaryFormatter();
- return f.Deserialize(w);
- }
- catch(System.Exception ex)
- {
- throw new Ice.MarshalException("cannot deserialize object:", ex);
- }
-#else
- throw new Ice.MarshalException("serialization not supported");
-#endif
- }
-
- public void writeBool(bool v)
- {
- expand(1);
- _buf.b.put(v ? (byte)1 : (byte)0);
- }
-
- public void writeBool(int tag, Ice.Optional<bool> v)
- {
- if(v.HasValue)
- {
- writeBool(tag, v.Value);
- }
- }
-
- public void writeBool(int tag, bool v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F1))
- {
- writeBool(v);
- }
- }
-
- public void rewriteBool(bool v, int dest)
- {
- _buf.b.put(dest, v ? (byte)1 : (byte)0);
- }
-
- public void writeBoolSeq(bool[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length);
- _buf.b.putBoolSeq(v);
- }
- }
-
- public void writeBoolSeq(int count, IEnumerable<bool> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<bool> value = v as List<bool>;
- if(value != null)
- {
- writeBoolSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<bool> value = v as LinkedList<bool>;
- if(value != null)
- {
- writeSize(count);
- expand(count);
- IEnumerator<bool> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putBool(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<bool> value = v as Queue<bool>;
- if(value != null)
- {
- writeBoolSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<bool> value = v as Stack<bool>;
- if(value != null)
- {
- writeBoolSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count);
- foreach(bool b in v)
- {
- _buf.b.putBool(b);
- }
- }
-
- public void writeBoolSeq(int tag, Ice.Optional<bool[]> v)
- {
- if(v.HasValue)
- {
- writeBoolSeq(tag, v.Value);
- }
- }
-
- public void writeBoolSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<bool>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeBoolSeq(count, v.Value);
- }
- }
-
- public void writeBoolSeq(int tag, bool[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeBoolSeq(v);
- }
- }
-
- public void writeBoolSeq(int tag, int count, IEnumerable<bool> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeBoolSeq(count, v);
- }
- }
-
- public bool readBool()
- {
- try
- {
- return _buf.b.get() == 1;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<bool> readBool(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F1))
- {
- return new Ice.Optional<bool>(readBool());
- }
- else
- {
- return new Ice.Optional<bool>();
- }
- }
-
- public void readBool(int tag, out bool isset, out bool v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F1))
- {
- v = readBool();
- }
- else
- {
- v = false;
- }
- }
-
- public bool[] readBoolSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(1);
- bool[] v = new bool[sz];
- _buf.b.getBoolSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readBoolSeq(out List<bool> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<bool>(readBoolSeq());
- }
-
- public void readBoolSeq(out LinkedList<bool> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new LinkedList<bool>(readBoolSeq());
- }
-
- public void readBoolSeq(out Queue<bool> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue is faster than constructing the queue
- // and adding to it one element at a time.
- //
- l = new Queue<bool>(readBoolSeq());
- }
-
- public void readBoolSeq(out Stack<bool> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- bool[] array = readBoolSeq();
- Array.Reverse(array);
- l = new Stack<bool>(array);
- }
-
- public Ice.Optional<bool[]> readBoolSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- return new Ice.Optional<bool[]>(readBoolSeq());
- }
- else
- {
- return new Ice.Optional<bool[]>();
- }
- }
-
- public void readBoolSeq(int tag, out bool isset, out bool[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- v = readBoolSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeShort(short v)
- {
- expand(2);
- _buf.b.putShort(v);
- }
-
- public void writeShort(int tag, Ice.Optional<short> v)
- {
- if(v.HasValue)
- {
- writeShort(tag, v.Value);
- }
- }
-
- public void writeShort(int tag, short v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F2))
- {
- writeShort(v);
- }
- }
-
- public void writeShortSeq(short[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length * 2);
- _buf.b.putShortSeq(v);
- }
- }
-
- public void writeShortSeq(int count, IEnumerable<short> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<short> value = v as List<short>;
- if(value != null)
- {
- writeShortSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<short> value = v as LinkedList<short>;
- if(value != null)
- {
- writeSize(count);
- expand(count * 2);
- IEnumerator<short> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putShort(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<short> value = v as Queue<short>;
- if(value != null)
- {
- writeShortSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<short> value = v as Stack<short>;
- if(value != null)
- {
- writeShortSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count * 2);
- foreach(short s in v)
- {
- _buf.b.putShort(s);
- }
- }
-
- public void writeShortSeq(int tag, Ice.Optional<short[]> v)
- {
- if(v.HasValue)
- {
- writeShortSeq(tag, v.Value);
- }
- }
-
- public void writeShortSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<short>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(count == 0 ? 1 : count * 2 + (count > 254 ? 5 : 1));
- writeShortSeq(count, v.Value);
- }
- }
-
- public void writeShortSeq(int tag, short[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || v.Length == 0 ? 1 : v.Length * 2 + (v.Length > 254 ? 5 : 1));
- writeShortSeq(v);
- }
- }
-
- public void writeShortSeq(int tag, int count, IEnumerable<short> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || count == 0 ? 1 : count * 2 + (count > 254 ? 5 : 1));
- writeShortSeq(count, v);
- }
- }
-
- public short readShort()
- {
- try
- {
- return _buf.b.getShort();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<short> readShort(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F2))
- {
- return new Ice.Optional<short>(readShort());
- }
- else
- {
- return new Ice.Optional<short>();
- }
- }
-
- public void readShort(int tag, out bool isset, out short v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F2))
- {
- v = readShort();
- }
- else
- {
- v = 0;
- }
- }
-
- public short[] readShortSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(2);
- short[] v = new short[sz];
- _buf.b.getShortSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readShortSeq(out List<short> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<short>(readShortSeq());
- }
-
- public void readShortSeq(out LinkedList<short> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new LinkedList<short>(readShortSeq());
- }
-
- public void readShortSeq(out Queue<short> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue is faster than constructing the queue
- // and adding to it one element at a time.
- //
- l = new Queue<short>(readShortSeq());
- }
-
- public void readShortSeq(out Stack<short> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- short[] array = readShortSeq();
- Array.Reverse(array);
- l = new Stack<short>(array);
- }
-
- public Ice.Optional<short[]> readShortSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- return new Ice.Optional<short[]>(readShortSeq());
- }
- else
- {
- return new Ice.Optional<short[]>();
- }
- }
-
- public void readShortSeq(int tag, out bool isset, out short[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- v = readShortSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeInt(int v)
- {
- expand(4);
- _buf.b.putInt(v);
- }
-
- public void writeInt(int tag, Ice.Optional<int> v)
- {
- if(v.HasValue)
- {
- writeInt(tag, v.Value);
- }
- }
-
- public void writeInt(int tag, int v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F4))
- {
- writeInt(v);
- }
- }
-
- public void rewriteInt(int v, int dest)
- {
- _buf.b.putInt(dest, v);
- }
-
- public void writeIntSeq(int[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length * 4);
- _buf.b.putIntSeq(v);
- }
- }
-
- public void writeIntSeq(int count, IEnumerable<int> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<int> value = v as List<int>;
- if(value != null)
- {
- writeIntSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<int> value = v as LinkedList<int>;
- if(value != null)
- {
- writeSize(count);
- expand(count * 4);
- IEnumerator<int> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putInt(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<int> value = v as Queue<int>;
- if(value != null)
- {
- writeIntSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<int> value = v as Stack<int>;
- if(value != null)
- {
- writeIntSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count * 4);
- foreach(int i in v)
- {
- _buf.b.putInt(i);
- }
- }
-
- public void writeIntSeq(int tag, Ice.Optional<int[]> v)
- {
- if(v.HasValue)
- {
- writeIntSeq(tag, v.Value);
- }
- }
-
- public void writeIntSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<int>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
- writeIntSeq(count, v.Value);
- }
- }
-
- public void writeIntSeq(int tag, int[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || v.Length == 0 ? 1 : v.Length * 4 + (v.Length > 254 ? 5 : 1));
- writeIntSeq(v);
- }
- }
-
- public void writeIntSeq(int tag, int count, IEnumerable<int> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
- writeIntSeq(count, v);
- }
- }
-
- public int readInt()
- {
- try
- {
- return _buf.b.getInt();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<int> readInt(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F4))
- {
- return new Ice.Optional<int>(readInt());
- }
- else
- {
- return new Ice.Optional<int>();
- }
- }
-
- public void readInt(int tag, out bool isset, out int v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F4))
- {
- v = readInt();
- }
- else
- {
- v = 0;
- }
- }
-
- public int[] readIntSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- int[] v = new int[sz];
- _buf.b.getIntSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readIntSeq(out List<int> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<int>(readIntSeq());
- }
-
- public void readIntSeq(out LinkedList<int> l)
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new LinkedList<int>();
- for(int i = 0; i < sz; ++i)
- {
- l.AddLast(_buf.b.getInt());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readIntSeq(out Queue<int> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue takes the same time as constructing the queue
- // and adding to it one element at a time, so
- // we avoid the copy.
- //
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new Queue<int>(sz);
- for(int i = 0; i < sz; ++i)
- {
- l.Enqueue(_buf.b.getInt());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readIntSeq(out Stack<int> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- int[] array = readIntSeq();
- Array.Reverse(array);
- l = new Stack<int>(array);
- }
-
- public Ice.Optional<int[]> readIntSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- return new Ice.Optional<int[]>(readIntSeq());
- }
- else
- {
- return new Ice.Optional<int[]>();
- }
- }
-
- public void readIntSeq(int tag, out bool isset, out int[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- v = readIntSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeLong(long v)
- {
- expand(8);
- _buf.b.putLong(v);
- }
-
- public void writeLong(int tag, Ice.Optional<long> v)
- {
- if(v.HasValue)
- {
- writeLong(tag, v.Value);
- }
- }
-
- public void writeLong(int tag, long v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F8))
- {
- writeLong(v);
- }
- }
-
- public void writeLongSeq(long[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length * 8);
- _buf.b.putLongSeq(v);
- }
- }
-
- public void writeLongSeq(int count, IEnumerable<long> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<long> value = v as List<long>;
- if(value != null)
- {
- writeLongSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<long> value = v as LinkedList<long>;
- if(value != null)
- {
- writeSize(count);
- expand(count * 8);
- IEnumerator<long> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putLong(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<long> value = v as Queue<long>;
- if(value != null)
- {
- writeLongSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<long> value = v as Stack<long>;
- if(value != null)
- {
- writeLongSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count * 8);
- foreach(long l in v)
- {
- _buf.b.putLong(l);
- }
- }
-
- public void writeLongSeq(int tag, Ice.Optional<long[]> v)
- {
- if(v.HasValue)
- {
- writeLongSeq(tag, v.Value);
- }
- }
-
- public void writeLongSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<long>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
- writeLongSeq(count, v.Value);
- }
- }
-
- public void writeLongSeq(int tag, long[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || v.Length == 0 ? 1 : v.Length * 8 + (v.Length > 254 ? 5 : 1));
- writeLongSeq(v);
- }
- }
-
- public void writeLongSeq(int tag, int count, IEnumerable<long> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
- writeLongSeq(count, v);
- }
- }
-
- public long readLong()
- {
- try
- {
- return _buf.b.getLong();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<long> readLong(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F8))
- {
- return new Ice.Optional<long>(readLong());
- }
- else
- {
- return new Ice.Optional<long>();
- }
- }
-
- public void readLong(int tag, out bool isset, out long v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F8))
- {
- v = readLong();
- }
- else
- {
- v = 0;
- }
- }
-
- public long[] readLongSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(8);
- long[] v = new long[sz];
- _buf.b.getLongSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readLongSeq(out List<long> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<long>(readLongSeq());
- }
-
- public void readLongSeq(out LinkedList<long> l)
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new LinkedList<long>();
- for(int i = 0; i < sz; ++i)
- {
- l.AddLast(_buf.b.getLong());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readLongSeq(out Queue<long> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue takes the same time as constructing the queue
- // and adding to it one element at a time, so
- // we avoid the copy.
- //
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new Queue<long>(sz);
- for(int i = 0; i < sz; ++i)
- {
- l.Enqueue(_buf.b.getLong());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readLongSeq(out Stack<long> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- long[] array = readLongSeq();
- Array.Reverse(array);
- l = new Stack<long>(array);
- }
-
- public Ice.Optional<long[]> readLongSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- return new Ice.Optional<long[]>(readLongSeq());
- }
- else
- {
- return new Ice.Optional<long[]>();
- }
- }
-
- public void readLongSeq(int tag, out bool isset, out long[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- v = readLongSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeFloat(float v)
- {
- expand(4);
- _buf.b.putFloat(v);
- }
-
- public void writeFloat(int tag, Ice.Optional<float> v)
- {
- if(v.HasValue)
- {
- writeFloat(tag, v.Value);
- }
- }
-
- public void writeFloat(int tag, float v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F4))
- {
- writeFloat(v);
- }
- }
-
- public void writeFloatSeq(float[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length * 4);
- _buf.b.putFloatSeq(v);
- }
- }
-
- public void writeFloatSeq(int count, IEnumerable<float> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<float> value = v as List<float>;
- if(value != null)
- {
- writeFloatSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<float> value = v as LinkedList<float>;
- if(value != null)
- {
- writeSize(count);
- expand(count * 4);
- IEnumerator<float> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putFloat(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<float> value = v as Queue<float>;
- if(value != null)
- {
- writeFloatSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<float> value = v as Stack<float>;
- if(value != null)
- {
- writeFloatSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count * 4);
- foreach(float f in v)
- {
- _buf.b.putFloat(f);
- }
- }
-
- public void writeFloatSeq(int tag, Ice.Optional<float[]> v)
- {
- if(v.HasValue)
- {
- writeFloatSeq(tag, v.Value);
- }
- }
-
- public void writeFloatSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<float>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
- writeFloatSeq(count, v.Value);
- }
- }
-
- public void writeFloatSeq(int tag, float[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || v.Length == 0 ? 1 : v.Length * 4 + (v.Length > 254 ? 5 : 1));
- writeFloatSeq(v);
- }
- }
-
- public void writeFloatSeq(int tag, int count, IEnumerable<float> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
- writeFloatSeq(count, v);
- }
- }
-
- public float readFloat()
- {
- try
- {
- return _buf.b.getFloat();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<float> readFloat(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F4))
- {
- return new Ice.Optional<float>(readFloat());
- }
- else
- {
- return new Ice.Optional<float>();
- }
- }
-
- public void readFloat(int tag, out bool isset, out float v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F4))
- {
- v = readFloat();
- }
- else
- {
- v = 0;
- }
- }
-
- public float[] readFloatSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- float[] v = new float[sz];
- _buf.b.getFloatSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readFloatSeq(out List<float> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<float>(readFloatSeq());
- }
-
- public void readFloatSeq(out LinkedList<float> l)
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new LinkedList<float>();
- for(int i = 0; i < sz; ++i)
- {
- l.AddLast(_buf.b.getFloat());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readFloatSeq(out Queue<float> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue takes the same time as constructing the queue
- // and adding to it one element at a time, so
- // we avoid the copy.
- //
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new Queue<float>(sz);
- for(int i = 0; i < sz; ++i)
- {
- l.Enqueue(_buf.b.getFloat());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readFloatSeq(out Stack<float> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- float[] array = readFloatSeq();
- Array.Reverse(array);
- l = new Stack<float>(array);
- }
-
- public Ice.Optional<float[]> readFloatSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- return new Ice.Optional<float[]>(readFloatSeq());
- }
- else
- {
- return new Ice.Optional<float[]>();
- }
- }
-
- public void readFloatSeq(int tag, out bool isset, out float[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- v = readFloatSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeDouble(double v)
- {
- expand(8);
- _buf.b.putDouble(v);
- }
-
- public void writeDouble(int tag, Ice.Optional<double> v)
- {
- if(v.HasValue)
- {
- writeDouble(tag, v.Value);
- }
- }
-
- public void writeDouble(int tag, double v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.F8))
- {
- writeDouble(v);
- }
- }
-
- public void writeDoubleSeq(double[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- expand(v.Length * 8);
- _buf.b.putDoubleSeq(v);
- }
- }
-
- public void writeDoubleSeq(int count, IEnumerable<double> v)
- {
- if(count == 0)
- {
- writeSize(0);
- return;
- }
-
- {
- List<double> value = v as List<double>;
- if(value != null)
- {
- writeDoubleSeq(value.ToArray());
- return;
- }
- }
-
- {
- LinkedList<double> value = v as LinkedList<double>;
- if(value != null)
- {
- writeSize(count);
- expand(count * 8);
- IEnumerator<double> i = v.GetEnumerator();
- while(i.MoveNext())
- {
- _buf.b.putDouble(i.Current);
- }
- return;
- }
- }
-
- {
- Queue<double> value = v as Queue<double>;
- if(value != null)
- {
- writeDoubleSeq(value.ToArray());
- return;
- }
- }
-
- {
- Stack<double> value = v as Stack<double>;
- if (value != null)
- {
- writeDoubleSeq(value.ToArray());
- return;
- }
- }
-
- writeSize(count);
- expand(count * 8);
- foreach(double d in v)
- {
- _buf.b.putDouble(d);
- }
- }
-
- public void writeDoubleSeq(int tag, Ice.Optional<double[]> v)
- {
- if(v.HasValue)
- {
- writeDoubleSeq(tag, v.Value);
- }
- }
-
- public void writeDoubleSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<double>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
- writeDoubleSeq(count, v.Value);
- }
- }
-
- public void writeDoubleSeq(int tag, double[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || v.Length == 0 ? 1 : v.Length * 8 + (v.Length > 254 ? 5 : 1));
- writeDoubleSeq(v);
- }
- }
-
- public void writeDoubleSeq(int tag, int count, IEnumerable<double> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeSize(v == null || count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
- writeDoubleSeq(count, v);
- }
- }
-
- public double readDouble()
- {
- try
- {
- return _buf.b.getDouble();
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public Ice.Optional<double> readDouble(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.F8))
- {
- return new Ice.Optional<double>(readDouble());
- }
- else
- {
- return new Ice.Optional<double>();
- }
- }
-
- public void readDouble(int tag, out bool isset, out double v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.F8))
- {
- v = readDouble();
- }
- else
- {
- v = 0;
- }
- }
-
- public double[] readDoubleSeq()
- {
- try
- {
- int sz = readAndCheckSeqSize(8);
- double[] v = new double[sz];
- _buf.b.getDoubleSeq(v);
- return v;
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readDoubleSeq(out List<double> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is faster than constructing the list
- // and adding to it one element at a time.
- //
- l = new List<double>(readDoubleSeq());
- }
-
- public void readDoubleSeq(out LinkedList<double> l)
- {
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new LinkedList<double>();
- for(int i = 0; i < sz; ++i)
- {
- l.AddLast(_buf.b.getDouble());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readDoubleSeq(out Queue<double> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue takes the same time as constructing the queue
- // and adding to it one element at a time, so
- // we avoid the copy.
- //
- try
- {
- int sz = readAndCheckSeqSize(4);
- l = new Queue<double>(sz);
- for(int i = 0; i < sz; ++i)
- {
- l.Enqueue(_buf.b.getDouble());
- }
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- }
-
- public void readDoubleSeq(out Stack<double> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- double[] array = readDoubleSeq();
- Array.Reverse(array);
- l = new Stack<double>(array);
- }
-
- public Ice.Optional<double[]> readDoubleSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- return new Ice.Optional<double[]>(readDoubleSeq());
- }
- else
- {
- return new Ice.Optional<double[]>();
- }
- }
-
- public void readDoubleSeq(int tag, out bool isset, out double[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- skipSize();
- v = readDoubleSeq();
- }
- else
- {
- v = null;
- }
- }
-
- private static System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding(false, true);
-
- public void writeString(string v)
- {
- if(v == null || v.Length == 0)
- {
- writeSize(0);
- return;
- }
- byte[] arr = utf8.GetBytes(v);
- writeSize(arr.Length);
- expand(arr.Length);
- _buf.b.put(arr);
- }
-
- public void writeString(int tag, Ice.Optional<string> v)
- {
- if(v.HasValue)
- {
- writeString(tag, v.Value);
- }
- }
-
- public void writeString(int tag, string v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.VSize))
- {
- writeString(v);
- }
- }
-
- public void writeStringSeq(string[] v)
- {
- if(v == null)
- {
- writeSize(0);
- }
- else
- {
- writeSize(v.Length);
- for(int i = 0; i < v.Length; i++)
- {
- writeString(v[i]);
- }
- }
- }
-
- public void writeStringSeq(int size, IEnumerable<string> e)
- {
- writeSize(size);
- if(size != 0)
- {
- foreach(string s in e)
- {
- writeString(s);
- }
- }
- }
-
- public void writeStringSeq(int tag, Ice.Optional<String[]> v)
- {
- if(v.HasValue)
- {
- writeStringSeq(tag, v.Value);
- }
- }
-
- public void writeStringSeq<T>(int tag, int count, Ice.Optional<T> v)
- where T : IEnumerable<string>
- {
- if(v.HasValue && writeOpt(tag, Ice.OptionalFormat.FSize))
- {
- int pos = startSize();
- writeStringSeq(count, v.Value);
- endSize(pos);
- }
- }
-
- public void writeStringSeq(int tag, string[] v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.FSize))
- {
- int pos = startSize();
- writeStringSeq(v);
- endSize(pos);
- }
- }
-
- public void writeStringSeq(int tag, int count, IEnumerable<string> v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.FSize))
- {
- int pos = startSize();
- writeStringSeq(count, v);
- endSize(pos);
- }
- }
-
- public string readString()
- {
- int len = readSize();
-
- if(len == 0)
- {
- return "";
- }
-
- //
- // Check the buffer has enough bytes to read.
- //
- if(_buf.b.remaining() < len)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
-
- try
- {
- //
- // We reuse the _stringBytes array to avoid creating
- // excessive garbage
- //
- if(_stringBytes == null || len > _stringBytes.Length)
- {
- _stringBytes = new byte[len];
- }
- _buf.b.get(_stringBytes, 0, len);
- return utf8.GetString(_stringBytes, 0, len);
- }
- catch(InvalidOperationException ex)
- {
- throw new Ice.UnmarshalOutOfBoundsException(ex);
- }
- catch(System.ArgumentException ex)
- {
- throw new Ice.MarshalException("Invalid UTF8 string", ex);
- }
- }
-
- public Ice.Optional<string> readString(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.VSize))
- {
- return new Ice.Optional<string>(readString());
- }
- else
- {
- return new Ice.Optional<string>();
- }
- }
-
- public void readString(int tag, out bool isset, out string v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.VSize))
- {
- v = readString();
- }
- else
- {
- v = null;
- }
- }
-
- public string[] readStringSeq()
- {
- int sz = readAndCheckSeqSize(1);
- string[] v = new string[sz];
- for(int i = 0; i < sz; i++)
- {
- v[i] = readString();
- }
- return v;
- }
-
- public void readStringSeq(out List<string> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is slower than constructing the list
- // and adding to it one element at a time.
- //
- int sz = readAndCheckSeqSize(1);
- l = new List<string>(sz);
- for(int i = 0; i < sz; ++i)
- {
- l.Add(readString());
- }
- }
-
- public void readStringSeq(out LinkedList<string> l)
- {
- //
- // Reading into an array and copy-constructing the
- // list is slower than constructing the list
- // and adding to it one element at a time.
- //
- int sz = readAndCheckSeqSize(1);
- l = new LinkedList<string>();
- for(int i = 0; i < sz; ++i)
- {
- l.AddLast(readString());
- }
- }
-
- public void readStringSeq(out Queue<string> l)
- {
- //
- // Reading into an array and copy-constructing the
- // queue is slower than constructing the queue
- // and adding to it one element at a time.
- //
- int sz = readAndCheckSeqSize(1);
- l = new Queue<string>();
- for(int i = 0; i < sz; ++i)
- {
- l.Enqueue(readString());
- }
- }
-
- public void readStringSeq(out Stack<string> l)
- {
- //
- // Reverse the contents by copying into an array first
- // because the stack is marshaled in top-to-bottom order.
- //
- string[] array = readStringSeq();
- Array.Reverse(array);
- l = new Stack<string>(array);
- }
-
- public Ice.Optional<string[]> readStringSeq(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.FSize))
- {
- skip(4);
- return new Ice.Optional<string[]>(readStringSeq());
- }
- else
- {
- return new Ice.Optional<string[]>();
- }
- }
-
- public void readStringSeq(int tag, out bool isset, out string[] v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.FSize))
- {
- skip(4);
- v = readStringSeq();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeProxy(Ice.ObjectPrx v)
- {
- instance_.proxyFactory().proxyToStream(v, this);
- }
-
- public void writeProxy(int tag, Ice.Optional<Ice.ObjectPrx> v)
- {
- if(v.HasValue)
- {
- writeProxy(tag, v.Value);
- }
- }
-
- public void writeProxy(int tag, Ice.ObjectPrx v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.FSize))
- {
- int pos = startSize();
- writeProxy(v);
- endSize(pos);
- }
- }
-
- public Ice.ObjectPrx readProxy()
- {
- return instance_.proxyFactory().streamToProxy(this);
- }
-
- public Ice.Optional<Ice.ObjectPrx> readProxy(int tag)
- {
- if(readOpt(tag, Ice.OptionalFormat.FSize))
- {
- skip(4);
- return new Ice.Optional<Ice.ObjectPrx>(readProxy());
- }
- else
- {
- return new Ice.Optional<Ice.ObjectPrx>();
- }
- }
-
- public void readProxy(int tag, out bool isset, out Ice.ObjectPrx v)
- {
- if(isset = readOpt(tag, Ice.OptionalFormat.FSize))
- {
- skip(4);
- v = readProxy();
- }
- else
- {
- v = null;
- }
- }
-
- public void writeEnum(int v, int maxValue)
- {
- if(isWriteEncoding_1_0())
- {
- if(maxValue < 127)
- {
- writeByte((byte)v);
- }
- else if(maxValue < 32767)
- {
- writeShort((short)v);
- }
- else
- {
- writeInt(v);
- }
- }
- else
- {
- writeSize(v);
- }
- }
-
- public void writeEnum(int tag, int v, int maxValue)
- {
- if(writeOpt(tag, Ice.OptionalFormat.Size))
- {
- writeEnum(v, maxValue);
- }
- }
-
- public int readEnum(int maxValue)
- {
- if(getReadEncoding().Equals(Ice.Util.Encoding_1_0))
- {
- if(maxValue < 127)
- {
- return readByte();
- }
- else if(maxValue < 32767)
- {
- return readShort();
- }
- else
- {
- return readInt();
- }
- }
- else
- {
- return readSize();
- }
- }
-
- public void writeObject(Ice.Object v)
- {
- initWriteEncaps();
- _writeEncapsStack.encoder.writeObject(v);
- }
-
- public void writeObject<T>(int tag, Ice.Optional<T> v)
- where T : Ice.Object
- {
- if(v.HasValue)
- {
- writeObject(tag, v.Value);
- }
- }
-
- public void writeObject(int tag, Ice.Object v)
- {
- if(writeOpt(tag, Ice.OptionalFormat.Class))
- {
- writeObject(v);
- }
- }
-
- public void readObject(IPatcher patcher)
- {
- initReadEncaps();
- _readEncapsStack.decoder.readObject(patcher);
- }
-
- public void readObject(int tag, IPatcher patcher)
- {
- if(readOpt(tag, Ice.OptionalFormat.Class))
- {
- readObject(patcher);
- }
- }
-
- public void writeUserException(Ice.UserException v)
- {
- initWriteEncaps();
- _writeEncapsStack.encoder.writeUserException(v);
- }
-
- public void throwException(UserExceptionFactory factory)
- {
- initReadEncaps();
- _readEncapsStack.decoder.throwException(factory);
- }
-
- public void sliceObjects(bool b)
- {
- _sliceObjects = b;
- }
-
- public bool readOptImpl(int readTag, Ice.OptionalFormat expectedFormat)
- {
- if(isReadEncoding_1_0())
- {
- return false; // Optional members aren't supported with the 1.0 encoding.
- }
-
- while(true)
- {
- if(_buf.b.position() >= _readEncapsStack.start + _readEncapsStack.sz)
- {
- return false; // End of encapsulation also indicates end of optionals.
- }
-
- int v = readByte();
- if(v == OPTIONAL_END_MARKER)
- {
- _buf.b.position(_buf.b.position() - 1); // Rewind.
- return false;
- }
-
- Ice.OptionalFormat format = (Ice.OptionalFormat)(v & 0x07); // First 3 bits.
- int tag = v >> 3;
- if(tag == 30)
- {
- tag = readSize();
- }
-
- if(tag > readTag)
- {
- int offset = tag < 30 ? 1 : (tag < 255 ? 2 : 6); // Rewind
- _buf.b.position(_buf.b.position() - offset);
- return false; // No optional data members with the requested tag.
- }
- else if(tag < readTag)
- {
- skipOpt(format); // Skip optional data members
- }
- else
- {
- if(format != expectedFormat)
- {
- throw new Ice.MarshalException("invalid optional data member `" + tag + "': unexpected format");
- }
- return true;
- }
- }
- }
-
- public bool writeOptImpl(int tag, Ice.OptionalFormat format)
- {
- if(isWriteEncoding_1_0())
- {
- return false; // Optional members aren't supported with the 1.0 encoding.
- }
-
- int v = (int)format;
- if(tag < 30)
- {
- v |= tag << 3;
- writeByte((byte)v);
- }
- else
- {
- v |= 0x0F0; // tag = 30
- writeByte((byte)v);
- writeSize(tag);
- }
- return true;
- }
-
- public void skipOpt(Ice.OptionalFormat format)
- {
- switch(format)
- {
- case Ice.OptionalFormat.F1:
- {
- skip(1);
- break;
- }
- case Ice.OptionalFormat.F2:
- {
- skip(2);
- break;
- }
- case Ice.OptionalFormat.F4:
- {
- skip(4);
- break;
- }
- case Ice.OptionalFormat.F8:
- {
- skip(8);
- break;
- }
- case Ice.OptionalFormat.Size:
- {
- skipSize();
- break;
- }
- case Ice.OptionalFormat.VSize:
- {
- skip(readSize());
- break;
- }
- case Ice.OptionalFormat.FSize:
- {
- skip(readInt());
- break;
- }
- case Ice.OptionalFormat.Class:
- {
- readObject(null);
- break;
- }
- }
- }
-
- public bool skipOpts()
- {
- //
- // Skip remaining un-read optional members.
- //
- while(true)
- {
- if(_buf.b.position() >= _readEncapsStack.start + _readEncapsStack.sz)
- {
- return false; // End of encapsulation also indicates end of optionals.
- }
-
- int v = readByte();
- if(v == OPTIONAL_END_MARKER)
- {
- return true;
- }
-
- Ice.OptionalFormat format = (Ice.OptionalFormat)(v & 0x07); // Read first 3 bits.
- if((v >> 3) == 30)
- {
- skipSize();
- }
- skipOpt(format);
- }
- }
-
- public void skip(int size)
- {
- if(size > _buf.b.remaining())
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- _buf.b.position(_buf.b.position() + size);
- }
-
- public void skipSize()
- {
- byte b = readByte();
- if(b == 255)
- {
- skip(4);
- }
- }
-
- public int pos()
- {
- return _buf.b.position();
- }
-
- public void pos(int n)
- {
- _buf.b.position(n);
- }
-
- public int size()
- {
- return _buf.size();
- }
-
-#if !MANAGED && !COMPACT && !SILVERLIGHT
- static string getBZ2Error(int error)
- {
- string rc;
-
- switch(error)
- {
- case BZ_SEQUENCE_ERROR:
- {
- rc = "BZ_SEQUENCE_ERROR";
- break;
- }
- case BZ_PARAM_ERROR:
- {
- rc = "BZ_PARAM_ERROR";
- break;
- }
- case BZ_MEM_ERROR:
- {
- rc = "BZ_MEM_ERROR";
- break;
- }
- case BZ_DATA_ERROR:
- {
- rc = "BZ_DATA_ERROR";
- break;
- }
- case BZ_DATA_ERROR_MAGIC:
- {
- rc = "BZ_DATA_ERROR_MAGIC";
- break;
- }
- case BZ_IO_ERROR:
- {
- rc = "BZ_IO_ERROR";
- break;
- }
- case BZ_UNEXPECTED_EOF:
- {
- rc = "BZ_UNEXPECTED_EOF";
- break;
- }
- case BZ_OUTBUFF_FULL:
- {
- rc = "BZ_OUTBUFF_FULL";
- break;
- }
- case BZ_CONFIG_ERROR:
- {
- rc = "BZ_CONFIG_ERROR";
- break;
- }
- default:
- {
- rc = "Unknown bzip2 error: " + error;
- break;
- }
- }
- return rc;
- }
-#endif
-
- public static bool compressible()
- {
- return _bzlibInstalled;
- }
-
- public bool compress(ref BasicStream cstream, int headerSize, int compressionLevel)
- {
-#if MANAGED || COMPACT || SILVERLIGHT
- cstream = this;
- return false;
-#else
- if(!_bzlibInstalled)
- {
- cstream = this;
- return false;
- }
-
- //
- // Compress the message body, but not the header.
- //
- int uncompressedLen = size() - headerSize;
- byte[] uncompressed = _buf.b.rawBytes(headerSize, uncompressedLen);
- int compressedLen = (int)(uncompressedLen * 1.01 + 600);
- byte[] compressed = new byte[compressedLen];
-
- int rc = NativeMethods.BZ2_bzBuffToBuffCompress(compressed, ref compressedLen, uncompressed,
- uncompressedLen, compressionLevel, 0, 0);
- if(rc == BZ_OUTBUFF_FULL)
- {
- cstream = null;
- return false;
- }
- else if(rc < 0)
- {
- Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffCompress failed");
- ex.reason = getBZ2Error(rc);
- throw ex;
- }
-
- //
- // Don't bother if the compressed data is larger than the
- // uncompressed data.
- //
- if(compressedLen >= uncompressedLen)
- {
- return false;
- }
-
- cstream = new BasicStream(instance_, _encoding);
- cstream.resize(headerSize + 4 + compressedLen, false);
- cstream.pos(0);
-
- //
- // Copy the header from the uncompressed stream to the
- // compressed one.
- //
- cstream._buf.b.put(_buf.b.rawBytes(0, headerSize));
-
- //
- // Add the size of the uncompressed stream before the
- // message body.
- //
- cstream.writeInt(size());
-
- //
- // Add the compressed message body.
- //
- cstream._buf.b.put(compressed, 0, compressedLen);
-
- return true;
-#endif
- }
-
- public BasicStream uncompress(int headerSize, int messageSizeMax)
- {
-#if MANAGED || COMPACT || SILVERLIGHT
- return this;
-#else
- if(!_bzlibInstalled)
- {
- return this;
- }
-
- pos(headerSize);
- int uncompressedSize = readInt();
- if(uncompressedSize <= headerSize)
- {
- throw new Ice.IllegalMessageSizeException("compressed size <= header size");
- }
- if(uncompressedSize > messageSizeMax)
- {
- IceInternal.Ex.throwMemoryLimitException(uncompressedSize, messageSizeMax);
- }
-
- int compressedLen = size() - headerSize - 4;
- byte[] compressed = _buf.b.rawBytes(headerSize + 4, compressedLen);
- int uncompressedLen = uncompressedSize - headerSize;
- byte[] uncompressed = new byte[uncompressedLen];
- int rc = NativeMethods.BZ2_bzBuffToBuffDecompress(uncompressed, ref uncompressedLen, compressed,
- compressedLen, 0, 0);
- if(rc < 0)
- {
- Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffDecompress failed");
- ex.reason = getBZ2Error(rc);
- throw ex;
- }
- BasicStream ucStream = new BasicStream(instance_, _encoding);
- ucStream.resize(uncompressedSize, false);
- ucStream.pos(0);
- ucStream._buf.b.put(_buf.b.rawBytes(0, headerSize));
- ucStream._buf.b.put(uncompressed, 0, uncompressedLen);
- return ucStream;
-#endif
- }
-
- public bool isEmpty()
- {
- return _buf.empty();
- }
-
- public void expand(int n)
- {
- _buf.expand(n);
- }
-
- private Ice.Object createObject(string id)
- {
- Ice.Object obj = null;
-
- try
- {
- Type c = AssemblyUtil.findType(instance_, typeToClass(id));
- //
- // Ensure the class is instantiable.
- //
- if(c != null && !c.IsAbstract && !c.IsInterface)
- {
- obj = (Ice.Object)AssemblyUtil.createInstance(c);
- }
- }
- catch(Exception ex)
- {
- Ice.NoObjectFactoryException e = new Ice.NoObjectFactoryException(ex);
- e.type = id;
- throw e;
- }
-
- return obj;
- }
-
- private string getTypeId(int compactId)
- {
- String className = "IceCompactId.TypeId_" + compactId;
- try
- {
- Type c = AssemblyUtil.findType(instance_, className);
- if(c != null)
- {
- return (string)c.GetField("typeId").GetValue(null);
- }
- }
- catch(Exception)
- {
- }
- return "";
- }
-
- private sealed class DynamicUserExceptionFactory : UserExceptionFactory
- {
- internal DynamicUserExceptionFactory(Type c)
- {
- _class = c;
- }
-
- public void createAndThrow(string typeId)
- {
- try
- {
- throw (Ice.UserException)AssemblyUtil.createInstance(_class);
- }
- catch(Ice.UserException)
- {
- throw;
- }
- catch(Exception ex)
- {
- throw new Ice.SyscallException(ex);
- }
- }
-
- public void destroy()
- {
- }
-
- private Type _class;
- }
-
- private Ice.UserException createUserException(string id)
- {
- Ice.UserException userEx = null;
-
- try
- {
- Type c = AssemblyUtil.findType(instance_, typeToClass(id));
- if(c != null)
- {
- //
- // Ensure the class is instantiable.
- //
- Debug.Assert(!c.IsAbstract && !c.IsInterface);
- userEx = (Ice.UserException)AssemblyUtil.createInstance(c);
- }
- }
- catch(Exception ex)
- {
- throw new Ice.MarshalException(ex);
- }
-
- return userEx;
- }
-
- private static string typeToClass(string id)
- {
- if(!id.StartsWith("::", StringComparison.Ordinal))
- {
- throw new Ice.MarshalException("expected type id but received `" + id + "'");
- }
- return id.Substring(2).Replace("::", ".");
- }
-
- //
- // Optional data member type.
- //
- internal const int MemberFormatF1 = 0;
- internal const int MemberFormatF2 = 1;
- internal const int MemberFormatF4 = 2;
- internal const int MemberFormatF8 = 3;
- internal const int MemberFormatVSize = 4;
- internal const int MemberFormatFSize = 5;
- internal const int MemberFormatReserved = 6;
- internal const int MemberFormatEndMarker = 7;
-
- private Instance instance_;
- private Buffer _buf;
- private object _closure;
- private byte[] _stringBytes; // Reusable array for reading strings.
-
- private enum SliceType { NoSlice, ObjectSlice, ExceptionSlice }
-
- abstract private class EncapsDecoder
- {
- internal EncapsDecoder(BasicStream stream, ReadEncaps encaps, bool sliceObjects, ObjectFactoryManager f)
- {
- _stream = stream;
- _encaps = encaps;
- _sliceObjects = sliceObjects;
- _servantFactoryManager = f;
- _typeIdIndex = 0;
- _unmarshaledMap = new Dictionary<int, Ice.Object>();
- }
-
- internal abstract void readObject(IPatcher patcher);
- internal abstract void throwException(UserExceptionFactory factory);
-
- internal abstract void startInstance(SliceType type);
- internal abstract Ice.SlicedData endInstance(bool preserve);
- internal abstract string startSlice();
- internal abstract void endSlice();
- internal abstract void skipSlice();
-
- internal virtual bool readOpt(int tag, Ice.OptionalFormat format)
- {
- return false;
- }
-
- internal virtual void readPendingObjects()
- {
- }
-
- protected string readTypeId(bool isIndex)
- {
- if(_typeIdMap == null)
- {
- _typeIdMap = new Dictionary<int, string>();
- }
-
- if(isIndex)
- {
- int index = _stream.readSize();
- string typeId;
- if(!_typeIdMap.TryGetValue(index, out typeId))
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- return typeId;
- }
- else
- {
- string typeId = _stream.readString();
- _typeIdMap.Add(++_typeIdIndex, typeId);
- return typeId;
- }
- }
-
- protected Ice.Object newInstance(string typeId)
- {
- //
- // Try to find a factory registered for the specific type.
- //
- Ice.ObjectFactory userFactory = _servantFactoryManager.find(typeId);
- Ice.Object v = null;
- if(userFactory != null)
- {
- v = userFactory.create(typeId);
- }
-
- //
- // If that fails, invoke the default factory if one has been
- // registered.
- //
- if(v == null)
- {
- userFactory = _servantFactoryManager.find("");
- if(userFactory != null)
- {
- v = userFactory.create(typeId);
- }
- }
-
- //
- // Last chance: try to instantiate the class dynamically.
- //
- if(v == null)
- {
- v = _stream.createObject(typeId);
- }
-
- return v;
- }
-
- protected void addPatchEntry(int index, IPatcher patcher)
- {
- Debug.Assert(index > 0);
-
- //
- // Check if already un-marshalled the object. If that's the case,
- // just patch the object smart pointer and we're done.
- //
- Ice.Object obj;
- if(_unmarshaledMap.TryGetValue(index, out obj))
- {
- patcher.patch(obj);
- return;
- }
-
- if(_patchMap == null)
- {
- _patchMap = new Dictionary<int, LinkedList<IPatcher>>();
- }
-
- //
- // Add patch entry if the object isn't un-marshalled yet,
- // the smart pointer will be patched when the instance is
- // un-marshalled.
- //
- LinkedList<IPatcher> l;
- if(!_patchMap.TryGetValue(index, out l))
- {
- //
- // We have no outstanding instances to be patched for this
- // index, so make a new entry in the patch map.
- //
- l = new LinkedList<IPatcher>();
- _patchMap.Add(index, l);
- }
-
- //
- // Append a patch entry for this instance.
- //
- l.AddLast(patcher);
- }
-
- protected void unmarshal(int index, Ice.Object v)
- {
- //
- // Add the object to the map of un-marshalled objects, this must
- // be done before reading the objects (for circular references).
- //
- _unmarshaledMap.Add(index, v);
-
- //
- // Read the object.
- //
- v.read__(_stream);
-
- if(_patchMap != null)
- {
- //
- // Patch all instances now that the object is un-marshalled.
- //
- LinkedList<IPatcher> l;
- if(_patchMap.TryGetValue(index, out l))
- {
- Debug.Assert(l.Count > 0);
-
- //
- // Patch all pointers that refer to the instance.
- //
- foreach(IPatcher p in l)
- {
- p.patch(v);
- }
-
- //
- // Clear out the patch map for that index -- there is nothing left
- // to patch for that index for the time being.
- //
- _patchMap.Remove(index);
- }
- }
-
- if((_patchMap == null || _patchMap.Count == 0) && _objectList == null)
- {
- try
- {
- v.ice_postUnmarshal();
- }
- catch(System.Exception ex)
- {
- string s = "exception raised by ice_postUnmarshal:\n" + ex;
- _stream.instance().initializationData().logger.warning(s);
- }
- }
- else
- {
- if(_objectList == null)
- {
- _objectList = new List<Ice.Object>();
- }
- _objectList.Add(v);
-
- if(_patchMap == null || _patchMap.Count == 0)
- {
- //
- // Iterate over the object list and invoke ice_postUnmarshal on
- // each object. We must do this after all objects have been
- // unmarshaled in order to ensure that any object data members
- // have been properly patched.
- //
- foreach(Ice.Object p in _objectList)
- {
- try
- {
- p.ice_postUnmarshal();
- }
- catch(System.Exception ex)
- {
- string s = "exception raised by ice_postUnmarshal:\n" + ex;
- _stream.instance().initializationData().logger.warning(s);
- }
- }
- _objectList.Clear();
- }
- }
- }
-
- protected readonly BasicStream _stream;
- protected readonly ReadEncaps _encaps;
- protected readonly bool _sliceObjects;
- protected ObjectFactoryManager _servantFactoryManager;
-
- // Encapsulation attributes for object un-marshalling
- protected Dictionary<int, LinkedList<IPatcher> > _patchMap;
-
- // Encapsulation attributes for object un-marshalling
- private Dictionary<int, Ice.Object> _unmarshaledMap;
- private Dictionary<int, string> _typeIdMap;
- private int _typeIdIndex;
- private List<Ice.Object> _objectList;
- };
-
- private sealed class EncapsDecoder10 : EncapsDecoder
- {
- internal EncapsDecoder10(BasicStream stream, ReadEncaps encaps, bool sliceObjects, ObjectFactoryManager f)
- : base(stream, encaps, sliceObjects, f)
- {
- _sliceType = SliceType.NoSlice;
- }
-
- internal override void readObject(IPatcher patcher)
- {
- Debug.Assert(patcher != null);
-
- //
- // Object references are encoded as a negative integer in 1.0.
- //
- int index = _stream.readInt();
- if(index > 0)
- {
- throw new Ice.MarshalException("invalid object id");
- }
- index = -index;
-
- if(index == 0)
- {
- patcher.patch(null);
- }
- else
- {
- addPatchEntry(index, patcher);
- }
- }
-
- internal override void throwException(UserExceptionFactory factory)
- {
- Debug.Assert(_sliceType == SliceType.NoSlice);
-
- //
- // User exception with the 1.0 encoding start with a bool flag
- // that indicates whether or not the exception has classes.
- //
- // This allows reading the pending objects even if some part of
- // the exception was sliced.
- //
- bool usesClasses = _stream.readBool();
-
- _sliceType = SliceType.ExceptionSlice;
- _skipFirstSlice = false;
-
- //
- // Read the first slice header.
- //
- startSlice();
- string mostDerivedId = _typeId;
- while(true)
- {
- Ice.UserException userEx = null;
-
- //
- // Use a factory if one was provided.
- //
- if(factory != null)
- {
- try
- {
- factory.createAndThrow(_typeId);
- }
- catch(Ice.UserException ex)
- {
- userEx = ex;
- }
- }
-
- if(userEx == null)
- {
- userEx = _stream.createUserException(_typeId);
- }
-
- //
- // We found the exception.
- //
- if(userEx != null)
- {
- userEx.read__(_stream);
- if(usesClasses)
- {
- readPendingObjects();
- }
- throw userEx;
-
- // Never reached.
- }
-
- //
- // Slice off what we don't understand.
- //
- skipSlice();
- try
- {
- startSlice();
- }
- catch(Ice.UnmarshalOutOfBoundsException ex)
- {
- //
- // An oversight in the 1.0 encoding means there is no marker to indicate
- // the last slice of an exception. As a result, we just try to read the
- // next type ID, which raises UnmarshalOutOfBoundsException when the
- // input buffer underflows.
- //
- // Set the reason member to a more helpful message.
- //
- ex.reason = "unknown exception type `" + mostDerivedId + "'";
- throw ex;
- }
- }
- }
-
- internal override void startInstance(SliceType sliceType)
- {
- Debug.Assert(_sliceType == sliceType);
- _skipFirstSlice = true;
- }
-
- internal override Ice.SlicedData endInstance(bool preserve)
- {
- //
- // Read the Ice::Object slice.
- //
- if(_sliceType == SliceType.ObjectSlice)
- {
- startSlice();
- int sz = _stream.readSize(); // For compatibility with the old AFM.
- if(sz != 0)
- {
- throw new Ice.MarshalException("invalid Object slice");
- }
- endSlice();
- }
-
- _sliceType = SliceType.NoSlice;
- return null;
- }
-
- internal override string startSlice()
- {
- //
- // If first slice, don't read the header, it was already read in
- // readInstance or throwException to find the factory.
- //
- if(_skipFirstSlice)
- {
- _skipFirstSlice = false;
- return _typeId;
- }
-
- //
- // For objects, first read the type ID bool which indicates
- // whether or not the type ID is encoded as a string or as an
- // index. For exceptions, the type ID is always encoded as a
- // string.
- //
- if(_sliceType == SliceType.ObjectSlice) // For exceptions, the type ID is always encoded as a string
- {
- bool isIndex = _stream.readBool();
- _typeId = readTypeId(isIndex);
- }
- else
- {
- _typeId = _stream.readString();
- }
-
- _sliceSize = _stream.readInt();
- if(_sliceSize < 4)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
-
- return _typeId;
- }
-
- internal override void endSlice()
- {
- }
-
- internal override void skipSlice()
- {
- if(_stream.instance().traceLevels().slicing > 0)
- {
- Ice.Logger logger = _stream.instance().initializationData().logger;
- string slicingCat = _stream.instance().traceLevels().slicingCat;
- if(_sliceType == SliceType.ObjectSlice)
- {
- TraceUtil.traceSlicing("object", _typeId, slicingCat, logger);
- }
- else
- {
- TraceUtil.traceSlicing("exception", _typeId, slicingCat, logger);
- }
- }
-
- Debug.Assert(_sliceSize >= 4);
- _stream.skip(_sliceSize - 4);
- }
-
- internal override void readPendingObjects()
- {
- int num;
- do
- {
- num = _stream.readSize();
- for(int k = num; k > 0; --k)
- {
- readInstance();
- }
- }
- while(num > 0);
-
- if(_patchMap != null && _patchMap.Count > 0)
- {
- //
- // If any entries remain in the patch map, the sender has sent an index for an object, but failed
- // to supply the object.
- //
- throw new Ice.MarshalException("index for class received, but no instance");
- }
- }
-
- private void readInstance()
- {
- int index = _stream.readInt();
-
- if(index <= 0)
- {
- throw new Ice.MarshalException("invalid object id");
- }
-
- _sliceType = SliceType.ObjectSlice;
- _skipFirstSlice = false;
-
- //
- // Read the first slice header.
- //
- startSlice();
- string mostDerivedId = _typeId;
- Ice.Object v = null;
- while(true)
- {
- //
- // For the 1.0 encoding, the type ID for the base Object class
- // marks the last slice.
- //
- if(_typeId.Equals(Ice.ObjectImpl.ice_staticId()))
- {
- throw new Ice.NoObjectFactoryException("", mostDerivedId);
- }
-
- v = newInstance(_typeId);
-
- //
- // We found a factory, we get out of this loop.
- //
- if(v != null)
- {
- break;
- }
-
- //
- // If object slicing is disabled, stop un-marshalling.
- //
- if(!_sliceObjects)
- {
- throw new Ice.NoObjectFactoryException("no object factory found and object slicing is disabled",
- _typeId);
- }
-
- //
- // Slice off what we don't understand.
- //
- skipSlice();
- startSlice(); // Read next Slice header for next iteration.
- }
-
- //
- // Un-marshal the object and add-it to the map of un-marshaled objects.
- //
- unmarshal(index, v);
- }
-
- // Object/exception attributes
- private SliceType _sliceType;
- private bool _skipFirstSlice;
-
- // Slice attributes
- private int _sliceSize;
- private string _typeId;
- }
-
- private sealed class EncapsDecoder11 : EncapsDecoder
- {
- internal EncapsDecoder11(BasicStream stream, ReadEncaps encaps, bool sliceObjects, ObjectFactoryManager f)
- : base(stream, encaps, sliceObjects, f)
- {
- _objectIdIndex = 1;
- _current = null;
- }
-
- internal override void readObject(IPatcher patcher)
- {
- int index = _stream.readSize();
- if(index < 0)
- {
- throw new Ice.MarshalException("invalid object id");
- }
- else if(index == 0)
- {
- if(patcher != null)
- {
- patcher.patch(null);
- }
- }
- else if(_current != null && (_current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) != 0)
- {
- //
- // When reading an object within a slice and there's an
- // indirect object table, always read an indirect reference
- // that points to an object from the indirect object table
- // marshaled at the end of the Slice.
- //
- // Maintain a list of indirect references. Note that the
- // indirect index starts at 1, so we decrement it by one to
- // derive an index into the indirection table that we'll read
- // at the end of the slice.
- //
- if(patcher != null)
- {
- if(_current.indirectPatchList == null)
- {
- _current.indirectPatchList = new Stack<IndirectPatchEntry>();
- }
- IndirectPatchEntry e = new IndirectPatchEntry();
- e.index = index - 1;
- e.patcher = patcher;
- _current.indirectPatchList.Push(e);
- }
- }
- else
- {
- readInstance(index, patcher);
- }
- }
-
- internal override void throwException(UserExceptionFactory factory)
- {
- Debug.Assert(_current == null);
-
- push(SliceType.ExceptionSlice);
-
- //
- // Read the first slice header.
- //
- startSlice();
- string mostDerivedId = _current.typeId;
- while(true)
- {
- Ice.UserException userEx = null;
-
- //
- // Use a factory if one was provided.
- //
- if(factory != null)
- {
- try
- {
- factory.createAndThrow(_current.typeId);
- }
- catch(Ice.UserException ex)
- {
- userEx = ex;
- }
- }
-
- if(userEx == null)
- {
- userEx = _stream.createUserException(_current.typeId);
- }
-
- //
- // We found the exception.
- //
- if(userEx != null)
- {
- userEx.read__(_stream);
- throw userEx;
-
- // Never reached.
- }
-
- //
- // Slice off what we don't understand.
- //
- skipSlice();
-
- if((_current.sliceFlags & FLAG_IS_LAST_SLICE) != 0)
- {
- if(mostDerivedId.StartsWith("::", StringComparison.Ordinal))
- {
- throw new Ice.UnknownUserException(mostDerivedId.Substring(2));
- }
- else
- {
- throw new Ice.UnknownUserException(mostDerivedId);
- }
- }
-
- startSlice();
- }
- }
-
- internal override void startInstance(SliceType sliceType)
- {
- Debug.Assert(_current.sliceType == sliceType);
- _current.skipFirstSlice = true;
- }
-
- internal override Ice.SlicedData endInstance(bool preserve)
- {
- Ice.SlicedData slicedData = null;
- if(preserve)
- {
- slicedData = readSlicedData();
- }
- if(_current.slices != null)
- {
- _current.slices.Clear();
- _current.indirectionTables.Clear();
- }
- _current = _current.previous;
- return slicedData;
- }
-
- internal override string startSlice()
- {
- //
- // If first slice, don't read the header, it was already read in
- // readInstance or throwException to find the factory.
- //
- if(_current.skipFirstSlice)
- {
- _current.skipFirstSlice = false;
- return _current.typeId;
- }
-
- _current.sliceFlags = _stream.readByte();
-
- //
- // Read the type ID, for object slices the type ID is encoded as a
- // string or as an index, for exceptions it's always encoded as a
- // string.
- //
- if(_current.sliceType == SliceType.ObjectSlice)
- {
- if((_current.sliceFlags & FLAG_HAS_TYPE_ID_COMPACT) == FLAG_HAS_TYPE_ID_COMPACT) // Must
- // be
- // checked
- // 1st!
- {
- _current.typeId = "";
- _current.compactId = _stream.readSize();
- }
- else if((_current.sliceFlags & (FLAG_HAS_TYPE_ID_INDEX | FLAG_HAS_TYPE_ID_STRING)) != 0)
- {
- _current.typeId = readTypeId((_current.sliceFlags & FLAG_HAS_TYPE_ID_INDEX) != 0);
- _current.compactId = -1;
- }
- else
- {
- // Only the most derived slice encodes the type ID for the compact format.
- _current.typeId = "";
- _current.compactId = -1;
- }
- }
- else
- {
- _current.typeId = _stream.readString();
- _current.compactId = -1;
- }
-
- //
- // Read the slice size if necessary.
- //
- if((_current.sliceFlags & FLAG_HAS_SLICE_SIZE) != 0)
- {
- _current.sliceSize = _stream.readInt();
- if(_current.sliceSize < 4)
- {
- throw new Ice.UnmarshalOutOfBoundsException();
- }
- }
- else
- {
- _current.sliceSize = 0;
- }
-
- return _current.typeId;
- }
-
- internal override void endSlice()
- {
- if((_current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) != 0)
- {
- _stream.skipOpts();
- }
-
- //
- // Read the indirection table if one is present and transform the
- // indirect patch list into patch entries with direct references.
- //
- if((_current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) != 0)
- {
- //
- // The table is written as a sequence<size> to conserve space.
- //
- int[] indirectionTable = new int[_stream.readAndCheckSeqSize(1)];
- for(int i = 0; i < indirectionTable.Length; ++i)
- {
- indirectionTable[i] = readInstance(_stream.readSize(), null);
- }
-
- //
- // Sanity checks. If there are optional members, it's possible
- // that not all object references were read if they are from
- // unknown optional data members.
- //
- if(indirectionTable.Length == 0)
- {
- throw new Ice.MarshalException("empty indirection table");
- }
- if((_current.indirectPatchList == null || _current.indirectPatchList.Count == 0) &&
- (_current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) == 0)
- {
- throw new Ice.MarshalException("no references to indirection table");
- }
-
- //
- // Convert indirect references into direct references.
- //
- if(_current.indirectPatchList != null)
- {
- foreach(IndirectPatchEntry e in _current.indirectPatchList)
- {
- Debug.Assert(e.index >= 0);
- if(e.index >= indirectionTable.Length)
- {
- throw new Ice.MarshalException("indirection out of range");
- }
- addPatchEntry(indirectionTable[e.index], e.patcher);
- }
- _current.indirectPatchList.Clear();
- }
- }
- }
-
- internal override void skipSlice()
- {
- if(_stream.instance().traceLevels().slicing > 0)
- {
- Ice.Logger logger = _stream.instance().initializationData().logger;
- string slicingCat = _stream.instance().traceLevels().slicingCat;
- if(_current.sliceType == SliceType.ExceptionSlice)
- {
- TraceUtil.traceSlicing("exception", _current.typeId, slicingCat, logger);
- }
- else
- {
- TraceUtil.traceSlicing("object", _current.typeId, slicingCat, logger);
- }
- }
-
- int start = _stream.pos();
-
- if((_current.sliceFlags & FLAG_HAS_SLICE_SIZE) != 0)
- {
- Debug.Assert(_current.sliceSize >= 4);
- _stream.skip(_current.sliceSize - 4);
- }
- else
- {
- if(_current.sliceType == SliceType.ObjectSlice)
- {
- throw new Ice.NoObjectFactoryException("no object factory found and compact format prevents " +
- "slicing (the sender should use the sliced format " +
- "instead)", _current.typeId);
- }
- else
- {
- if(_current.typeId.StartsWith("::", StringComparison.Ordinal))
- {
- throw new Ice.UnknownUserException(_current.typeId.Substring(2));
- }
- else
- {
- throw new Ice.UnknownUserException(_current.typeId);
- }
- }
- }
-
- //
- // Preserve this slice.
- //
- Ice.SliceInfo info = new Ice.SliceInfo();
- info.typeId = _current.typeId;
- info.compactId = _current.compactId;
- info.hasOptionalMembers = (_current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) != 0;
- info.isLastSlice = (_current.sliceFlags & FLAG_IS_LAST_SLICE) != 0;
- ByteBuffer b = _stream.getBuffer().b;
- int end = b.position();
- int dataEnd = end;
- if(info.hasOptionalMembers)
- {
- //
- // Don't include the optional member end marker. It will be re-written by
- // endSlice when the sliced data is re-written.
- //
- --dataEnd;
- }
- info.bytes = new byte[dataEnd - start];
- b.position(start);
- b.get(info.bytes);
- b.position(end);
-
- if(_current.slices == null)
- {
- _current.slices = new List<Ice.SliceInfo>();
- _current.indirectionTables = new List<int[]>();
- }
-
- //
- // Read the indirect object table. We read the instances or their
- // IDs if the instance is a reference to an already un-marhsaled
- // object.
- //
- // The SliceInfo object sequence is initialized only if
- // readSlicedData is called.
- //
- if((_current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) != 0)
- {
- int[] indirectionTable = new int[_stream.readAndCheckSeqSize(1)];
- for(int i = 0; i < indirectionTable.Length; ++i)
- {
- indirectionTable[i] = readInstance(_stream.readSize(), null);
- }
- _current.indirectionTables.Add(indirectionTable);
- }
- else
- {
- _current.indirectionTables.Add(null);
- }
-
- _current.slices.Add(info);
- }
-
- internal override bool readOpt(int readTag, Ice.OptionalFormat expectedFormat)
- {
- if(_current == null)
- {
- return _stream.readOptImpl(readTag, expectedFormat);
- }
- else if((_current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) != 0)
- {
- return _stream.readOptImpl(readTag, expectedFormat);
- }
- return false;
- }
-
- private int readInstance(int index, IPatcher patcher)
- {
- Debug.Assert(index > 0);
-
- if(index > 1)
- {
- if(patcher != null)
- {
- addPatchEntry(index, patcher);
- }
- return index;
- }
-
- push(SliceType.ObjectSlice);
-
- //
- // Get the object ID before we start reading slices. If some
- // slices are skiped, the indirect object table are still read and
- // might read other objects.
- //
- index = ++_objectIdIndex;
-
- //
- // Read the first slice header.
- //
- startSlice();
- string mostDerivedId = _current.typeId;
- Ice.Object v = null;
- Ice.CompactIdResolver compactIdResolver = _stream.instance().initializationData().compactIdResolver;
- while(true)
- {
- if(_current.compactId >= 0)
- {
- //
- // Translate a compact (numeric) type ID into a string type ID.
- //
- _current.typeId = "";
- if(compactIdResolver != null)
- {
- try
- {
- _current.typeId = compactIdResolver(_current.compactId);
- }
- catch(Ice.LocalException)
- {
- throw;
- }
- catch(System.Exception ex)
- {
- throw new Ice.MarshalException("exception in CompactIdResolver for ID " +
- _current.compactId, ex);
- }
- }
- if(_current.typeId.Length == 0)
- {
- _current.typeId = _stream.getTypeId(_current.compactId);
- }
- }
-
- if(_current.typeId.Length > 0)
- {
- v = newInstance(_current.typeId);
-
- //
- // We found a factory, we get out of this loop.
- //
- if(v != null)
- {
- break;
- }
- }
-
- //
- // If object slicing is disabled, stop un-marshalling.
- //
- if(!_sliceObjects)
- {
- throw new Ice.NoObjectFactoryException("no object factory found and object slicing is disabled",
- _current.typeId);
- }
-
- //
- // Slice off what we don't understand.
- //
- skipSlice();
-
- //
- // If this is the last slice, keep the object as an opaque
- // UnknownSlicedData object.
- //
- if((_current.sliceFlags & FLAG_IS_LAST_SLICE) != 0)
- {
- //
- // Provide a factory with an opportunity to supply the object.
- // We pass the "::Ice::Object" ID to indicate that this is the
- // last chance to preserve the object.
- //
- v = newInstance(Ice.ObjectImpl.ice_staticId());
- if(v == null)
- {
- v = new Ice.UnknownSlicedObject(mostDerivedId);
- }
-
- break;
- }
-
- startSlice(); // Read next Slice header for next iteration.
- }
-
- //
- // Un-marshal the object
- //
- unmarshal(index, v);
-
- if(_current == null && _patchMap != null && _patchMap.Count > 0)
- {
- //
- // If any entries remain in the patch map, the sender has sent an index for an object, but failed
- // to supply the object.
- //
- throw new Ice.MarshalException("index for class received, but no instance");
- }
-
- if(patcher != null)
- {
- patcher.patch(v);
- }
- return index;
- }
-
- private Ice.SlicedData readSlicedData()
- {
- if(_current.slices == null) // No preserved slices.
- {
- return null;
- }
-
- //
- // The _indirectionTables member holds the indirection table for each slice
- // in _slices.
- //
- Debug.Assert(_current.slices.Count == _current.indirectionTables.Count);
- for(int n = 0; n < _current.slices.Count; ++n)
- {
- //
- // We use the "objects" list in SliceInfo to hold references
- // to the target objects. Note that the objects might not have
- // been read yet in the case of a circular reference to an
- // enclosing object.
- //
- int[] table = _current.indirectionTables[n];
- Ice.SliceInfo info = _current.slices[n];
- info.objects = new Ice.Object[table != null ? table.Length : 0];
- for(int j = 0; j < info.objects.Length; ++j)
- {
- IPatcher patcher = new ArrayPatcher<Ice.Object>(Ice.ObjectImpl.ice_staticId(), info.objects, j);
- addPatchEntry(table[j], patcher);
- }
- }
-
- return new Ice.SlicedData(_current.slices.ToArray());
- }
-
- private void push(SliceType sliceType)
- {
- if(_current == null)
- {
- _current = new InstanceData(null);
- }
- else
- {
- _current = _current.next == null ? new InstanceData(_current) : _current.next;
- }
- _current.sliceType = sliceType;
- _current.skipFirstSlice = false;
- }
-
- private sealed class IndirectPatchEntry
- {
- public int index;
- public IPatcher patcher;
- }
-
- private sealed class InstanceData
- {
- internal InstanceData(InstanceData previous)
- {
- if(previous != null)
- {
- previous.next = this;
- }
- this.previous = previous;
- this.next = null;
- }
-
- // Instance attributes
- internal SliceType sliceType;
- internal bool skipFirstSlice;
- internal List<Ice.SliceInfo> slices; // Preserved slices.
- internal List<int[]> indirectionTables;
-
- // Slice attributes
- internal byte sliceFlags;
- internal int sliceSize;
- internal string typeId;
- internal int compactId;
- internal Stack<IndirectPatchEntry> indirectPatchList;
-
- internal InstanceData previous;
- internal InstanceData next;
- };
- private InstanceData _current;
-
- private int _objectIdIndex; // The ID of the next object to un-marshal.
- };
-
- abstract private class EncapsEncoder
- {
- protected EncapsEncoder(BasicStream stream, WriteEncaps encaps)
- {
- _stream = stream;
- _encaps = encaps;
- _typeIdIndex = 0;
- _marshaledMap = new Dictionary<Ice.Object, int>();
- }
-
- internal abstract void writeObject(Ice.Object v);
- internal abstract void writeUserException(Ice.UserException v);
-
- internal abstract void startInstance(SliceType type, Ice.SlicedData data);
- internal abstract void endInstance();
- internal abstract void startSlice(string typeId, int compactId, bool last);
- internal abstract void endSlice();
-
- internal virtual bool writeOpt(int tag, Ice.OptionalFormat format)
- {
- return false;
- }
-
- internal virtual void writePendingObjects()
- {
- }
-
- protected int registerTypeId(string typeId)
- {
- if(_typeIdMap == null)
- {
- _typeIdMap = new Dictionary<string, int>();
- }
-
- int p;
- if(_typeIdMap.TryGetValue(typeId, out p))
- {
- return p;
- }
- else
- {
- _typeIdMap.Add(typeId, ++_typeIdIndex);
- return -1;
- }
- }
-
- protected readonly BasicStream _stream;
- protected readonly WriteEncaps _encaps;
-
- // Encapsulation attributes for object marshalling.
- protected readonly Dictionary<Ice.Object, int> _marshaledMap;
-
- // Encapsulation attributes for object marshalling.
- private Dictionary<string, int> _typeIdMap;
- private int _typeIdIndex;
- };
-
- private sealed class EncapsEncoder10 : EncapsEncoder
- {
- internal EncapsEncoder10(BasicStream stream, WriteEncaps encaps) : base(stream, encaps)
- {
- _sliceType = SliceType.NoSlice;
- _objectIdIndex = 0;
- _toBeMarshaledMap = new Dictionary<Ice.Object, int>();
- }
-
- internal override void writeObject(Ice.Object v)
- {
- //
- // Object references are encoded as a negative integer in 1.0.
- //
- if(v != null)
- {
- _stream.writeInt(-registerObject(v));
- }
- else
- {
- _stream.writeInt(0);
- }
- }
-
- internal override void writeUserException(Ice.UserException v)
- {
- //
- // User exception with the 1.0 encoding start with a bool
- // flag that indicates whether or not the exception uses
- // classes.
- //
- // This allows reading the pending objects even if some part of
- // the exception was sliced.
- //
- bool usesClasses = v.usesClasses__();
- _stream.writeBool(usesClasses);
- v.write__(_stream);
- if(usesClasses)
- {
- writePendingObjects();
- }
- }
-
- internal override void startInstance(SliceType sliceType, Ice.SlicedData sliceData)
- {
- _sliceType = sliceType;
- }
-
- internal override void endInstance()
- {
- if(_sliceType == SliceType.ObjectSlice)
- {
- //
- // Write the Object slice.
- //
- startSlice(Ice.ObjectImpl.ice_staticId(), -1, true);
- _stream.writeSize(0); // For compatibility with the old AFM.
- endSlice();
- }
- _sliceType = SliceType.NoSlice;
- }
-
- internal override void startSlice(string typeId, int compactId, bool last)
- {
- //
- // For object slices, encode a bool to indicate how the type ID
- // is encoded and the type ID either as a string or index. For
- // exception slices, always encode the type ID as a string.
- //
- if(_sliceType == SliceType.ObjectSlice)
- {
- int index = registerTypeId(typeId);
- if(index < 0)
- {
- _stream.writeBool(false);
- _stream.writeString(typeId);
- }
- else
- {
- _stream.writeBool(true);
- _stream.writeSize(index);
- }
- }
- else
- {
- _stream.writeString(typeId);
- }
-
- _stream.writeInt(0); // Placeholder for the slice length.
-
- _writeSlice = _stream.pos();
- }
-
- internal override void endSlice()
- {
- //
- // Write the slice length.
- //
- int sz = _stream.pos() - _writeSlice + 4;
- _stream.rewriteInt(sz, _writeSlice - 4);
- }
-
- internal override void writePendingObjects()
- {
- while(_toBeMarshaledMap.Count > 0)
- {
- //
- // Consider the to be marshalled objects as marshalled now,
- // this is necessary to avoid adding again the "to be
- // marshalled objects" into _toBeMarshaledMap while writing
- // objects.
- //
- foreach(KeyValuePair<Ice.Object, int> e in _toBeMarshaledMap)
- {
- _marshaledMap.Add(e.Key, e.Value);
- }
-
- Dictionary<Ice.Object, int> savedMap = _toBeMarshaledMap;
- _toBeMarshaledMap = new Dictionary<Ice.Object, int>();
- _stream.writeSize(savedMap.Count);
- foreach(KeyValuePair<Ice.Object, int> p in savedMap)
- {
- //
- // Ask the instance to marshal itself. Any new class
- // instances that are triggered by the classes marshaled
- // are added to toBeMarshaledMap.
- //
- _stream.writeInt(p.Value);
-
- try
- {
- p.Key.ice_preMarshal();
- }
- catch(System.Exception ex)
- {
- string s = "exception raised by ice_preMarshal:\n" + ex;
- _stream.instance().initializationData().logger.warning(s);
- }
-
- p.Key.write__(_stream);
- }
- }
- _stream.writeSize(0); // Zero marker indicates end of sequence of sequences of instances.
- }
-
- private int registerObject(Ice.Object v)
- {
- Debug.Assert(v != null);
-
- //
- // Look for this instance in the to-be-marshaled map.
- //
- int p;
- if(_toBeMarshaledMap.TryGetValue(v, out p))
- {
- return p;
- }
-
- //
- // Didn't find it, try the marshaled map next.
- //
- if(_marshaledMap.TryGetValue(v, out p))
- {
- return p;
- }
-
- //
- // We haven't seen this instance previously, create a new
- // index, and insert it into the to-be-marshaled map.
- //
- _toBeMarshaledMap.Add(v, ++_objectIdIndex);
- return _objectIdIndex;
- }
-
- // Instance attributes
- private SliceType _sliceType;
-
- // Slice attributes
- private int _writeSlice; // Position of the slice data members
-
- // Encapsulation attributes for object marshalling.
- private int _objectIdIndex;
- private Dictionary<Ice.Object, int> _toBeMarshaledMap;
- };
-
- private sealed class EncapsEncoder11 : EncapsEncoder
- {
- internal EncapsEncoder11(BasicStream stream, WriteEncaps encaps) : base(stream, encaps)
- {
- _current = null;
- _objectIdIndex = 1;
- }
-
- internal override void writeObject(Ice.Object v)
- {
- if(v == null)
- {
- _stream.writeSize(0);
- }
- else if(_current != null && _encaps.format == Ice.FormatType.SlicedFormat)
- {
- if(_current.indirectionTable == null)
- {
- _current.indirectionTable = new List<Ice.Object>();
- _current.indirectionMap = new Dictionary<Ice.Object, int>();
- }
-
- //
- // If writting an object within a slice and using the sliced
- // format, write an index from the object indirection table.
- //
- int index;
- if(!_current.indirectionMap.TryGetValue(v, out index))
- {
- _current.indirectionTable.Add(v);
- int idx = _current.indirectionTable.Count; // Position + 1 (0 is reserved for nil)
- _current.indirectionMap.Add(v, idx);
- _stream.writeSize(idx);
- }
- else
- {
- _stream.writeSize(index);
- }
- }
- else
- {
- writeInstance(v); // Write the instance or a reference if already marshaled.
- }
- }
-
- internal override void writeUserException(Ice.UserException v)
- {
- v.write__(_stream);
- }
-
- internal override void startInstance(SliceType sliceType, Ice.SlicedData data)
- {
- if(_current == null)
- {
- _current = new InstanceData(null);
- }
- else
- {
- _current = _current.next == null ? new InstanceData(_current) : _current.next;
- }
- _current.sliceType = sliceType;
- _current.firstSlice = true;
-
- if(data != null)
- {
- writeSlicedData(data);
- }
- }
-
- internal override void endInstance()
- {
- _current = _current.previous;
- }
-
- internal override void startSlice(string typeId, int compactId, bool last)
- {
- Debug.Assert((_current.indirectionTable == null || _current.indirectionTable.Count == 0) &&
- (_current.indirectionMap == null || _current.indirectionMap.Count == 0));
-
- _current.sliceFlagsPos = _stream.pos();
-
- _current.sliceFlags = (byte)0;
- if(_encaps.format == Ice.FormatType.SlicedFormat)
- {
- _current.sliceFlags |= FLAG_HAS_SLICE_SIZE; // Encode the slice size if using the sliced format.
- }
- if(last)
- {
- _current.sliceFlags |= FLAG_IS_LAST_SLICE; // This is the last slice.
- }
-
- _stream.writeByte((byte)0); // Placeholder for the slice flags
-
- //
- // For object slices, encode the flag and the type ID either as a
- // string or index. For exception slices, always encode the type
- // ID a string.
- //
- if(_current.sliceType == SliceType.ObjectSlice)
- {
- //
- // Encode the type ID (only in the first slice for the compact
- // encoding).
- //
- if(_encaps.format == Ice.FormatType.SlicedFormat || _current.firstSlice)
- {
- if(compactId >= 0)
- {
- _current.sliceFlags |= FLAG_HAS_TYPE_ID_COMPACT;
- _stream.writeSize(compactId);
- }
- else
- {
- int index = registerTypeId(typeId);
- if(index < 0)
- {
- _current.sliceFlags |= FLAG_HAS_TYPE_ID_STRING;
- _stream.writeString(typeId);
- }
- else
- {
- _current.sliceFlags |= FLAG_HAS_TYPE_ID_INDEX;
- _stream.writeSize(index);
- }
- }
- }
- }
- else
- {
- _stream.writeString(typeId);
- }
-
- if((_current.sliceFlags & FLAG_HAS_SLICE_SIZE) != 0)
- {
- _stream.writeInt(0); // Placeholder for the slice length.
- }
-
- _current.writeSlice = _stream.pos();
- _current.firstSlice = false;
- }
-
- internal override void endSlice()
- {
- //
- // Write the optional member end marker if some optional members
- // were encoded. Note that the optional members are encoded before
- // the indirection table and are included in the slice size.
- //
- if((_current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) != 0)
- {
- _stream.writeByte((byte)OPTIONAL_END_MARKER);
- }
-
- //
- // Write the slice length if necessary.
- //
- if((_current.sliceFlags & FLAG_HAS_SLICE_SIZE) != 0)
- {
- int sz = _stream.pos() - _current.writeSlice + 4;
- _stream.rewriteInt(sz, _current.writeSlice - 4);
- }
-
- //
- // Only write the indirection table if it contains entries.
- //
- if(_current.indirectionTable != null && _current.indirectionTable.Count > 0)
- {
- Debug.Assert(_encaps.format == Ice.FormatType.SlicedFormat);
- _current.sliceFlags |= FLAG_HAS_INDIRECTION_TABLE;
-
- //
- // Write the indirection object table.
- //
- _stream.writeSize(_current.indirectionTable.Count);
- foreach(Ice.Object v in _current.indirectionTable)
- {
- writeInstance(v);
- }
- _current.indirectionTable.Clear();
- _current.indirectionMap.Clear();
- }
-
- //
- // Finally, update the slice flags.
- //
- _stream.rewriteByte(_current.sliceFlags, _current.sliceFlagsPos);
- }
-
- internal override bool writeOpt(int tag, Ice.OptionalFormat format)
- {
- if(_current == null)
- {
- return _stream.writeOptImpl(tag, format);
- }
- else
- {
- if(_stream.writeOptImpl(tag, format))
- {
- _current.sliceFlags |= FLAG_HAS_OPTIONAL_MEMBERS;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
- private void writeSlicedData(Ice.SlicedData slicedData)
- {
- Debug.Assert(slicedData != null);
-
- //
- // We only remarshal preserved slices if we are using the sliced
- // format. Otherwise, we ignore the preserved slices, which
- // essentially "slices" the object into the most-derived type
- // known by the sender.
- //
- if(_encaps.format != Ice.FormatType.SlicedFormat)
- {
- return;
- }
-
- foreach(Ice.SliceInfo info in slicedData.slices)
- {
- startSlice(info.typeId, info.compactId, info.isLastSlice);
-
- //
- // Write the bytes associated with this slice.
- //
- _stream.writeBlob(info.bytes);
-
- if(info.hasOptionalMembers)
- {
- _current.sliceFlags |= FLAG_HAS_OPTIONAL_MEMBERS;
- }
-
- //
- // Make sure to also re-write the object indirection table.
- //
- if(info.objects != null && info.objects.Length > 0)
- {
- if(_current.indirectionTable == null)
- {
- _current.indirectionTable = new List<Ice.Object>();
- _current.indirectionMap = new Dictionary<Ice.Object, int>();
- }
- foreach(Ice.Object o in info.objects)
- {
- _current.indirectionTable.Add(o);
- }
- }
-
- endSlice();
- }
- }
-
- private void writeInstance(Ice.Object v)
- {
- Debug.Assert(v != null);
-
- //
- // If the instance was already marshaled, just write it's ID.
- //
- int p;
- if(_marshaledMap.TryGetValue(v, out p))
- {
- _stream.writeSize(p);
- return;
- }
-
- //
- // We haven't seen this instance previously, create a new ID,
- // insert it into the marshaled map, and write the instance.
- //
- _marshaledMap.Add(v, ++_objectIdIndex);
-
- try
- {
- v.ice_preMarshal();
- }
- catch(System.Exception ex)
- {
- string s = "exception raised by ice_preMarshal:\n" + ex;
- _stream.instance().initializationData().logger.warning(s);
- }
-
- _stream.writeSize(1); // Object instance marker.
- v.write__(_stream);
- }
-
- private sealed class InstanceData
- {
- internal InstanceData(InstanceData previous)
- {
- if(previous != null)
- {
- previous.next = this;
- }
- this.previous = previous;
- this.next = null;
- }
-
- // Instance attributes
- internal SliceType sliceType;
- internal bool firstSlice;
-
- // Slice attributes
- internal byte sliceFlags;
- internal int writeSlice; // Position of the slice data members
- internal int sliceFlagsPos; // Position of the slice flags
- internal List<Ice.Object> indirectionTable;
- internal Dictionary<Ice.Object, int> indirectionMap;
-
- internal InstanceData previous;
- internal InstanceData next;
- };
- private InstanceData _current;
-
- private int _objectIdIndex; // The ID of the next object to marhsal
- };
-
- private sealed class ReadEncaps
- {
- internal void reset()
- {
- decoder = null;
- }
-
- internal void setEncoding(Ice.EncodingVersion encoding)
- {
- this.encoding = encoding;
- encoding_1_0 = encoding.Equals(Ice.Util.Encoding_1_0);
- }
-
- internal int start;
- internal int sz;
- internal Ice.EncodingVersion encoding;
- internal bool encoding_1_0;
-
- internal EncapsDecoder decoder;
-
- internal ReadEncaps next;
- }
-
- private sealed class WriteEncaps
- {
- internal void reset()
- {
- encoder = null;
- }
-
- internal void setEncoding(Ice.EncodingVersion encoding)
- {
- this.encoding = encoding;
- encoding_1_0 = encoding.Equals(Ice.Util.Encoding_1_0);
- }
-
- internal int start;
- internal Ice.EncodingVersion encoding;
- internal bool encoding_1_0;
- internal Ice.FormatType format = Ice.FormatType.DefaultFormat;
-
- internal EncapsEncoder encoder;
-
- internal WriteEncaps next;
- }
-
- //
- // The encoding version to use when there's no encapsulation to
- // read from or write to. This is for example used to read message
- // headers or when the user is using the streaming API with no
- // encapsulation.
- //
- private Ice.EncodingVersion _encoding;
-
- private bool isReadEncoding_1_0()
- {
- return _readEncapsStack != null ? _readEncapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0);
- }
-
- private bool isWriteEncoding_1_0()
- {
- return _writeEncapsStack != null ? _writeEncapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0);
- }
-
- private ReadEncaps _readEncapsStack;
- private WriteEncaps _writeEncapsStack;
- private ReadEncaps _readEncapsCache;
- private WriteEncaps _writeEncapsCache;
-
- private void initReadEncaps()
- {
- if(_readEncapsStack == null) // Lazy initialization
- {
- _readEncapsStack = _readEncapsCache;
- if(_readEncapsStack != null)
- {
- _readEncapsCache = _readEncapsCache.next;
- }
- else
- {
- _readEncapsStack = new ReadEncaps();
- }
- _readEncapsStack.setEncoding(_encoding);
- _readEncapsStack.sz = _buf.b.limit();
- }
-
- if(_readEncapsStack.decoder == null) // Lazy initialization.
- {
- ObjectFactoryManager factoryMgr = instance_.servantFactoryManager();
- if(_readEncapsStack.encoding_1_0)
- {
- _readEncapsStack.decoder = new EncapsDecoder10(this, _readEncapsStack, _sliceObjects, factoryMgr);
- }
- else
- {
- _readEncapsStack.decoder = new EncapsDecoder11(this, _readEncapsStack, _sliceObjects, factoryMgr);
- };
- }
- }
-
- private void initWriteEncaps()
- {
- if(_writeEncapsStack == null) // Lazy initialization
- {
- _writeEncapsStack = _writeEncapsCache;
- if(_writeEncapsStack != null)
- {
- _writeEncapsCache = _writeEncapsCache.next;
- }
- else
- {
- _writeEncapsStack = new WriteEncaps();
- }
- _writeEncapsStack.setEncoding(_encoding);
- }
-
- if(_writeEncapsStack.format == Ice.FormatType.DefaultFormat)
- {
- _writeEncapsStack.format = instance_.defaultsAndOverrides().defaultFormat;
- }
-
- if(_writeEncapsStack.encoder == null) // Lazy initialization.
- {
- if(_writeEncapsStack.encoding_1_0)
- {
- _writeEncapsStack.encoder = new EncapsEncoder10(this, _writeEncapsStack);
- }
- else
- {
- _writeEncapsStack.encoder = new EncapsEncoder11(this, _writeEncapsStack);
- }
- }
- }
-
- private bool _sliceObjects;
-
- private int _startSeq;
- private int _minSeqSize;
-
- private const byte OPTIONAL_END_MARKER = 0xFF;
-
- private const byte FLAG_HAS_TYPE_ID_STRING = (byte)(1<<0);
- private const byte FLAG_HAS_TYPE_ID_INDEX = (byte)(1<<1);
- private const byte FLAG_HAS_TYPE_ID_COMPACT = (byte)(1<<1 | 1<<0);
- private const byte FLAG_HAS_OPTIONAL_MEMBERS = (byte)(1<<2);
- private const byte FLAG_HAS_INDIRECTION_TABLE = (byte)(1<<3);
- private const byte FLAG_HAS_SLICE_SIZE = (byte)(1<<4);
- private const byte FLAG_IS_LAST_SLICE = (byte)(1<<5);
-
- private static bool _bzlibInstalled;
-
- const int BZ_SEQUENCE_ERROR = -1;
- const int BZ_PARAM_ERROR = -2;
- const int BZ_MEM_ERROR = -3;
- const int BZ_DATA_ERROR = -4;
- const int BZ_DATA_ERROR_MAGIC = -5;
- const int BZ_IO_ERROR = -6;
- const int BZ_UNEXPECTED_EOF = -7;
- const int BZ_OUTBUFF_FULL = -8;
- const int BZ_CONFIG_ERROR = -9;
- }
-
-}
diff --git a/csharp/src/Ice/BatchRequestInterceptor.cs b/csharp/src/Ice/BatchRequestInterceptor.cs
index e7fbc8d1b86..5eb12d7f59d 100644
--- a/csharp/src/Ice/BatchRequestInterceptor.cs
+++ b/csharp/src/Ice/BatchRequestInterceptor.cs
@@ -33,7 +33,7 @@ namespace Ice
/// </summary>
/// <returns>The request proxy.</returns>
Ice.ObjectPrx getProxy();
- };
+ }
/// <summary>
/// Base interface for listening to batch request queues.
@@ -53,5 +53,5 @@ namespace Ice
/// <param name="queueBatchRequestCount">The number of batch request queued.</param>
/// <param name="queueBatchRequestSize">The size of the queued batch requests.</param>
void enqueue(Ice.BatchRequest request, int queueBatchRequestCount, int queueBatchRequestSize);
- };
-};
+ }
+}
diff --git a/csharp/src/Ice/BatchRequestQueue.cs b/csharp/src/Ice/BatchRequestQueue.cs
index d532e5bcd66..5507e879933 100644
--- a/csharp/src/Ice/BatchRequestQueue.cs
+++ b/csharp/src/Ice/BatchRequestQueue.cs
@@ -49,8 +49,7 @@ namespace IceInternal
private Ice.ObjectPrx _proxy;
private string _operation;
private int _size;
- };
-
+ }
public sealed class BatchRequestQueue
{
@@ -60,7 +59,7 @@ namespace IceInternal
_interceptor = initData.batchRequestInterceptor;
_batchStreamInUse = false;
_batchRequestNum = 0;
- _batchStream = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
+ _batchStream = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding);
_batchStream.writeBlob(Protocol.requestBatchHdr);
_batchMarker = _batchStream.size();
_request = new BatchRequestI(this);
@@ -78,7 +77,7 @@ namespace IceInternal
}
public void
- prepareBatchRequest(BasicStream os)
+ prepareBatchRequest(Ice.OutputStream os)
{
lock(this)
{
@@ -93,7 +92,7 @@ namespace IceInternal
}
public void
- finishBatchRequest(BasicStream os, Ice.ObjectPrx proxy, string operation)
+ finishBatchRequest(Ice.OutputStream os, Ice.ObjectPrx proxy, string operation)
{
//
// No need for synchronization, no other threads are supposed
@@ -127,7 +126,7 @@ namespace IceInternal
{
lock(this)
{
- _batchStream.resize(_batchMarker, false);
+ _batchStream.resize(_batchMarker);
_batchStreamInUse = false;
_batchStreamCanFlush = false;
System.Threading.Monitor.PulseAll(this);
@@ -136,14 +135,14 @@ namespace IceInternal
}
public void
- abortBatchRequest(BasicStream os)
+ abortBatchRequest(Ice.OutputStream os)
{
lock(this)
{
if(_batchStreamInUse)
{
_batchStream.swap(os);
- _batchStream.resize(_batchMarker, false);
+ _batchStream.resize(_batchMarker);
_batchStreamInUse = false;
System.Threading.Monitor.PulseAll(this);
}
@@ -151,7 +150,7 @@ namespace IceInternal
}
public int
- swap(BasicStream os)
+ swap(Ice.OutputStream os)
{
lock(this)
{
@@ -169,7 +168,7 @@ namespace IceInternal
Buffer buffer = _batchStream.getBuffer();
buffer.b.position(_batchMarker);
buffer.b.get(lastRequest);
- _batchStream.resize(_batchMarker, false);
+ _batchStream.resize(_batchMarker);
}
int requestNum = _batchRequestNum;
@@ -230,7 +229,7 @@ namespace IceInternal
}
private Ice.BatchRequestInterceptor _interceptor;
- private BasicStream _batchStream;
+ private Ice.OutputStream _batchStream;
private bool _batchStreamInUse;
private bool _batchStreamCanFlush;
private int _batchRequestNum;
@@ -241,4 +240,4 @@ namespace IceInternal
private static int _udpOverhead = 20 + 8;
}
-};
+}
diff --git a/csharp/src/Ice/Buffer.cs b/csharp/src/Ice/Buffer.cs
index b41d8f6906e..9046b895caf 100644
--- a/csharp/src/Ice/Buffer.cs
+++ b/csharp/src/Ice/Buffer.cs
@@ -42,6 +42,33 @@ namespace IceInternal
_order = order;
}
+ public Buffer(ByteBuffer data) : this(data, ByteBuffer.ByteOrder.LITTLE_ENDIAN)
+ {
+ }
+
+ public Buffer(ByteBuffer data, ByteBuffer.ByteOrder order)
+ {
+ b = data;
+ b.order(order);
+ _size = data.remaining();
+ _capacity = 0;
+ _order = order;
+ }
+
+ public Buffer(Buffer buf, bool adopt)
+ {
+ b = buf.b;
+ _size = buf._size;
+ _capacity = buf._capacity;
+ _shrinkCounter = buf._shrinkCounter;
+ _order = buf._order;
+
+ if(adopt)
+ {
+ buf.clear();
+ }
+ }
+
public int size()
{
return _size;
@@ -57,6 +84,7 @@ namespace IceInternal
b = _emptyBuffer;
_size = 0;
_capacity = 0;
+ _shrinkCounter = 0;
}
//
diff --git a/csharp/src/Ice/ByteBuffer.cs b/csharp/src/Ice/ByteBuffer.cs
index 4139f7dfa61..8112a6149bc 100644
--- a/csharp/src/Ice/ByteBuffer.cs
+++ b/csharp/src/Ice/ByteBuffer.cs
@@ -234,7 +234,7 @@ namespace IceInternal
return put(b, 0, System.Buffer.ByteLength(b));
}
- public ByteBuffer put(byte[]b, int offset, int length)
+ public ByteBuffer put(byte[] b, int offset, int length)
{
if(offset < 0)
{
diff --git a/csharp/src/Ice/CollocatedRequestHandler.cs b/csharp/src/Ice/CollocatedRequestHandler.cs
index 8e7f4e945ed..b08e8626b9b 100644
--- a/csharp/src/Ice/CollocatedRequestHandler.cs
+++ b/csharp/src/Ice/CollocatedRequestHandler.cs
@@ -19,7 +19,7 @@ namespace IceInternal
public class CollocatedRequestHandler : RequestHandler, ResponseHandler
{
private void
- fillInValue(BasicStream os, int pos, int value)
+ fillInValue(Ice.OutputStream os, int pos, int value)
{
os.rewriteInt(value, pos);
}
@@ -88,7 +88,7 @@ namespace IceInternal
}
}
- public void sendResponse(int requestId, BasicStream os, byte status, bool amd)
+ public void sendResponse(int requestId, Ice.OutputStream os, byte status, bool amd)
{
Ice.AsyncCallback cb = null;
OutgoingAsyncBase outAsync;
@@ -96,18 +96,25 @@ namespace IceInternal
{
Debug.Assert(_response);
- os.pos(Protocol.replyHdr.Length + 4);
-
if(_traceLevels.protocol >= 1)
{
fillInValue(os, 10, os.size());
- TraceUtil.traceRecv(os, _logger, _traceLevels);
+ }
+
+ // Adopt the OutputStream's buffer.
+ Ice.InputStream iss = new Ice.InputStream(os.instance(), os.getEncoding(), os.getBuffer(), true);
+
+ iss.pos(Protocol.replyHdr.Length + 4);
+
+ if(_traceLevels.protocol >= 1)
+ {
+ TraceUtil.traceRecv(iss, _logger, _traceLevels);
}
if(_asyncRequests.TryGetValue(requestId, out outAsync))
{
_asyncRequests.Remove(requestId);
- outAsync.getIs().swap(os);
+ outAsync.getIs().swap(iss);
cb = outAsync.completed();
}
}
@@ -259,17 +266,8 @@ namespace IceInternal
return true;
}
- private void invokeAll(BasicStream os, int requestId, int batchRequestNum)
+ private void invokeAll(Ice.OutputStream os, int requestId, int batchRequestNum)
{
- if(batchRequestNum > 0)
- {
- os.pos(Protocol.requestBatchHdr.Length);
- }
- else
- {
- os.pos(Protocol.requestHdr.Length);
- }
-
if(_traceLevels.protocol >= 1)
{
fillInValue(os, 10, os.size());
@@ -284,6 +282,17 @@ namespace IceInternal
TraceUtil.traceSend(os, _logger, _traceLevels);
}
+ Ice.InputStream iss = new Ice.InputStream(os.instance(), os.getEncoding(), os.getBuffer(), false);
+
+ if(batchRequestNum > 0)
+ {
+ iss.pos(Protocol.requestBatchHdr.Length);
+ }
+ else
+ {
+ iss.pos(Protocol.requestHdr.Length);
+ }
+
int invokeNum = batchRequestNum > 0 ? batchRequestNum : 1;
ServantManager servantManager = _adapter.getServantManager();
try
@@ -308,7 +317,7 @@ namespace IceInternal
Incoming @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0,
requestId);
- @in.invoke(servantManager, os);
+ @in.invoke(servantManager, iss);
--invokeNum;
}
}
diff --git a/csharp/src/Ice/CommunicatorI.cs b/csharp/src/Ice/CommunicatorI.cs
index 4663e4d75ed..ce4a70aa580 100644
--- a/csharp/src/Ice/CommunicatorI.cs
+++ b/csharp/src/Ice/CommunicatorI.cs
@@ -102,12 +102,17 @@ namespace Ice
public void addObjectFactory(ObjectFactory factory, string id)
{
- instance_.servantFactoryManager().add(factory, id);
+ instance_.addObjectFactory(factory, id);
}
public ObjectFactory findObjectFactory(string id)
{
- return instance_.servantFactoryManager().find(id);
+ return instance_.findObjectFactory(id);
+ }
+
+ public ValueFactoryManager getValueFactoryManager()
+ {
+ return instance_.initializationData().valueFactoryManager;
}
public Properties getProperties()
@@ -177,7 +182,7 @@ namespace Ice
// This callback object receives the results of all invocations
// of Connection.begin_flushBatchRequests.
//
- IceInternal.CommunicatorFlushBatch result =
+ IceInternal.CommunicatorFlushBatch result =
new IceInternal.CommunicatorFlushBatch(this, instance_, __flushBatchRequests_name, cookie);
if(cb != null)
@@ -200,7 +205,7 @@ namespace Ice
public void end_flushBatchRequests(AsyncResult result)
{
- IceInternal.CommunicatorFlushBatch outAsync =
+ IceInternal.CommunicatorFlushBatch outAsync =
IceInternal.CommunicatorFlushBatch.check(result, this, __flushBatchRequests_name);
outAsync.wait();
}
@@ -209,7 +214,7 @@ namespace Ice
{
return instance_.createAdmin(adminAdapter, adminIdentity);
}
-
+
public Ice.ObjectPrx getAdmin()
{
return instance_.getAdmin();
diff --git a/csharp/src/Ice/ConnectionFactory.cs b/csharp/src/Ice/ConnectionFactory.cs
index 1c418b84198..19ebfbad9e6 100644
--- a/csharp/src/Ice/ConnectionFactory.cs
+++ b/csharp/src/Ice/ConnectionFactory.cs
@@ -850,7 +850,7 @@ namespace IceInternal
{
if(_observer != null)
{
- _observer.failed(ex.ice_name());
+ _observer.failed(ex.ice_id());
_observer.detach();
}
_factory.handleConnectionException(ex, _hasMore || _iter < _connectors.Count);
diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs
index eef11d4ee4c..93f6efb87cb 100644
--- a/csharp/src/Ice/ConnectionI.cs
+++ b/csharp/src/Ice/ConnectionI.cs
@@ -385,7 +385,7 @@ namespace Ice
public bool sendAsyncRequest(IceInternal.OutgoingAsyncBase og, bool compress, bool response,
int batchRequestNum, out Ice.AsyncCallback sentCallback)
{
- IceInternal.BasicStream os = og.getOs();
+ OutputStream os = og.getOs();
lock(this)
{
@@ -507,7 +507,7 @@ namespace Ice
return result;
}
- public void setCallback(ConnectionCallback callback)
+ public void setCloseCallback(CloseCallback callback)
{
lock(this)
{
@@ -519,7 +519,7 @@ namespace Ice
{
try
{
- callback.closed(this);
+ callback(this);
}
catch(System.Exception ex)
{
@@ -530,11 +530,19 @@ namespace Ice
}
else
{
- _callback = callback;
+ _closeCallback = callback;
}
}
}
+ public void setHeartbeatCallback(HeartbeatCallback callback)
+ {
+ lock(this)
+ {
+ _heartbeatCallback = callback;
+ }
+ }
+
public void setACM(Optional<int> timeout, Optional<ACMClose> close, Optional<ACMHeartbeat> heartbeat)
{
lock(this)
@@ -649,7 +657,7 @@ namespace Ice
}
}
- public void sendResponse(int requestId, IceInternal.BasicStream os, byte compressFlag, bool amd)
+ public void sendResponse(int requestId, OutputStream os, byte compressFlag, bool amd)
{
lock(this)
{
@@ -1043,7 +1051,7 @@ namespace Ice
}
if(size > _readStream.size())
{
- _readStream.resize(size, true);
+ _readStream.resize(size);
}
_readStream.pos(pos);
}
@@ -1152,7 +1160,7 @@ namespace Ice
{
_logger.warning("maximum datagram size of " + _readStream.pos() + " exceeded");
}
- _readStream.resize(IceInternal.Protocol.headerSize, true);
+ _readStream.resize(IceInternal.Protocol.headerSize);
_readStream.pos(0);
_readHeader = true;
return;
@@ -1171,7 +1179,7 @@ namespace Ice
String s = "datagram connection exception:\n" + ex + '\n' + _desc;
_logger.warning(s);
}
- _readStream.resize(IceInternal.Protocol.headerSize, true);
+ _readStream.resize(IceInternal.Protocol.headerSize);
_readStream.pos(0);
_readHeader = true;
}
@@ -1249,7 +1257,7 @@ namespace Ice
{
try
{
- info.heartbeatCallback.heartbeat(this);
+ info.heartbeatCallback(this);
}
catch(System.Exception ex)
{
@@ -1324,7 +1332,8 @@ namespace Ice
// to call code that will potentially block (this avoids promoting a new leader and
// unecessary thread creation, especially if this is called on shutdown).
//
- if(_startCallback == null && _sendStreams.Count == 0 && _asyncRequests.Count == 0 && _callback == null)
+ if(_startCallback == null && _sendStreams.Count == 0 && _asyncRequests.Count == 0 &&
+ _closeCallback == null && _heartbeatCallback == null)
{
finish();
return;
@@ -1453,19 +1462,21 @@ namespace Ice
_readStream.getBuffer().clear();
_incomingCache = null;
- if(_callback != null)
+ if(_closeCallback != null)
{
try
{
- _callback.closed(this);
+ _closeCallback(this);
}
catch(System.Exception ex)
{
_logger.error("connection callback exception:\n" + ex + '\n' + _desc);
}
- _callback = null;
+ _closeCallback = null;
}
+ _heartbeatCallback = null;
+
//
// This must be done last as this will cause waitUntilFinished() to return (and communicator
// objects such as the timer might be destroyed too).
@@ -1555,7 +1566,7 @@ namespace Ice
static ConnectionI()
{
- _compressionSupported = IceInternal.BasicStream.compressible();
+ _compressionSupported = IceInternal.BZip2.supported();
}
internal ConnectionI(Communicator communicator, IceInternal.Instance instance,
@@ -1593,10 +1604,10 @@ namespace Ice
_nextRequestId = 1;
_messageSizeMax = adapter != null ? adapter.messageSizeMax() : instance.messageSizeMax();
_batchRequestQueue = new IceInternal.BatchRequestQueue(instance, _endpoint.datagram());
- _readStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding);
+ _readStream = new InputStream(instance, Util.currentProtocolEncoding);
_readHeader = false;
_readStreamPos = -1;
- _writeStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding);
+ _writeStream = new OutputStream(instance, Util.currentProtocolEncoding);
_writeStreamPos = -1;
_dispatchCount = 0;
_state = StateNotInitialized;
@@ -1863,7 +1874,7 @@ namespace Ice
_exception is ObjectAdapterDeactivatedException ||
(_exception is ConnectionLostException && _state >= StateClosing)))
{
- _observer.failed(_exception.ice_name());
+ _observer.failed(_exception.ice_id());
}
}
}
@@ -1900,7 +1911,7 @@ namespace Ice
//
// Before we shut down, we send a close connection message.
//
- IceInternal.BasicStream os = new IceInternal.BasicStream(_instance, Util.currentProtocolEncoding);
+ OutputStream os = new OutputStream(_instance, Util.currentProtocolEncoding);
os.writeBlob(IceInternal.Protocol.magic);
Ice.Util.currentProtocol.write__(os);
Ice.Util.currentProtocolEncoding.write__(os);
@@ -1931,7 +1942,7 @@ namespace Ice
if(!_endpoint.datagram())
{
- IceInternal.BasicStream os = new IceInternal.BasicStream(_instance, Util.currentProtocolEncoding);
+ OutputStream os = new OutputStream(_instance, Util.currentProtocolEncoding);
os.writeBlob(IceInternal.Protocol.magic);
Ice.Util.currentProtocol.write__(os);
Ice.Util.currentProtocolEncoding.write__(os);
@@ -2014,7 +2025,7 @@ namespace Ice
{
if(_readStream.size() == 0)
{
- _readStream.resize(IceInternal.Protocol.headerSize, true);
+ _readStream.resize(IceInternal.Protocol.headerSize);
_readStream.pos(0);
}
@@ -2075,10 +2086,10 @@ namespace Ice
}
}
- _writeStream.resize(0, false);
+ _writeStream.resize(0);
_writeStream.pos(0);
- _readStream.resize(IceInternal.Protocol.headerSize, true);
+ _readStream.resize(IceInternal.Protocol.headerSize);
_readStream.pos(0);
_readHeader = true;
@@ -2169,7 +2180,7 @@ namespace Ice
//
message = _sendStreams.First.Value;
Debug.Assert(!message.prepared);
- IceInternal.BasicStream stream = message.stream;
+ OutputStream stream = message.stream;
message.stream = doCompress(message.stream, message.compress);
message.stream.prepareWrite();
@@ -2246,7 +2257,7 @@ namespace Ice
Debug.Assert(!message.prepared);
- IceInternal.BasicStream stream = message.stream;
+ OutputStream stream = message.stream;
message.stream = doCompress(stream, message.compress);
message.stream.prepareWrite();
@@ -2294,7 +2305,7 @@ namespace Ice
return false;
}
- private IceInternal.BasicStream doCompress(IceInternal.BasicStream uncompressed, bool compress)
+ private OutputStream doCompress(OutputStream uncompressed, bool compress)
{
if(_compressionSupported)
{
@@ -2303,9 +2314,14 @@ namespace Ice
//
// Do compression.
//
- IceInternal.BasicStream cstream = null;
- if(uncompressed.compress(ref cstream, IceInternal.Protocol.headerSize, _compressionLevel))
+ IceInternal.Buffer cbuf = IceInternal.BZip2.compress(uncompressed.getBuffer(),
+ IceInternal.Protocol.headerSize,
+ _compressionLevel);
+ if(cbuf != null)
{
+ OutputStream cstream =
+ new OutputStream(uncompressed.instance(), uncompressed.getEncoding(), cbuf, true);
+
//
// Set compression status.
//
@@ -2345,7 +2361,7 @@ namespace Ice
private struct MessageInfo
{
- public IceInternal.BasicStream stream;
+ public InputStream stream;
public int invokeNum;
public int requestId;
public byte compress;
@@ -2353,7 +2369,7 @@ namespace Ice
public ObjectAdapter adapter;
public IceInternal.OutgoingAsyncBase outAsync;
public Ice.AsyncCallback completedCallback;
- public ConnectionCallback heartbeatCallback;
+ public HeartbeatCallback heartbeatCallback;
public int messageDispatchCount;
}
@@ -2361,9 +2377,9 @@ namespace Ice
{
Debug.Assert(_state > StateNotValidated && _state < StateClosed);
- info.stream = new IceInternal.BasicStream(_instance, Util.currentProtocolEncoding);
+ info.stream = new InputStream(_instance, Util.currentProtocolEncoding);
_readStream.swap(info.stream);
- _readStream.resize(IceInternal.Protocol.headerSize, true);
+ _readStream.resize(IceInternal.Protocol.headerSize);
_readStream.pos(0);
_readHeader = true;
@@ -2389,7 +2405,10 @@ namespace Ice
{
if(_compressionSupported)
{
- info.stream = info.stream.uncompress(IceInternal.Protocol.headerSize, _messageSizeMax);
+ IceInternal.Buffer ubuf = IceInternal.BZip2.uncompress(info.stream.getBuffer(),
+ IceInternal.Protocol.headerSize,
+ _messageSizeMax);
+ info.stream = new InputStream(info.stream.instance(), info.stream.getEncoding(), ubuf, true);
}
else
{
@@ -2511,9 +2530,9 @@ namespace Ice
case IceInternal.Protocol.validateConnectionMsg:
{
IceInternal.TraceUtil.traceRecv(info.stream, _logger, _traceLevels);
- if(_callback != null)
+ if(_heartbeatCallback != null)
{
- info.heartbeatCallback = _callback;
+ info.heartbeatCallback = _heartbeatCallback;
++info.messageDispatchCount;
}
break;
@@ -2545,7 +2564,7 @@ namespace Ice
return _state == StateHolding ? IceInternal.SocketOperation.None : IceInternal.SocketOperation.Read;
}
- private void invokeAll(IceInternal.BasicStream stream, int invokeNum, int requestId, byte compress,
+ private void invokeAll(InputStream stream, int invokeNum, int requestId, byte compress,
IceInternal.ServantManager servantManager, ObjectAdapter adapter)
{
//
@@ -2850,7 +2869,7 @@ namespace Ice
private class OutgoingMessage
{
- internal OutgoingMessage(IceInternal.BasicStream stream, bool compress, bool adopt)
+ internal OutgoingMessage(OutputStream stream, bool compress, bool adopt)
{
this.stream = stream;
this.compress = compress;
@@ -2859,7 +2878,7 @@ namespace Ice
this.requestId = 0;
}
- internal OutgoingMessage(IceInternal.OutgoingAsyncBase outAsync, IceInternal.BasicStream stream,
+ internal OutgoingMessage(IceInternal.OutgoingAsyncBase outAsync, OutputStream stream,
bool compress, int requestId)
{
this.stream = stream;
@@ -2879,8 +2898,7 @@ namespace Ice
{
if(_adopt)
{
- IceInternal.BasicStream stream = new IceInternal.BasicStream(this.stream.instance(),
- Util.currentProtocolEncoding);
+ OutputStream stream = new OutputStream(this.stream.instance(), Util.currentProtocolEncoding);
stream.swap(this.stream);
this.stream = stream;
_adopt = false;
@@ -2908,7 +2926,7 @@ namespace Ice
}
}
- internal IceInternal.BasicStream stream;
+ internal OutputStream stream;
internal IceInternal.OutgoingAsyncBase outAsync;
internal bool receivedReply;
internal bool compress;
@@ -2962,9 +2980,9 @@ namespace Ice
private LinkedList<OutgoingMessage> _sendStreams = new LinkedList<OutgoingMessage>();
- private IceInternal.BasicStream _readStream;
+ private InputStream _readStream;
private bool _readHeader;
- private IceInternal.BasicStream _writeStream;
+ private OutputStream _writeStream;
private ConnectionObserver _observer;
private int _readStreamPos;
@@ -2986,7 +3004,8 @@ namespace Ice
private Ice.ConnectionInfo _info;
- private Ice.ConnectionCallback _callback;
+ private Ice.CloseCallback _closeCallback;
+ private Ice.HeartbeatCallback _heartbeatCallback;
private static ConnectionState[] connectionStateMap = new ConnectionState[] {
ConnectionState.ConnectionStateValidating, // StateNotInitialized
diff --git a/csharp/src/Ice/DefaultsAndOverrides.cs b/csharp/src/Ice/DefaultsAndOverrides.cs
index b1fe897fbd0..573e0b673ec 100644
--- a/csharp/src/Ice/DefaultsAndOverrides.cs
+++ b/csharp/src/Ice/DefaultsAndOverrides.cs
@@ -116,7 +116,7 @@ namespace IceInternal
{
overrideCompress = true;
overrideCompressValue = properties.getPropertyAsInt("Ice.Override.Compress") > 0;
- if(!BasicStream.compressible() && overrideCompressValue)
+ if(!BZip2.supported() && overrideCompressValue)
{
string lib = AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono ? "bzip2 library" : "bzip2.dll";
Console.Error.WriteLine("warning: " + lib + " not found, Ice.Override.Compress ignored.");
@@ -125,7 +125,7 @@ namespace IceInternal
}
else
{
- overrideCompress = !BasicStream.compressible();
+ overrideCompress = !BZip2.supported();
overrideCompressValue = false;
}
#endif
diff --git a/csharp/src/Ice/EndpointFactory.cs b/csharp/src/Ice/EndpointFactory.cs
index 059522acd20..c3bae69ecbe 100644
--- a/csharp/src/Ice/EndpointFactory.cs
+++ b/csharp/src/Ice/EndpointFactory.cs
@@ -16,7 +16,7 @@ namespace IceInternal
short type();
string protocol();
EndpointI create(List<string> args, bool oaEndpoint);
- EndpointI read(BasicStream s);
+ EndpointI read(Ice.InputStream s);
void destroy();
EndpointFactory clone(ProtocolInstance instance);
diff --git a/csharp/src/Ice/EndpointFactoryManager.cs b/csharp/src/Ice/EndpointFactoryManager.cs
index 7ed0f8f9670..1c8172ffcc5 100644
--- a/csharp/src/Ice/EndpointFactoryManager.cs
+++ b/csharp/src/Ice/EndpointFactoryManager.cs
@@ -142,16 +142,16 @@ namespace IceInternal
// and ask the factory to read the endpoint data from that stream to create
// the actual endpoint.
//
- BasicStream bs = new BasicStream(instance_, Ice.Util.currentProtocolEncoding);
- bs.writeShort(ue.type());
- ue.streamWrite(bs);
- Buffer buf = bs.getBuffer();
- buf.b.position(0);
- buf.b.limit(buf.size());
- bs.readShort(); // type
- bs.startReadEncaps();
- EndpointI e = factory.read(bs);
- bs.endReadEncaps();
+ Ice.OutputStream os = new Ice.OutputStream(instance_, Ice.Util.currentProtocolEncoding);
+ os.writeShort(ue.type());
+ ue.streamWrite(os);
+ Ice.InputStream iss =
+ new Ice.InputStream(instance_, Ice.Util.currentProtocolEncoding, os.getBuffer(), true);
+ iss.pos(0);
+ iss.readShort(); // type
+ iss.startEncapsulation();
+ EndpointI e = factory.read(iss);
+ iss.endEncapsulation();
return e;
}
return ue; // Endpoint is opaque, but we don't have a factory for its type.
@@ -160,7 +160,7 @@ namespace IceInternal
return null;
}
- public EndpointI read(BasicStream s)
+ public EndpointI read(Ice.InputStream s)
{
lock(this)
{
@@ -169,7 +169,7 @@ namespace IceInternal
EndpointFactory factory = get(type);
EndpointI e = null;
- s.startReadEncaps();
+ s.startEncapsulation();
if(factory != null)
{
@@ -180,7 +180,7 @@ namespace IceInternal
e = new OpaqueEndpointI(type, s);
}
- s.endReadEncaps();
+ s.endEncapsulation();
return e;
}
diff --git a/csharp/src/Ice/EndpointHostResolver.cs b/csharp/src/Ice/EndpointHostResolver.cs
index a94a2c37923..c925763dfeb 100644
--- a/csharp/src/Ice/EndpointHostResolver.cs
+++ b/csharp/src/Ice/EndpointHostResolver.cs
@@ -163,7 +163,7 @@ namespace IceInternal
{
if(r.observer != null)
{
- r.observer.failed(ex.ice_name());
+ r.observer.failed(ex.ice_id());
}
r.callback.exception(ex);
}
@@ -186,7 +186,7 @@ namespace IceInternal
Ice.CommunicatorDestroyedException ex = new Ice.CommunicatorDestroyedException();
if(entry.observer != null)
{
- entry.observer.failed(ex.ice_name());
+ entry.observer.failed(ex.ice_id());
entry.observer.detach();
}
entry.callback.exception(ex);
diff --git a/csharp/src/Ice/EndpointI.cs b/csharp/src/Ice/EndpointI.cs
index 800e23afa12..926e547ddff 100644
--- a/csharp/src/Ice/EndpointI.cs
+++ b/csharp/src/Ice/EndpointI.cs
@@ -60,7 +60,7 @@ namespace IceInternal
//
// Marshal the endpoint.
//
- public abstract void streamWrite(BasicStream s);
+ public abstract void streamWrite(Ice.OutputStream s);
//
// Return the endpoint type.
diff --git a/csharp/src/Ice/Exception.cs b/csharp/src/Ice/Exception.cs
index 4a05b30a00f..3fcda64934f 100644
--- a/csharp/src/Ice/Exception.cs
+++ b/csharp/src/Ice/Exception.cs
@@ -71,10 +71,21 @@ namespace Ice
#endif
/// <summary>
+ /// ice_name() is deprecated, use ice_id() instead.
/// Returns the name of this exception.
/// </summary>
/// <returns>The name of this exception.</returns>
- public abstract string ice_name();
+ [System.Obsolete("ice_name() is deprecated, use ice_id() instead.")]
+ public string ice_name()
+ {
+ return ice_id().Substring(2);
+ }
+
+ /// <summary>
+ /// Returns the type id of this exception.
+ /// </summary>
+ /// <returns>The type id of this exception.</returns>
+ public abstract string ice_id();
/// <summary>
/// Returns a string representation of this exception, including
@@ -207,20 +218,6 @@ namespace Ice
protected UserException(SerializationInfo info, StreamingContext context) : base(info, context) {}
#endif
- public virtual void write__(IceInternal.BasicStream os__)
- {
- os__.startWriteException(null);
- writeImpl__(os__);
- os__.endWriteException();
- }
-
- public virtual void read__(IceInternal.BasicStream is__)
- {
- is__.startReadException();
- readImpl__(is__);
- is__.endReadException(false);
- }
-
public virtual void write__(OutputStream os__)
{
os__.startException(null);
@@ -240,18 +237,8 @@ namespace Ice
return false;
}
- protected abstract void writeImpl__(IceInternal.BasicStream os__);
- protected abstract void readImpl__(IceInternal.BasicStream is__);
-
- protected virtual void writeImpl__(OutputStream os__)
- {
- throw new MarshalException("exception was not generated with stream support");
- }
-
- protected virtual void readImpl__(InputStream is__)
- {
- throw new MarshalException("exception was not generated with stream support");
- }
+ protected abstract void writeImpl__(OutputStream os__);
+ protected abstract void readImpl__(InputStream is__);
}
}
diff --git a/csharp/src/Ice/IPEndpointI.cs b/csharp/src/Ice/IPEndpointI.cs
index e3826a7f15d..7cb442a4284 100644
--- a/csharp/src/Ice/IPEndpointI.cs
+++ b/csharp/src/Ice/IPEndpointI.cs
@@ -38,7 +38,7 @@ namespace IceInternal
_hashInitialized = false;
}
- public IPEndpointI(ProtocolInstance instance, BasicStream s)
+ public IPEndpointI(ProtocolInstance instance, Ice.InputStream s)
{
instance_ = instance;
host_ = s.readString();
@@ -80,11 +80,11 @@ namespace IceInternal
return info;
}
- public override void streamWrite(BasicStream s)
+ public override void streamWrite(Ice.OutputStream s)
{
- s.startWriteEncaps();
+ s.startEncapsulation();
streamWriteImpl(s);
- s.endWriteEncaps();
+ s.endEncapsulation();
}
public override short type()
@@ -272,7 +272,7 @@ namespace IceInternal
return port_;
}
- public virtual void streamWriteImpl(BasicStream s)
+ public virtual void streamWriteImpl(Ice.OutputStream s)
{
s.writeString(host_);
s.writeInt(port_);
diff --git a/csharp/src/Ice/ImplicitContextI.cs b/csharp/src/Ice/ImplicitContextI.cs
index f127ae007c6..75372babf47 100644
--- a/csharp/src/Ice/ImplicitContextI.cs
+++ b/csharp/src/Ice/ImplicitContextI.cs
@@ -46,8 +46,7 @@ namespace Ice
public abstract string put(string key, string value);
public abstract string remove(string key);
- abstract public void write(Dictionary<string, string> prxContext,
- IceInternal.BasicStream os);
+ abstract public void write(Dictionary<string, string> prxContext, OutputStream os);
abstract internal Dictionary<string, string> combine(Dictionary<string, string> prxContext);
}
@@ -158,7 +157,7 @@ namespace Ice
}
}
- public override void write(Dictionary<string, string> prxContext, IceInternal.BasicStream os)
+ public override void write(Dictionary<string, string> prxContext, OutputStream os)
{
if(prxContext.Count == 0)
{
@@ -345,7 +344,7 @@ namespace Ice
return val;
}
- public override void write(Dictionary<string, string> prxContext, IceInternal.BasicStream os)
+ public override void write(Dictionary<string, string> prxContext, OutputStream os)
{
Dictionary<string, string> threadContext = null;
lock(this)
diff --git a/csharp/src/Ice/Incoming.cs b/csharp/src/Ice/Incoming.cs
index 19d558f1da7..1f4c24c7fb7 100644
--- a/csharp/src/Ice/Incoming.cs
+++ b/csharp/src/Ice/Incoming.cs
@@ -26,7 +26,7 @@ namespace IceInternal
compress_ = compress;
if(response_)
{
- os_ = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
+ os_ = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding);
}
current_ = new Ice.Current();
@@ -94,7 +94,7 @@ namespace IceInternal
inc.responseHandler_ = null;
}
- public BasicStream startWriteParams__(Ice.FormatType format)
+ public Ice.OutputStream startWriteParams__(Ice.FormatType format)
{
if(!response_)
{
@@ -103,7 +103,7 @@ namespace IceInternal
Debug.Assert(os_.size() == Protocol.headerSize + 4); // Reply status position.
os_.writeByte((byte)0);
- os_.startWriteEncaps(current_.encoding, format);
+ os_.startEncapsulation(current_.encoding, format);
return os_;
}
@@ -120,7 +120,7 @@ namespace IceInternal
os_.pos(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ok ? ReplyStatus.replyOK : ReplyStatus.replyUserException);
os_.pos(save);
- os_.endWriteEncaps();
+ os_.endEncapsulation();
}
}
@@ -130,7 +130,7 @@ namespace IceInternal
{
Debug.Assert(os_.size() == Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyOK);
- os_.writeEmptyEncaps(current_.encoding);
+ os_.writeEmptyEncapsulation(current_.encoding);
}
}
@@ -147,19 +147,19 @@ namespace IceInternal
os_.writeByte(ok ? ReplyStatus.replyOK : ReplyStatus.replyUserException);
if(v == null || v.Length == 0)
{
- os_.writeEmptyEncaps(current_.encoding);
+ os_.writeEmptyEncapsulation(current_.encoding);
}
else
{
- os_.writeEncaps(v);
+ os_.writeEncapsulation(v);
}
}
}
public void writeUserException__(Ice.UserException ex, Ice.FormatType format)
{
- BasicStream os__ = startWriteParams__(format);
- os__.writeUserException(ex);
+ Ice.OutputStream os__ = startWriteParams__(format);
+ os__.writeException(ex);
endWriteParams__(false);
}
@@ -188,7 +188,7 @@ namespace IceInternal
if(response_ && os_ == null)
{
- os_ = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
+ os_ = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding);
}
responseHandler_ = handler;
@@ -263,11 +263,11 @@ namespace IceInternal
//
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUserException);
- os_.startWriteEncaps(current_.encoding, Ice.FormatType.DefaultFormat);
- os_.writeUserException(ex);
- os_.endWriteEncaps();
+ os_.startEncapsulation(current_.encoding, Ice.FormatType.DefaultFormat);
+ os_.writeException(ex);
+ os_.endEncapsulation();
if(observer_ != null)
{
observer_.reply(os_.size() - Protocol.headerSize - 4);
@@ -325,12 +325,12 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
if(ex is Ice.ObjectNotExistException)
{
os_.writeByte(ReplyStatus.replyObjectNotExist);
@@ -384,12 +384,12 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownLocalException);
os_.writeString(ex.unknown);
if(observer_ != null)
@@ -412,12 +412,12 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownUserException);
os_.writeString(ex.unknown);
if(observer_ != null)
@@ -440,12 +440,12 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownException);
os_.writeString(ex.unknown);
if(observer_ != null)
@@ -468,14 +468,14 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownUserException);
- os_.writeString(ex.ice_name() + "\n" + ex.StackTrace);
+ os_.writeString(ex.ice_id() + "\n" + ex.StackTrace);
if(observer_ != null)
{
observer_.reply(os_.size() - Protocol.headerSize - 4);
@@ -504,14 +504,14 @@ namespace IceInternal
if(observer_ != null)
{
- observer_.failed(ex.ice_name());
+ observer_.failed(ex.ice_id());
}
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownLocalException);
- os_.writeString(ex.ice_name() + "\n" + ex.StackTrace);
+ os_.writeString(ex.ice_id() + "\n" + ex.StackTrace);
if(observer_ != null)
{
observer_.reply(os_.size() - Protocol.headerSize - 4);
@@ -537,7 +537,7 @@ namespace IceInternal
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false); // Reply status position.
+ os_.resize(Protocol.headerSize + 4); // Reply status position.
os_.writeByte(ReplyStatus.replyUnknownException);
os_.writeString(ex.ToString());
if(observer_ != null)
@@ -570,7 +570,7 @@ namespace IceInternal
protected internal bool response_;
protected internal byte compress_;
- protected internal BasicStream os_;
+ protected internal Ice.OutputStream os_;
protected ResponseHandler responseHandler_;
@@ -636,7 +636,7 @@ namespace IceInternal
base.reclaim();
}
- public void invoke(ServantManager servantManager, BasicStream stream)
+ public void invoke(ServantManager servantManager, Ice.InputStream stream)
{
_is = stream;
@@ -714,7 +714,7 @@ namespace IceInternal
}
catch(Ice.UserException ex)
{
- Ice.EncodingVersion encoding = _is.skipEncaps(); // Required for batch requests.
+ Ice.EncodingVersion encoding = _is.skipEncapsulation(); // Required for batch requests.
if(observer_ != null)
{
@@ -724,9 +724,9 @@ namespace IceInternal
if(response_)
{
os_.writeByte(ReplyStatus.replyUserException);
- os_.startWriteEncaps(encoding, Ice.FormatType.DefaultFormat);
- os_.writeUserException(ex);
- os_.endWriteEncaps();
+ os_.startEncapsulation(encoding, Ice.FormatType.DefaultFormat);
+ os_.writeException(ex);
+ os_.endEncapsulation();
if(observer_ != null)
{
observer_.reply(os_.size() - Protocol.headerSize - 4);
@@ -748,7 +748,7 @@ namespace IceInternal
}
catch(System.Exception ex)
{
- _is.skipEncaps(); // Required for batch requests.
+ _is.skipEncapsulation(); // Required for batch requests.
handleException__(ex, false);
return;
}
@@ -783,7 +783,7 @@ namespace IceInternal
// Skip the input parameters, this is required for reading
// the next batch request if dispatching batch requests.
//
- _is.skipEncaps();
+ _is.skipEncapsulation();
if(servantManager != null && servantManager.hasServant(current_.id))
{
@@ -869,7 +869,7 @@ namespace IceInternal
_is.pos(_inParamPos);
if(response_)
{
- os_.resize(Protocol.headerSize + 4, false);
+ os_.resize(Protocol.headerSize + 4);
}
}
}
@@ -889,29 +889,29 @@ namespace IceInternal
}
}
- public BasicStream startReadParams()
+ public Ice.InputStream startReadParams()
{
//
// Remember the encoding used by the input parameters, we'll
// encode the response parameters with the same encoding.
//
- current_.encoding = _is.startReadEncaps();
+ current_.encoding = _is.startEncapsulation();
return _is;
}
public void endReadParams()
{
- _is.endReadEncaps();
+ _is.endEncapsulation();
}
public void readEmptyParams()
{
- current_.encoding = _is.skipEmptyEncaps();
+ current_.encoding = _is.skipEmptyEncapsulation();
}
public byte[] readParamEncaps()
{
- return _is.readEncaps(out current_.encoding);
+ return _is.readEncapsulation(out current_.encoding);
}
internal void setActive(IncomingAsync cb)
@@ -927,7 +927,7 @@ namespace IceInternal
public Incoming next; // For use by Connection.
- private BasicStream _is;
+ private Ice.InputStream _is;
private IncomingAsync _cb;
private int _inParamPos = -1;
diff --git a/csharp/src/Ice/IncomingAsync.cs b/csharp/src/Ice/IncomingAsync.cs
index a375a906931..3008e5b72f3 100644
--- a/csharp/src/Ice/IncomingAsync.cs
+++ b/csharp/src/Ice/IncomingAsync.cs
@@ -152,7 +152,7 @@ namespace IceInternal
}
}
- protected internal BasicStream getOs__()
+ protected internal Ice.OutputStream getOs__()
{
return os_;
}
diff --git a/csharp/src/Ice/InputStream.cs b/csharp/src/Ice/InputStream.cs
new file mode 100644
index 00000000000..100328fcb5e
--- /dev/null
+++ b/csharp/src/Ice/InputStream.cs
@@ -0,0 +1,4029 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+namespace Ice
+{
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Reflection;
+#if !COMPACT && !SILVERLIGHT
+ using System.Runtime.Serialization;
+ using System.Runtime.Serialization.Formatters.Binary;
+#endif
+ using System.Threading;
+ using Protocol = IceInternal.Protocol;
+
+ /// <summary>
+ /// After a call to readPendingObjects(), delegates are called to supply the
+ /// unmarshaled objects.
+ /// </summary>
+ /// <param name="obj">The unmarshaled object.</param>
+ public delegate void ReadObjectCallback(Ice.Object obj);
+
+ /// <summary>
+ /// A ClassResolver translates a Slice type Id into a type using
+ /// an implementation-defined algorithm.
+ /// </summary>
+ /// <param name="id">A Slice type Id corresponding to a Slice value or user exception.</param>
+ public delegate System.Type ClassResolver(string id);
+
+ /// <summary>
+ /// Throws a UserException corresponding to the given Slice type Id, such as "::Module::MyException".
+ /// If the implementation does not throw an exception, the Ice run time will fall back
+ /// to using its default behavior for instantiating the user exception.
+ /// </summary>
+ /// <param name="id">A Slice type Id corresponding to a Slice user exception.</param>
+ public delegate void UserExceptionFactory(string id);
+
+ /// <summary>
+ /// Interface for input streams used to extract Slice types from a sequence of bytes.
+ /// </summary>
+ public class InputStream
+ {
+
+ /// <summary>
+ /// Constructing an InputStream without providing a communicator means the stream will
+ /// use the default encoding version. A communicator is required in order to unmarshal
+ /// proxies. You can supply a communicator later by calling initialize().
+ /// </summary>
+ public InputStream()
+ {
+ initialize(Util.currentEncoding);
+ _buf = new IceInternal.Buffer();
+ }
+
+ /// <summary>
+ /// Constructing an InputStream without providing a communicator means the stream will
+ /// use the default encoding version. A communicator is required in order to unmarshal
+ /// proxies. You can supply a communicator later by calling initialize().
+ /// </summary>
+ /// <param name="data">The byte array containing encoded Slice types.</param>
+ public InputStream(byte[] data)
+ {
+ initialize(Util.currentEncoding);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ public InputStream(IceInternal.ByteBuffer buf)
+ {
+ initialize(Util.currentEncoding);
+ _buf = new IceInternal.Buffer(buf);
+ }
+
+ public InputStream(IceInternal.Buffer buf) :
+ this(buf, false)
+ {
+ }
+
+ public InputStream(IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(Util.currentEncoding);
+ _buf = new IceInternal.Buffer(buf, adopt);
+ }
+
+ /// <summary>
+ /// This constructor uses the communicator's default encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ public InputStream(Communicator communicator)
+ {
+ initialize(communicator);
+ _buf = new IceInternal.Buffer();
+ }
+
+ /// <summary>
+ /// This constructor uses the communicator's default encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="data">The byte array containing encoded Slice types.</param>
+ public InputStream(Communicator communicator, byte[] data)
+ {
+ initialize(communicator);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ public InputStream(Communicator communicator, IceInternal.ByteBuffer buf)
+ {
+ initialize(communicator);
+ _buf = new IceInternal.Buffer(buf);
+ }
+
+ public InputStream(Communicator communicator, IceInternal.Buffer buf) :
+ this(communicator, buf, false)
+ {
+ }
+
+ public InputStream(Communicator communicator, IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(communicator);
+ _buf = new IceInternal.Buffer(buf, adopt);
+ }
+
+ /// <summary>
+ /// This constructor uses the given encoding version.
+ /// </summary>
+ /// <param name="encoding">The desired encoding version.</param>
+ public InputStream(EncodingVersion encoding)
+ {
+ initialize(encoding);
+ _buf = new IceInternal.Buffer();
+ }
+
+ /// <summary>
+ /// This constructor uses the given encoding version.
+ /// </summary>
+ /// <param name="encoding">The desired encoding version.</param>
+ /// <param name="data">The byte array containing encoded Slice types.</param>
+ public InputStream(EncodingVersion encoding, byte[] data)
+ {
+ initialize(encoding);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ public InputStream(EncodingVersion encoding, IceInternal.ByteBuffer buf)
+ {
+ initialize(encoding);
+ _buf = new IceInternal.Buffer(buf);
+ }
+
+ public InputStream(EncodingVersion encoding, IceInternal.Buffer buf) :
+ this(encoding, buf, false)
+ {
+ }
+
+ public InputStream(EncodingVersion encoding, IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(encoding);
+ _buf = new IceInternal.Buffer(buf, adopt);
+ }
+
+ /// <summary>
+ /// This constructor uses the given encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="encoding">The desired encoding version.</param>
+ public InputStream(Communicator communicator, EncodingVersion encoding)
+ {
+ initialize(communicator, encoding);
+ _buf = new IceInternal.Buffer();
+ }
+
+ /// <summary>
+ /// This constructor uses the given encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="encoding">The desired encoding version.</param>
+ /// <param name="data">The byte array containing encoded Slice types.</param>
+ public InputStream(Communicator communicator, EncodingVersion encoding, byte[] data)
+ {
+ initialize(communicator, encoding);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.ByteBuffer buf)
+ {
+ initialize(communicator, encoding);
+ _buf = new IceInternal.Buffer(buf);
+ }
+
+ public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.Buffer buf) :
+ this(communicator, encoding, buf, false)
+ {
+ }
+
+ public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(communicator, encoding);
+ _buf = new IceInternal.Buffer(buf, adopt);
+ }
+
+ public InputStream(IceInternal.Instance instance, EncodingVersion encoding)
+ {
+ initialize(instance, encoding);
+ _buf = new IceInternal.Buffer();
+ }
+
+ public InputStream(IceInternal.Instance instance, EncodingVersion encoding, byte[] data)
+ {
+ initialize(instance, encoding);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.ByteBuffer buf)
+ {
+ initialize(instance, encoding);
+ _buf = new IceInternal.Buffer(buf);
+ }
+
+ public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf) :
+ this(instance, encoding, buf, false)
+ {
+ }
+
+ public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(instance, encoding);
+ _buf = new IceInternal.Buffer(buf, adopt);
+ }
+
+ /// <summary>
+ /// Initializes the stream to use the communicator's default encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ public void initialize(Communicator communicator)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, instance.defaultsAndOverrides().defaultEncoding);
+ }
+
+ /// <summary>
+ /// Initializes the stream to use the given communicator and encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="encoding">The desired encoding version.</param>
+ public void initialize(Communicator communicator, EncodingVersion encoding)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, encoding);
+ }
+
+ private void initialize(IceInternal.Instance instance, EncodingVersion encoding)
+ {
+ initialize(encoding);
+
+ instance_ = instance;
+ _traceSlicing = instance_.traceLevels().slicing > 0;
+
+ _valueFactoryManager = instance_.initializationData().valueFactoryManager;
+ _logger = instance_.initializationData().logger;
+ _classResolver = instance_.resolveClass;
+ }
+
+ private void initialize(EncodingVersion encoding)
+ {
+ instance_ = null;
+ _encoding = encoding;
+ _encapsStack = null;
+ _encapsCache = null;
+ _traceSlicing = false;
+ _closure = null;
+ _sliceObjects = true;
+ _startSeq = -1;
+ _minSeqSize = 0;
+ }
+
+ /// <summary>
+ /// Resets this stream. This method allows the stream to be reused, to avoid creating
+ /// unnecessary garbage.
+ /// </summary>
+ public void reset()
+ {
+ _buf.reset();
+ clear();
+ }
+
+ /// <summary>
+ /// Releases any data retained by encapsulations. Internally calls clear().
+ /// </summary>
+ public void clear()
+ {
+ if(_encapsStack != null)
+ {
+ Debug.Assert(_encapsStack.next == null);
+ _encapsStack.next = _encapsCache;
+ _encapsCache = _encapsStack;
+ _encapsStack = null;
+ _encapsCache.reset();
+ }
+
+ _startSeq = -1;
+ _sliceObjects = true;
+ }
+
+ /// <summary>
+ /// Sets the value factory manager to use when marshaling value instances. If the stream
+ /// was initialized with a communicator, the communicator's value factory manager will
+ /// be used by default.
+ /// </summary>
+ /// <param name="vfm">The value factory manager.</param>
+ public void setValueFactoryManager(ValueFactoryManager vfm)
+ {
+ _valueFactoryManager = vfm;
+ }
+
+ /// <summary>
+ /// Sets the logger to use when logging trace messages. If the stream
+ /// was initialized with a communicator, the communicator's logger will
+ /// be used by default.
+ /// </summary>
+ /// <param name="logger">The logger to use for logging trace messages.</param>
+ public void setLogger(Logger logger)
+ {
+ _logger = logger;
+ }
+
+ /// <summary>
+ /// Sets the compact ID resolver to use when unmarshaling value and exception
+ /// instances. If the stream was initialized with a communicator, the communicator's
+ /// resolver will be used by default.
+ /// </summary>
+ /// <param name="r">The compact ID resolver.</param>
+ public void setCompactIdResolver(CompactIdResolver r)
+ {
+ _compactIdResolver = r;
+ }
+
+ /// <summary>
+ /// Sets the class resolver, which the stream will use when attempting to unmarshal
+ /// a value or exception. If the stream was initialized with a communicator, the communicator's
+ /// resolver will be used by default.
+ /// </summary>
+ /// <param name="r">The class resolver.</param>
+ public void setClassResolver(ClassResolver r)
+ {
+ _classResolver = r;
+ }
+
+ /// <summary>
+ /// Determines the behavior of the stream when extracting Slice objects.
+ /// A Slice object is "sliced" when a factory cannot be found for a Slice type ID.
+ /// The stream's default behavior is to slice objects.
+ /// </summary>
+ /// <param name="b">If true (the default), slicing is enabled; if false,
+ /// slicing is disabled. If slicing is disabled and the stream encounters a Slice type ID
+ /// during decoding for which no value factory is installed, it raises NoValueFactoryException.
+ /// </param>
+ public void setSliceObjects(bool b)
+ {
+ _sliceObjects = b;
+ }
+
+ /// <summary>
+ /// Determines whether the stream logs messages about slicing instances of Slice values.
+ /// </summary>
+ /// <param name="b">True to enable logging, false to disable logging.</param>
+ public void setTraceSlicing(bool b)
+ {
+ _traceSlicing = b;
+ }
+
+ /// <summary>
+ /// Retrieves the closure object associated with this stream.
+ /// </summary>
+ /// <returns>The closure object.</returns>
+ public object getClosure()
+ {
+ return _closure;
+ }
+
+ /// <summary>
+ /// Associates a closure object with this stream.
+ /// </summary>
+ /// <param name="p">The new closure object.</param>
+ /// <returns>The previous closure object, or null.</returns>
+ public object setClosure(object p)
+ {
+ object prev = _closure;
+ _closure = p;
+ return prev;
+ }
+
+ public IceInternal.Instance instance()
+ {
+ return instance_;
+ }
+
+ /// <summary>
+ /// Swaps the contents of one stream with another.
+ /// </summary>
+ /// <param name="other">The other stream.</param>
+ public void swap(InputStream other)
+ {
+ Debug.Assert(instance_ == other.instance_);
+
+ IceInternal.Buffer tmpBuf = other._buf;
+ other._buf = _buf;
+ _buf = tmpBuf;
+
+ EncodingVersion tmpEncoding = other._encoding;
+ other._encoding = _encoding;
+ _encoding = tmpEncoding;
+
+ bool tmpTraceSlicing = other._traceSlicing;
+ other._traceSlicing = _traceSlicing;
+ _traceSlicing = tmpTraceSlicing;
+
+ object tmpClosure = other._closure;
+ other._closure = _closure;
+ _closure = tmpClosure;
+
+ bool tmpSliceObjects = other._sliceObjects;
+ other._sliceObjects = _sliceObjects;
+ _sliceObjects = tmpSliceObjects;
+
+ //
+ // Swap is never called for InputStreams that have encapsulations being read. However,
+ // encapsulations might still be set in case un-marshalling failed. We just
+ // reset the encapsulations if there are still some set.
+ //
+ resetEncapsulation();
+ other.resetEncapsulation();
+
+ int tmpStartSeq = other._startSeq;
+ other._startSeq = _startSeq;
+ _startSeq = tmpStartSeq;
+
+ int tmpMinSeqSize = other._minSeqSize;
+ other._minSeqSize = _minSeqSize;
+ _minSeqSize = tmpMinSeqSize;
+
+ ValueFactoryManager tmpVfm = other._valueFactoryManager;
+ other._valueFactoryManager = _valueFactoryManager;
+ _valueFactoryManager = tmpVfm;
+
+ Logger tmpLogger = other._logger;
+ other._logger = _logger;
+ _logger = tmpLogger;
+
+ CompactIdResolver tmpCompactIdResolver = other._compactIdResolver;
+ other._compactIdResolver = _compactIdResolver;
+ _compactIdResolver = tmpCompactIdResolver;
+
+ ClassResolver tmpClassResolver = other._classResolver;
+ other._classResolver = _classResolver;
+ _classResolver = tmpClassResolver;
+ }
+
+ private void resetEncapsulation()
+ {
+ _encapsStack = null;
+ }
+
+ /// <summary>
+ /// Resizes the stream to a new size.
+ /// </summary>
+ /// <param name="sz">The new size.</param>
+ public void resize(int sz)
+ {
+ _buf.resize(sz, true);
+ _buf.b.position(sz);
+ }
+
+ public IceInternal.Buffer getBuffer()
+ {
+ return _buf;
+ }
+
+ /// <summary>
+ /// Marks the start of an Ice object.
+ /// </summary>
+ public void startObject()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ _encapsStack.decoder.startInstance(SliceType.ObjectSlice);
+ }
+
+ /// <summary>
+ /// Marks the end of an Ice object.
+ /// </summary>
+ /// <param name="preserve">True if unknown slices should be preserved, false otherwise.</param>
+ /// <returns>A SlicedData object containing the preserved slices for unknown types.</returns>
+ public SlicedData endObject(bool preserve)
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ return _encapsStack.decoder.endInstance(preserve);
+ }
+
+ /// <summary>
+ /// Marks the start of a user exception.
+ /// </summary>
+ public void startException()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ _encapsStack.decoder.startInstance(SliceType.ExceptionSlice);
+ }
+
+ /// <summary>
+ /// Marks the end of a user exception.
+ /// </summary>
+ /// <param name="preserve">True if unknown slices should be preserved, false otherwise.</param>
+ /// <returns>A SlicedData object containing the preserved slices for unknown types.</returns>
+ public SlicedData endException(bool preserve)
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ return _encapsStack.decoder.endInstance(preserve);
+ }
+
+ /// <summary>
+ /// Reads the start of an encapsulation.
+ /// </summary>
+ /// <returns>The encapsulation encoding version.</returns>
+ public EncodingVersion startEncapsulation()
+ {
+ Encaps curr = _encapsCache;
+ if(curr != null)
+ {
+ curr.reset();
+ _encapsCache = _encapsCache.next;
+ }
+ else
+ {
+ curr = new Encaps();
+ }
+ curr.next = _encapsStack;
+ _encapsStack = curr;
+
+ _encapsStack.start = _buf.b.position();
+
+ //
+ // I don't use readSize() for encapsulations, because when creating an encapsulation,
+ // I must know in advance how many bytes the size information will require in the data
+ // stream. If I use an Int, it is always 4 bytes. For readSize(), it could be 1 or 5 bytes.
+ //
+ int sz = readInt();
+ if(sz < 6)
+ {
+ throw new UnmarshalOutOfBoundsException();
+ }
+ if(sz - 4 > _buf.b.remaining())
+ {
+ throw new UnmarshalOutOfBoundsException();
+ }
+ _encapsStack.sz = sz;
+
+ EncodingVersion encoding = new EncodingVersion();
+ encoding.read__(this);
+ Protocol.checkSupportedEncoding(encoding); // Make sure the encoding is supported.
+ _encapsStack.setEncoding(encoding);
+
+ return encoding;
+ }
+
+ /// <summary>
+ /// Ends the previous encapsulation.
+ /// </summary>
+ public void endEncapsulation()
+ {
+ Debug.Assert(_encapsStack != null);
+
+ if(!_encapsStack.encoding_1_0)
+ {
+ skipOptionals();
+ if(_buf.b.position() != _encapsStack.start + _encapsStack.sz)
+ {
+ throw new EncapsulationException();
+ }
+ }
+ else if(_buf.b.position() != _encapsStack.start + _encapsStack.sz)
+ {
+ if(_buf.b.position() + 1 != _encapsStack.start + _encapsStack.sz)
+ {
+ throw new EncapsulationException();
+ }
+
+ //
+ // Ice version < 3.3 had a bug where user exceptions with
+ // class members could be encoded with a trailing byte
+ // when dispatched with AMD. So we tolerate an extra byte
+ // in the encapsulation.
+ //
+ try
+ {
+ _buf.b.get();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ Encaps curr = _encapsStack;
+ _encapsStack = curr.next;
+ curr.next = _encapsCache;
+ _encapsCache = curr;
+ _encapsCache.reset();
+ }
+
+ /// <summary>
+ /// Skips an empty encapsulation.
+ /// </summary>
+ /// <returns>The encapsulation's encoding version.</returns>
+ public EncodingVersion skipEmptyEncapsulation()
+ {
+ int sz = readInt();
+ if(sz != 6)
+ {
+ throw new EncapsulationException();
+ }
+
+ EncodingVersion encoding = new EncodingVersion();
+ encoding.read__(this);
+ return encoding;
+ }
+
+ /// <summary>
+ /// Returns a blob of bytes representing an encapsulation. The encapsulation's encoding version
+ /// is returned in the argument.
+ /// </summary>
+ /// <param name="encoding">The encapsulation's encoding version.</param>
+ /// <returns>The encoded encapsulation.</returns>
+ public byte[] readEncapsulation(out EncodingVersion encoding)
+ {
+ int sz = readInt();
+ if(sz < 6)
+ {
+ throw new UnmarshalOutOfBoundsException();
+ }
+
+ if(sz - 4 > _buf.b.remaining())
+ {
+ throw new UnmarshalOutOfBoundsException();
+ }
+
+ encoding = new EncodingVersion();
+ encoding.read__(this);
+ _buf.b.position(_buf.b.position() - 6);
+
+ byte[] v = new byte[sz];
+ try
+ {
+ _buf.b.get(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Determines the current encoding version.
+ /// </summary>
+ /// <returns>The encoding version.</returns>
+ public EncodingVersion getEncoding()
+ {
+ return _encapsStack != null ? _encapsStack.encoding : _encoding;
+ }
+
+ /// <summary>
+ /// Determines the size of the current encapsulation, excluding the encapsulation header.
+ /// </summary>
+ /// <returns>The size of the encapsulated data.</returns>
+ public int getEncapsulationSize()
+ {
+ Debug.Assert(_encapsStack != null);
+ return _encapsStack.sz - 6;
+ }
+
+ /// <summary>
+ /// Skips over an encapsulation.
+ /// </summary>
+ /// <returns>The encoding version of the skipped encapsulation.</returns>
+ public EncodingVersion skipEncapsulation()
+ {
+ int sz = readInt();
+ if(sz < 6)
+ {
+ throw new UnmarshalOutOfBoundsException();
+ }
+ EncodingVersion encoding = new EncodingVersion();
+ encoding.read__(this);
+ try
+ {
+ _buf.b.position(_buf.b.position() + sz - 6);
+ }
+ catch(ArgumentOutOfRangeException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ return encoding;
+ }
+
+ /// <summary>
+ /// Reads the start of an object or exception slice.
+ /// </summary>
+ /// <returns>The Slice type ID for this slice.</returns>
+ public string startSlice() // Returns type ID of next slice
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ return _encapsStack.decoder.startSlice();
+ }
+
+ /// <summary>
+ /// Indicates that the end of an object or exception slice has been reached.
+ /// </summary>
+ public void endSlice()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ _encapsStack.decoder.endSlice();
+ }
+
+ /// <summary>
+ /// Skips over an object or exception slice.
+ /// </summary>
+ public void skipSlice()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.decoder != null);
+ _encapsStack.decoder.skipSlice();
+ }
+
+ /// <summary>
+ /// Indicates that unmarshaling is complete, except for any Slice objects. The application must call this
+ /// method only if the stream actually contains Slice objects. Calling readPendingObjects triggers the
+ /// calls the ReadObjectCallback delegates to inform the application that unmarshaling of a Slice
+ /// object is complete.
+ /// </summary>
+ public void readPendingObjects()
+ {
+ if(_encapsStack != null && _encapsStack.decoder != null)
+ {
+ _encapsStack.decoder.readPendingObjects();
+ }
+ else if(_encapsStack != null ? _encapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0))
+ {
+ //
+ // If using the 1.0 encoding and no objects were read, we
+ // still read an empty sequence of pending objects if
+ // requested (i.e.: if this is called).
+ //
+ // This is required by the 1.0 encoding, even if no objects
+ // are written we do marshal an empty sequence if marshaled
+ // data types use classes.
+ //
+ skipSize();
+ }
+ }
+
+ /// <summary>
+ /// Extracts a size from the stream.
+ /// </summary>
+ /// <returns>The extracted size.</returns>
+ public int readSize()
+ {
+ try
+ {
+ //
+ // COMPILERFIX: for some reasons _buf.get() doesn't work here on OS X with Mono;
+ //
+ //byte b = _buf.b.get();
+ byte b = readByte();
+ if(b == 255)
+ {
+ int v = _buf.b.getInt();
+ if(v < 0)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+ return v;
+ }
+ else
+ {
+ return b; // byte is unsigned
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Reads and validates a sequence size.
+ /// </summary>
+ /// <returns>The extracted size.</returns>
+ public int readAndCheckSeqSize(int minSize)
+ {
+ int sz = readSize();
+
+ if(sz == 0)
+ {
+ return 0;
+ }
+
+ //
+ // The _startSeq variable points to the start of the sequence for which
+ // we expect to read at least _minSeqSize bytes from the stream.
+ //
+ // If not initialized or if we already read more data than _minSeqSize,
+ // we reset _startSeq and _minSeqSize for this sequence (possibly a
+ // top-level sequence or enclosed sequence it doesn't really matter).
+ //
+ // Otherwise, we are reading an enclosed sequence and we have to bump
+ // _minSeqSize by the minimum size that this sequence will require on
+ // the stream.
+ //
+ // The goal of this check is to ensure that when we start un-marshalling
+ // a new sequence, we check the minimal size of this new sequence against
+ // the estimated remaining buffer size. This estimatation is based on
+ // the minimum size of the enclosing sequences, it's _minSeqSize.
+ //
+ if(_startSeq == -1 || _buf.b.position() > (_startSeq + _minSeqSize))
+ {
+ _startSeq = _buf.b.position();
+ _minSeqSize = sz * minSize;
+ }
+ else
+ {
+ _minSeqSize += sz * minSize;
+ }
+
+ //
+ // If there isn't enough data to read on the stream for the sequence (and
+ // possibly enclosed sequences), something is wrong with the marshalled
+ // data: it's claiming having more data that what is possible to read.
+ //
+ if(_startSeq + _minSeqSize > _buf.size())
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+
+ return sz;
+ }
+
+ /// <summary>
+ /// Reads a blob of bytes from the stream. The length of the given array determines how many bytes are read.
+ /// </summary>
+ /// <param name="v">Bytes from the stream.</param>
+ public void readBlob(byte[] v)
+ {
+ try
+ {
+ _buf.b.get(v);
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Reads a blob of bytes from the stream.
+ /// </summary>
+ /// <param name="sz">The number of bytes to read.</param>
+ /// <returns>The requested bytes as a byte array.</returns>
+ public byte[] readBlob(int sz)
+ {
+ if(_buf.b.remaining() < sz)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+ byte[] v = new byte[sz];
+ try
+ {
+ _buf.b.get(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Determine if an optional value is available for reading.
+ /// </summary>
+ /// <param name="tag">The tag associated with the value.</param>
+ /// <param name="expectedFormat">The optional format for the value.</param>
+ /// <returns>True if the value is present, false otherwise.</returns>
+ public bool readOptional(int tag, Ice.OptionalFormat expectedFormat)
+ {
+ Debug.Assert(_encapsStack != null);
+ if(_encapsStack.decoder != null)
+ {
+ return _encapsStack.decoder.readOptional(tag, expectedFormat);
+ }
+ else
+ {
+ return readOptImpl(tag, expectedFormat);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a byte value from the stream.
+ /// </summary>
+ /// <returns>The extracted byte.</returns>
+ public byte readByte()
+ {
+ try
+ {
+ return _buf.b.get();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional byte value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<byte> readByte(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F1))
+ {
+ return new Ice.Optional<byte>(readByte());
+ }
+ else
+ {
+ return new Ice.Optional<byte>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional byte value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readByte(int tag, out bool isset, out byte v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F1))
+ {
+ v = readByte();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of byte values from the stream.
+ /// </summary>
+ /// <returns>The extracted byte sequence.</returns>
+ public byte[] readByteSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(1);
+ byte[] v = new byte[sz];
+ _buf.b.get(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of byte values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted byte sequence as a list.</param>
+ public void readByteSeq(out List<byte> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<byte>(readByteSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of byte values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted byte sequence as a linked list.</param>
+ public void readByteSeq(out LinkedList<byte> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new LinkedList<byte>(readByteSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of byte values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted byte sequence as a queue.</param>
+ public void readByteSeq(out Queue<byte> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue is faster than constructing the queue
+ // and adding to it one element at a time.
+ //
+ l = new Queue<byte>(readByteSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of byte values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted byte sequence as a stack.</param>
+ public void readByteSeq(out Stack<byte> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ byte[] array = readByteSeq();
+ Array.Reverse(array);
+ l = new Stack<byte>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional byte sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<byte[]> readByteSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ return new Ice.Optional<byte[]>(readByteSeq());
+ }
+ else
+ {
+ return new Ice.Optional<byte[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional byte sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readByteSeq(int tag, out bool isset, out byte[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ v = readByteSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a serializable object from the stream.
+ /// </summary>
+ /// <returns>The serializable object.</returns>
+ public object readSerializable()
+ {
+#if !COMPACT && !SILVERLIGHT
+ int sz = readAndCheckSeqSize(1);
+ if(sz == 0)
+ {
+ return null;
+ }
+ try
+ {
+ IceInternal.InputStreamWrapper w = new IceInternal.InputStreamWrapper(sz, this);
+ IFormatter f = new BinaryFormatter();
+ return f.Deserialize(w);
+ }
+ catch(System.Exception ex)
+ {
+ throw new Ice.MarshalException("cannot deserialize object:", ex);
+ }
+#else
+ throw new Ice.MarshalException("serialization not supported");
+#endif
+ }
+
+ /// <summary>
+ /// Extracts a boolean value from the stream.
+ /// </summary>
+ /// <returns>The extracted boolean.</returns>
+ public bool readBool()
+ {
+ try
+ {
+ return _buf.b.get() == 1;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional boolean value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<bool> readBool(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F1))
+ {
+ return new Ice.Optional<bool>(readBool());
+ }
+ else
+ {
+ return new Ice.Optional<bool>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional boolean value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readBool(int tag, out bool isset, out bool v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F1))
+ {
+ v = readBool();
+ }
+ else
+ {
+ v = false;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of boolean values from the stream.
+ /// </summary>
+ /// <returns>The extracted boolean sequence.</returns>
+ public bool[] readBoolSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(1);
+ bool[] v = new bool[sz];
+ _buf.b.getBoolSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of boolean values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted boolean sequence as a list.</param>
+ public void readBoolSeq(out List<bool> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<bool>(readBoolSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of boolean values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted boolean sequence as a linked list.</param>
+ public void readBoolSeq(out LinkedList<bool> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new LinkedList<bool>(readBoolSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of boolean values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted boolean sequence as a queue.</param>
+ public void readBoolSeq(out Queue<bool> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue is faster than constructing the queue
+ // and adding to it one element at a time.
+ //
+ l = new Queue<bool>(readBoolSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of boolean values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted boolean sequence as a stack.</param>
+ public void readBoolSeq(out Stack<bool> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ bool[] array = readBoolSeq();
+ Array.Reverse(array);
+ l = new Stack<bool>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional boolean sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<bool[]> readBoolSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ return new Ice.Optional<bool[]>(readBoolSeq());
+ }
+ else
+ {
+ return new Ice.Optional<bool[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional boolean sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readBoolSeq(int tag, out bool isset, out bool[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ v = readBoolSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a short value from the stream.
+ /// </summary>
+ /// <returns>The extracted short.</returns>
+ public short readShort()
+ {
+ try
+ {
+ return _buf.b.getShort();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional short value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<short> readShort(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F2))
+ {
+ return new Ice.Optional<short>(readShort());
+ }
+ else
+ {
+ return new Ice.Optional<short>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional short value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readShort(int tag, out bool isset, out short v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F2))
+ {
+ v = readShort();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of short values from the stream.
+ /// </summary>
+ /// <returns>The extracted short sequence.</returns>
+ public short[] readShortSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(2);
+ short[] v = new short[sz];
+ _buf.b.getShortSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of short values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted short sequence as a list.</param>
+ public void readShortSeq(out List<short> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<short>(readShortSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of short values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted short sequence as a linked list.</param>
+ public void readShortSeq(out LinkedList<short> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new LinkedList<short>(readShortSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of short values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted short sequence as a queue.</param>
+ public void readShortSeq(out Queue<short> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue is faster than constructing the queue
+ // and adding to it one element at a time.
+ //
+ l = new Queue<short>(readShortSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of short values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted short sequence as a stack.</param>
+ public void readShortSeq(out Stack<short> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ short[] array = readShortSeq();
+ Array.Reverse(array);
+ l = new Stack<short>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional short sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<short[]> readShortSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ return new Ice.Optional<short[]>(readShortSeq());
+ }
+ else
+ {
+ return new Ice.Optional<short[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional short sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readShortSeq(int tag, out bool isset, out short[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ v = readShortSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts an int value from the stream.
+ /// </summary>
+ /// <returns>The extracted int.</returns>
+ public int readInt()
+ {
+ try
+ {
+ return _buf.b.getInt();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional int value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<int> readInt(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F4))
+ {
+ return new Ice.Optional<int>(readInt());
+ }
+ else
+ {
+ return new Ice.Optional<int>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional int value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readInt(int tag, out bool isset, out int v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F4))
+ {
+ v = readInt();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of int values from the stream.
+ /// </summary>
+ /// <returns>The extracted int sequence.</returns>
+ public int[] readIntSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ int[] v = new int[sz];
+ _buf.b.getIntSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of int values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted int sequence as a list.</param>
+ public void readIntSeq(out List<int> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<int>(readIntSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of int values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted int sequence as a linked list.</param>
+ public void readIntSeq(out LinkedList<int> l)
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new LinkedList<int>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.AddLast(_buf.b.getInt());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of int values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted int sequence as a queue.</param>
+ public void readIntSeq(out Queue<int> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue takes the same time as constructing the queue
+ // and adding to it one element at a time, so
+ // we avoid the copy.
+ //
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new Queue<int>(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Enqueue(_buf.b.getInt());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of int values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted int sequence as a stack.</param>
+ public void readIntSeq(out Stack<int> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ int[] array = readIntSeq();
+ Array.Reverse(array);
+ l = new Stack<int>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional int sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<int[]> readIntSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ return new Ice.Optional<int[]>(readIntSeq());
+ }
+ else
+ {
+ return new Ice.Optional<int[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional int sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readIntSeq(int tag, out bool isset, out int[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ v = readIntSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a long value from the stream.
+ /// </summary>
+ /// <returns>The extracted long.</returns>
+ public long readLong()
+ {
+ try
+ {
+ return _buf.b.getLong();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional long value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<long> readLong(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F8))
+ {
+ return new Ice.Optional<long>(readLong());
+ }
+ else
+ {
+ return new Ice.Optional<long>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional long value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readLong(int tag, out bool isset, out long v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F8))
+ {
+ v = readLong();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of long values from the stream.
+ /// </summary>
+ /// <returns>The extracted long sequence.</returns>
+ public long[] readLongSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(8);
+ long[] v = new long[sz];
+ _buf.b.getLongSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of long values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted long sequence as a list.</param>
+ public void readLongSeq(out List<long> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<long>(readLongSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of long values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted long sequence as a linked list.</param>
+ public void readLongSeq(out LinkedList<long> l)
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new LinkedList<long>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.AddLast(_buf.b.getLong());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of long values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted long sequence as a queue.</param>
+ public void readLongSeq(out Queue<long> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue takes the same time as constructing the queue
+ // and adding to it one element at a time, so
+ // we avoid the copy.
+ //
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new Queue<long>(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Enqueue(_buf.b.getLong());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of long values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted long sequence as a stack.</param>
+ public void readLongSeq(out Stack<long> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ long[] array = readLongSeq();
+ Array.Reverse(array);
+ l = new Stack<long>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional long sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<long[]> readLongSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ return new Ice.Optional<long[]>(readLongSeq());
+ }
+ else
+ {
+ return new Ice.Optional<long[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional long sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readLongSeq(int tag, out bool isset, out long[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ v = readLongSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a float value from the stream.
+ /// </summary>
+ /// <returns>The extracted float.</returns>
+ public float readFloat()
+ {
+ try
+ {
+ return _buf.b.getFloat();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional float value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<float> readFloat(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F4))
+ {
+ return new Ice.Optional<float>(readFloat());
+ }
+ else
+ {
+ return new Ice.Optional<float>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional float value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readFloat(int tag, out bool isset, out float v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F4))
+ {
+ v = readFloat();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of float values from the stream.
+ /// </summary>
+ /// <returns>The extracted float sequence.</returns>
+ public float[] readFloatSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ float[] v = new float[sz];
+ _buf.b.getFloatSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of float values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted float sequence as a list.</param>
+ public void readFloatSeq(out List<float> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<float>(readFloatSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of float values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted float sequence as a linked list.</param>
+ public void readFloatSeq(out LinkedList<float> l)
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new LinkedList<float>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.AddLast(_buf.b.getFloat());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of float values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted float sequence as a queue.</param>
+ public void readFloatSeq(out Queue<float> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue takes the same time as constructing the queue
+ // and adding to it one element at a time, so
+ // we avoid the copy.
+ //
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new Queue<float>(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Enqueue(_buf.b.getFloat());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of float values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted float sequence as a stack.</param>
+ public void readFloatSeq(out Stack<float> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ float[] array = readFloatSeq();
+ Array.Reverse(array);
+ l = new Stack<float>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional float sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<float[]> readFloatSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ return new Ice.Optional<float[]>(readFloatSeq());
+ }
+ else
+ {
+ return new Ice.Optional<float[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional float sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readFloatSeq(int tag, out bool isset, out float[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ v = readFloatSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a double value from the stream.
+ /// </summary>
+ /// <returns>The extracted double.</returns>
+ public double readDouble()
+ {
+ try
+ {
+ return _buf.b.getDouble();
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional double value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<double> readDouble(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.F8))
+ {
+ return new Ice.Optional<double>(readDouble());
+ }
+ else
+ {
+ return new Ice.Optional<double>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional double value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readDouble(int tag, out bool isset, out double v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.F8))
+ {
+ v = readDouble();
+ }
+ else
+ {
+ v = 0;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of double values from the stream.
+ /// </summary>
+ /// <returns>The extracted double sequence.</returns>
+ public double[] readDoubleSeq()
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(8);
+ double[] v = new double[sz];
+ _buf.b.getDoubleSeq(v);
+ return v;
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of double values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted double sequence as a list.</param>
+ public void readDoubleSeq(out List<double> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is faster than constructing the list
+ // and adding to it one element at a time.
+ //
+ l = new List<double>(readDoubleSeq());
+ }
+
+ /// <summary>
+ /// Extracts a sequence of double values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted double sequence as a linked list.</param>
+ public void readDoubleSeq(out LinkedList<double> l)
+ {
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new LinkedList<double>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.AddLast(_buf.b.getDouble());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of double values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted double sequence as a queue.</param>
+ public void readDoubleSeq(out Queue<double> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue takes the same time as constructing the queue
+ // and adding to it one element at a time, so
+ // we avoid the copy.
+ //
+ try
+ {
+ int sz = readAndCheckSeqSize(4);
+ l = new Queue<double>(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Enqueue(_buf.b.getDouble());
+ }
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of double values from the stream.
+ /// </summary>
+ /// <param name="l">The extracted double sequence as a stack.</param>
+ public void readDoubleSeq(out Stack<double> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ double[] array = readDoubleSeq();
+ Array.Reverse(array);
+ l = new Stack<double>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional double sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<double[]> readDoubleSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ return new Ice.Optional<double[]>(readDoubleSeq());
+ }
+ else
+ {
+ return new Ice.Optional<double[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional double sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readDoubleSeq(int tag, out bool isset, out double[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ skipSize();
+ v = readDoubleSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ private static System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding(false, true);
+
+ /// <summary>
+ /// Extracts a string from the stream.
+ /// </summary>
+ /// <returns>The extracted string.</returns>
+ public string readString()
+ {
+ int len = readSize();
+
+ if(len == 0)
+ {
+ return "";
+ }
+
+ //
+ // Check the buffer has enough bytes to read.
+ //
+ if(_buf.b.remaining() < len)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+
+ try
+ {
+ //
+ // We reuse the _stringBytes array to avoid creating
+ // excessive garbage
+ //
+ if(_stringBytes == null || len > _stringBytes.Length)
+ {
+ _stringBytes = new byte[len];
+ }
+ _buf.b.get(_stringBytes, 0, len);
+ return utf8.GetString(_stringBytes, 0, len);
+ }
+ catch(InvalidOperationException ex)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException(ex);
+ }
+ catch(System.ArgumentException ex)
+ {
+ throw new Ice.MarshalException("Invalid UTF8 string", ex);
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional string from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<string> readString(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ return new Ice.Optional<string>(readString());
+ }
+ else
+ {
+ return new Ice.Optional<string>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional string from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readString(int tag, out bool isset, out string v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ v = readString();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of strings from the stream.
+ /// </summary>
+ /// <returns>The extracted string sequence.</returns>
+ public string[] readStringSeq()
+ {
+ int sz = readAndCheckSeqSize(1);
+ string[] v = new string[sz];
+ for(int i = 0; i < sz; i++)
+ {
+ v[i] = readString();
+ }
+ return v;
+ }
+
+ /// <summary>
+ /// Extracts a sequence of strings from the stream.
+ /// </summary>
+ /// <param name="l">The extracted string sequence as a list.</param>
+ public void readStringSeq(out List<string> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is slower than constructing the list
+ // and adding to it one element at a time.
+ //
+ int sz = readAndCheckSeqSize(1);
+ l = new List<string>(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Add(readString());
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of strings from the stream.
+ /// </summary>
+ /// <param name="l">The extracted string sequence as a linked list.</param>
+ public void readStringSeq(out LinkedList<string> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // list is slower than constructing the list
+ // and adding to it one element at a time.
+ //
+ int sz = readAndCheckSeqSize(1);
+ l = new LinkedList<string>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.AddLast(readString());
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of strings from the stream.
+ /// </summary>
+ /// <param name="l">The extracted string sequence as a queue.</param>
+ public void readStringSeq(out Queue<string> l)
+ {
+ //
+ // Reading into an array and copy-constructing the
+ // queue is slower than constructing the queue
+ // and adding to it one element at a time.
+ //
+ int sz = readAndCheckSeqSize(1);
+ l = new Queue<string>();
+ for(int i = 0; i < sz; ++i)
+ {
+ l.Enqueue(readString());
+ }
+ }
+
+ /// <summary>
+ /// Extracts a sequence of strings from the stream.
+ /// </summary>
+ /// <param name="l">The extracted string sequence as a stack.</param>
+ public void readStringSeq(out Stack<string> l)
+ {
+ //
+ // Reverse the contents by copying into an array first
+ // because the stack is marshaled in top-to-bottom order.
+ //
+ string[] array = readStringSeq();
+ Array.Reverse(array);
+ l = new Stack<string>(array);
+ }
+
+ /// <summary>
+ /// Extracts an optional string sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<string[]> readStringSeq(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ skip(4);
+ return new Ice.Optional<string[]>(readStringSeq());
+ }
+ else
+ {
+ return new Ice.Optional<string[]>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional string sequence from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readStringSeq(int tag, out bool isset, out string[] v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ skip(4);
+ v = readStringSeq();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Extracts a proxy from the stream. The stream must have been initialized with a communicator.
+ /// </summary>
+ /// <returns>The extracted proxy.</returns>
+ public Ice.ObjectPrx readProxy()
+ {
+ return instance_.proxyFactory().streamToProxy(this);
+ }
+
+ /// <summary>
+ /// Extracts an optional proxy from the stream. The stream must have been initialized with a communicator.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <returns>The optional value.</returns>
+ public Ice.Optional<Ice.ObjectPrx> readProxy(int tag)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ skip(4);
+ return new Ice.Optional<Ice.ObjectPrx>(readProxy());
+ }
+ else
+ {
+ return new Ice.Optional<Ice.ObjectPrx>();
+ }
+ }
+
+ /// <summary>
+ /// Extracts an optional proxy from the stream. The stream must have been initialized with a communicator.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="isset">True if the optional value is present, false otherwise.</param>
+ /// <param name="v">The optional value.</param>
+ public void readProxy(int tag, out bool isset, out Ice.ObjectPrx v)
+ {
+ if(isset = readOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ skip(4);
+ v = readProxy();
+ }
+ else
+ {
+ v = null;
+ }
+ }
+
+ /// <summary>
+ /// Read an enumerated value.
+ /// </summary>
+ /// <param name="maxValue">The maximum enumerator value in the definition.</param>
+ /// <returns>The enumerator.</returns>
+ public int readEnum(int maxValue)
+ {
+ if(getEncoding().Equals(Ice.Util.Encoding_1_0))
+ {
+ if(maxValue < 127)
+ {
+ return readByte();
+ }
+ else if(maxValue < 32767)
+ {
+ return readShort();
+ }
+ else
+ {
+ return readInt();
+ }
+ }
+ else
+ {
+ return readSize();
+ }
+ }
+
+ /// <summary>
+ /// Extracts the index of a Slice value from the stream.
+ /// </summary>
+ /// <param name="cb">The callback to notify the application when the extracted instance is available.
+ /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
+ /// corresponding instance has been fully unmarshaled.</param>
+ public void readObject(ReadObjectCallback cb)
+ {
+ initEncaps();
+ _encapsStack.decoder.readObject(cb);
+ }
+
+ /// <summary>
+ /// Extracts the index of an optional Slice value from the stream.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="cb">The callback to notify the application when the extracted instance is available (if any).
+ /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
+ /// corresponding instance has been fully unmarshaled.</param>
+ public void readObject(int tag, ReadObjectCallback cb)
+ {
+ if(readOptional(tag, Ice.OptionalFormat.Class))
+ {
+ readObject(cb);
+ }
+ }
+
+ /// <summary>
+ /// Extracts a user exception from the stream and throws it.
+ /// </summary>
+ public void throwException()
+ {
+ throwException(null);
+ }
+
+ /// <summary>
+ /// Extracts a user exception from the stream and throws it.
+ /// </summary>
+ /// <param name="factory">The user exception factory, or null to use the stream's default behavior.</param>
+ public void throwException(UserExceptionFactory factory)
+ {
+ initEncaps();
+ _encapsStack.decoder.throwException(factory);
+ }
+
+ /// <summary>
+ /// Skip the given number of bytes.
+ /// </summary>
+ /// <param name="size">The number of bytes to skip</param>
+ public void skip(int size)
+ {
+ if(size < 0 || size > _buf.b.remaining())
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+ _buf.b.position(_buf.b.position() + size);
+ }
+
+ /// <summary>
+ /// Skip over a size value.
+ /// </summary>
+ public void skipSize()
+ {
+ byte b = readByte();
+ if(b == 255)
+ {
+ skip(4);
+ }
+ }
+
+ /// <summary>
+ /// Determines the current position in the stream.
+ /// </summary>
+ /// <returns>The current position.</returns>
+ public int pos()
+ {
+ return _buf.b.position();
+ }
+
+ /// <summary>
+ /// Sets the current position in the stream.
+ /// </summary>
+ /// <param name="n">The new position.</param>
+ public void pos(int n)
+ {
+ _buf.b.position(n);
+ }
+
+ /// <summary>
+ /// Determines the current size of the stream.
+ /// </summary>
+ /// <returns>The current size.</returns>
+ public int size()
+ {
+ return _buf.size();
+ }
+
+ /// <summary>
+ /// Determines whether the stream is empty.
+ /// </summary>
+ /// <returns>True if the internal buffer has no data, false otherwise.</returns>
+ public bool isEmpty()
+ {
+ return _buf.empty();
+ }
+
+ private bool readOptImpl(int readTag, Ice.OptionalFormat expectedFormat)
+ {
+ if(isEncoding_1_0())
+ {
+ return false; // Optional members aren't supported with the 1.0 encoding.
+ }
+
+ while(true)
+ {
+ if(_buf.b.position() >= _encapsStack.start + _encapsStack.sz)
+ {
+ return false; // End of encapsulation also indicates end of optionals.
+ }
+
+ int v = readByte();
+ if(v == Protocol.OPTIONAL_END_MARKER)
+ {
+ _buf.b.position(_buf.b.position() - 1); // Rewind.
+ return false;
+ }
+
+ Ice.OptionalFormat format = (Ice.OptionalFormat)(v & 0x07); // First 3 bits.
+ int tag = v >> 3;
+ if(tag == 30)
+ {
+ tag = readSize();
+ }
+
+ if(tag > readTag)
+ {
+ int offset = tag < 30 ? 1 : (tag < 255 ? 2 : 6); // Rewind
+ _buf.b.position(_buf.b.position() - offset);
+ return false; // No optional data members with the requested tag.
+ }
+ else if(tag < readTag)
+ {
+ skipOptional(format); // Skip optional data members
+ }
+ else
+ {
+ if(format != expectedFormat)
+ {
+ throw new Ice.MarshalException("invalid optional data member `" + tag + "': unexpected format");
+ }
+ return true;
+ }
+ }
+ }
+
+ private void skipOptional(Ice.OptionalFormat format)
+ {
+ switch(format)
+ {
+ case Ice.OptionalFormat.F1:
+ {
+ skip(1);
+ break;
+ }
+ case Ice.OptionalFormat.F2:
+ {
+ skip(2);
+ break;
+ }
+ case Ice.OptionalFormat.F4:
+ {
+ skip(4);
+ break;
+ }
+ case Ice.OptionalFormat.F8:
+ {
+ skip(8);
+ break;
+ }
+ case Ice.OptionalFormat.Size:
+ {
+ skipSize();
+ break;
+ }
+ case Ice.OptionalFormat.VSize:
+ {
+ skip(readSize());
+ break;
+ }
+ case Ice.OptionalFormat.FSize:
+ {
+ skip(readInt());
+ break;
+ }
+ case Ice.OptionalFormat.Class:
+ {
+ readObject(null);
+ break;
+ }
+ }
+ }
+
+ private bool skipOptionals()
+ {
+ //
+ // Skip remaining un-read optional members.
+ //
+ while(true)
+ {
+ if(_buf.b.position() >= _encapsStack.start + _encapsStack.sz)
+ {
+ return false; // End of encapsulation also indicates end of optionals.
+ }
+
+ int v = readByte();
+ if(v == Protocol.OPTIONAL_END_MARKER)
+ {
+ return true;
+ }
+
+ Ice.OptionalFormat format = (Ice.OptionalFormat)(v & 0x07); // Read first 3 bits.
+ if((v >> 3) == 30)
+ {
+ skipSize();
+ }
+ skipOptional(format);
+ }
+ }
+
+ private Ice.UserException createUserException(string id)
+ {
+ Ice.UserException userEx = null;
+
+ try
+ {
+ if(_classResolver != null)
+ {
+ Type c = _classResolver(id);
+ if(c != null)
+ {
+ Debug.Assert(!c.IsAbstract && !c.IsInterface);
+ userEx = (Ice.UserException)IceInternal.AssemblyUtil.createInstance(c);
+ }
+ }
+ }
+ catch(Exception ex)
+ {
+ throw new Ice.MarshalException(ex);
+ }
+
+ return userEx;
+ }
+
+ private IceInternal.Instance instance_;
+ private IceInternal.Buffer _buf;
+ private object _closure;
+ private byte[] _stringBytes; // Reusable array for reading strings.
+
+ private enum SliceType { NoSlice, ObjectSlice, ExceptionSlice }
+
+ abstract private class EncapsDecoder
+ {
+ internal EncapsDecoder(InputStream stream, Encaps encaps, bool sliceObjects, ValueFactoryManager f,
+ ClassResolver cr)
+ {
+ _stream = stream;
+ _encaps = encaps;
+ _sliceObjects = sliceObjects;
+ _valueFactoryManager = f;
+ _classResolver = cr;
+ _typeIdIndex = 0;
+ _unmarshaledMap = new Dictionary<int, Ice.Object>();
+ }
+
+ internal abstract void readObject(ReadObjectCallback cb);
+ internal abstract void throwException(UserExceptionFactory factory);
+
+ internal abstract void startInstance(SliceType type);
+ internal abstract Ice.SlicedData endInstance(bool preserve);
+ internal abstract string startSlice();
+ internal abstract void endSlice();
+ internal abstract void skipSlice();
+
+ internal virtual bool readOptional(int tag, Ice.OptionalFormat format)
+ {
+ return false;
+ }
+
+ internal virtual void readPendingObjects()
+ {
+ }
+
+ protected string readTypeId(bool isIndex)
+ {
+ if(_typeIdMap == null)
+ {
+ _typeIdMap = new Dictionary<int, string>();
+ }
+
+ if(isIndex)
+ {
+ int index = _stream.readSize();
+ string typeId;
+ if(!_typeIdMap.TryGetValue(index, out typeId))
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+ return typeId;
+ }
+ else
+ {
+ string typeId = _stream.readString();
+ _typeIdMap.Add(++_typeIdIndex, typeId);
+ return typeId;
+ }
+ }
+
+ protected Type resolveClass(string typeId)
+ {
+ Type cls = null;
+ if(_typeIdCache == null)
+ {
+ _typeIdCache = new Dictionary<string, Type>(); // Lazy initialization.
+ }
+ else
+ {
+ _typeIdCache.TryGetValue(typeId, out cls);
+ }
+
+ if(cls == typeof(EncapsDecoder)) // Marker for non-existent class.
+ {
+ cls = null;
+ }
+ else if(cls == null)
+ {
+ try
+ {
+ if(_classResolver != null)
+ {
+ cls = _classResolver(typeId);
+ _typeIdCache.Add(typeId, cls != null ? cls : typeof(EncapsDecoder));
+ }
+ }
+ catch(Exception ex)
+ {
+ throw new NoValueFactoryException("no value factory", typeId, ex);
+ }
+ }
+
+ return cls;
+ }
+
+ protected Ice.Object newInstance(string typeId)
+ {
+ //
+ // Try to find a factory registered for the specific type.
+ //
+ ValueFactory userFactory = _valueFactoryManager.find(typeId);
+ Ice.Object v = null;
+ if(userFactory != null)
+ {
+ v = userFactory(typeId);
+ }
+
+ //
+ // If that fails, invoke the default factory if one has been
+ // registered.
+ //
+ if(v == null)
+ {
+ userFactory = _valueFactoryManager.find("");
+ if(userFactory != null)
+ {
+ v = userFactory(typeId);
+ }
+ }
+
+ //
+ // Last chance: try to instantiate the class dynamically.
+ //
+ if(v == null)
+ {
+ Type cls = resolveClass(typeId);
+
+ if(cls != null)
+ {
+ try
+ {
+ Debug.Assert(!cls.IsAbstract && !cls.IsInterface);
+ v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls);
+ }
+ catch(Exception ex)
+ {
+ throw new NoValueFactoryException("no value factory", typeId, ex);
+ }
+ }
+ }
+
+ return v;
+ }
+
+ protected void addPatchEntry(int index, ReadObjectCallback cb)
+ {
+ Debug.Assert(index > 0);
+
+ //
+ // Check if already un-marshalled the object. If that's the case,
+ // just patch the object smart pointer and we're done.
+ //
+ Ice.Object obj;
+ if(_unmarshaledMap.TryGetValue(index, out obj))
+ {
+ cb(obj);
+ return;
+ }
+
+ if(_patchMap == null)
+ {
+ _patchMap = new Dictionary<int, LinkedList<ReadObjectCallback>>();
+ }
+
+ //
+ // Add patch entry if the object isn't un-marshalled yet,
+ // the smart pointer will be patched when the instance is
+ // un-marshalled.
+ //
+ LinkedList<ReadObjectCallback> l;
+ if(!_patchMap.TryGetValue(index, out l))
+ {
+ //
+ // We have no outstanding instances to be patched for this
+ // index, so make a new entry in the patch map.
+ //
+ l = new LinkedList<ReadObjectCallback>();
+ _patchMap.Add(index, l);
+ }
+
+ //
+ // Append a patch entry for this instance.
+ //
+ l.AddLast(cb);
+ }
+
+ protected void unmarshal(int index, Ice.Object v)
+ {
+ //
+ // Add the object to the map of un-marshalled objects, this must
+ // be done before reading the objects (for circular references).
+ //
+ _unmarshaledMap.Add(index, v);
+
+ //
+ // Read the object.
+ //
+ v.read__(_stream);
+
+ if(_patchMap != null)
+ {
+ //
+ // Patch all instances now that the object is un-marshalled.
+ //
+ LinkedList<ReadObjectCallback> l;
+ if(_patchMap.TryGetValue(index, out l))
+ {
+ Debug.Assert(l.Count > 0);
+
+ //
+ // Patch all pointers that refer to the instance.
+ //
+ foreach(ReadObjectCallback cb in l)
+ {
+ cb(v);
+ }
+
+ //
+ // Clear out the patch map for that index -- there is nothing left
+ // to patch for that index for the time being.
+ //
+ _patchMap.Remove(index);
+ }
+ }
+
+ if((_patchMap == null || _patchMap.Count == 0) && _objectList == null)
+ {
+ try
+ {
+ v.ice_postUnmarshal();
+ }
+ catch(System.Exception ex)
+ {
+ string s = "exception raised by ice_postUnmarshal:\n" + ex;
+ _stream.instance().initializationData().logger.warning(s);
+ }
+ }
+ else
+ {
+ if(_objectList == null)
+ {
+ _objectList = new List<Ice.Object>();
+ }
+ _objectList.Add(v);
+
+ if(_patchMap == null || _patchMap.Count == 0)
+ {
+ //
+ // Iterate over the object list and invoke ice_postUnmarshal on
+ // each object. We must do this after all objects have been
+ // unmarshaled in order to ensure that any object data members
+ // have been properly patched.
+ //
+ foreach(Ice.Object p in _objectList)
+ {
+ try
+ {
+ p.ice_postUnmarshal();
+ }
+ catch(System.Exception ex)
+ {
+ string s = "exception raised by ice_postUnmarshal:\n" + ex;
+ _stream.instance().initializationData().logger.warning(s);
+ }
+ }
+ _objectList.Clear();
+ }
+ }
+ }
+
+ protected readonly InputStream _stream;
+ protected readonly Encaps _encaps;
+ protected readonly bool _sliceObjects;
+ protected ValueFactoryManager _valueFactoryManager;
+ protected ClassResolver _classResolver;
+
+ //
+ // Encapsulation attributes for object unmarshaling.
+ //
+ protected Dictionary<int, LinkedList<ReadObjectCallback> > _patchMap;
+ private Dictionary<int, Ice.Object> _unmarshaledMap;
+ private Dictionary<int, string> _typeIdMap;
+ private int _typeIdIndex;
+ private List<Ice.Object> _objectList;
+ private Dictionary<string, Type> _typeIdCache;
+ }
+
+ private sealed class EncapsDecoder10 : EncapsDecoder
+ {
+ internal EncapsDecoder10(InputStream stream, Encaps encaps, bool sliceObjects, ValueFactoryManager f,
+ ClassResolver cr)
+ : base(stream, encaps, sliceObjects, f, cr)
+ {
+ _sliceType = SliceType.NoSlice;
+ }
+
+ internal override void readObject(ReadObjectCallback cb)
+ {
+ Debug.Assert(cb != null);
+
+ //
+ // Object references are encoded as a negative integer in 1.0.
+ //
+ int index = _stream.readInt();
+ if(index > 0)
+ {
+ throw new Ice.MarshalException("invalid object id");
+ }
+ index = -index;
+
+ if(index == 0)
+ {
+ cb(null);
+ }
+ else
+ {
+ addPatchEntry(index, cb);
+ }
+ }
+
+ internal override void throwException(UserExceptionFactory factory)
+ {
+ Debug.Assert(_sliceType == SliceType.NoSlice);
+
+ //
+ // User exception with the 1.0 encoding start with a bool flag
+ // that indicates whether or not the exception has classes.
+ //
+ // This allows reading the pending objects even if some part of
+ // the exception was sliced.
+ //
+ bool usesClasses = _stream.readBool();
+
+ _sliceType = SliceType.ExceptionSlice;
+ _skipFirstSlice = false;
+
+ //
+ // Read the first slice header.
+ //
+ startSlice();
+ string mostDerivedId = _typeId;
+ while(true)
+ {
+ Ice.UserException userEx = null;
+
+ //
+ // Use a factory if one was provided.
+ //
+ if(factory != null)
+ {
+ try
+ {
+ factory(_typeId);
+ }
+ catch(Ice.UserException ex)
+ {
+ userEx = ex;
+ }
+ }
+
+ if(userEx == null)
+ {
+ userEx = _stream.createUserException(_typeId);
+ }
+
+ //
+ // We found the exception.
+ //
+ if(userEx != null)
+ {
+ userEx.read__(_stream);
+ if(usesClasses)
+ {
+ readPendingObjects();
+ }
+ throw userEx;
+
+ // Never reached.
+ }
+
+ //
+ // Slice off what we don't understand.
+ //
+ skipSlice();
+ try
+ {
+ startSlice();
+ }
+ catch(Ice.UnmarshalOutOfBoundsException ex)
+ {
+ //
+ // An oversight in the 1.0 encoding means there is no marker to indicate
+ // the last slice of an exception. As a result, we just try to read the
+ // next type ID, which raises UnmarshalOutOfBoundsException when the
+ // input buffer underflows.
+ //
+ // Set the reason member to a more helpful message.
+ //
+ ex.reason = "unknown exception type `" + mostDerivedId + "'";
+ throw ex;
+ }
+ }
+ }
+
+ internal override void startInstance(SliceType sliceType)
+ {
+ Debug.Assert(_sliceType == sliceType);
+ _skipFirstSlice = true;
+ }
+
+ internal override Ice.SlicedData endInstance(bool preserve)
+ {
+ //
+ // Read the Ice::Object slice.
+ //
+ if(_sliceType == SliceType.ObjectSlice)
+ {
+ startSlice();
+ int sz = _stream.readSize(); // For compatibility with the old AFM.
+ if(sz != 0)
+ {
+ throw new Ice.MarshalException("invalid Object slice");
+ }
+ endSlice();
+ }
+
+ _sliceType = SliceType.NoSlice;
+ return null;
+ }
+
+ internal override string startSlice()
+ {
+ //
+ // If first slice, don't read the header, it was already read in
+ // readInstance or throwException to find the factory.
+ //
+ if(_skipFirstSlice)
+ {
+ _skipFirstSlice = false;
+ return _typeId;
+ }
+
+ //
+ // For objects, first read the type ID bool which indicates
+ // whether or not the type ID is encoded as a string or as an
+ // index. For exceptions, the type ID is always encoded as a
+ // string.
+ //
+ if(_sliceType == SliceType.ObjectSlice) // For exceptions, the type ID is always encoded as a string
+ {
+ bool isIndex = _stream.readBool();
+ _typeId = readTypeId(isIndex);
+ }
+ else
+ {
+ _typeId = _stream.readString();
+ }
+
+ _sliceSize = _stream.readInt();
+ if(_sliceSize < 4)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+
+ return _typeId;
+ }
+
+ internal override void endSlice()
+ {
+ }
+
+ internal override void skipSlice()
+ {
+ if(_stream.instance().traceLevels().slicing > 0)
+ {
+ Ice.Logger logger = _stream.instance().initializationData().logger;
+ string slicingCat = _stream.instance().traceLevels().slicingCat;
+ if(_sliceType == SliceType.ObjectSlice)
+ {
+ IceInternal.TraceUtil.traceSlicing("object", _typeId, slicingCat, logger);
+ }
+ else
+ {
+ IceInternal.TraceUtil.traceSlicing("exception", _typeId, slicingCat, logger);
+ }
+ }
+
+ Debug.Assert(_sliceSize >= 4);
+ _stream.skip(_sliceSize - 4);
+ }
+
+ internal override void readPendingObjects()
+ {
+ int num;
+ do
+ {
+ num = _stream.readSize();
+ for(int k = num; k > 0; --k)
+ {
+ readInstance();
+ }
+ }
+ while(num > 0);
+
+ if(_patchMap != null && _patchMap.Count > 0)
+ {
+ //
+ // If any entries remain in the patch map, the sender has sent an index for an object, but failed
+ // to supply the object.
+ //
+ throw new Ice.MarshalException("index for class received, but no instance");
+ }
+ }
+
+ private void readInstance()
+ {
+ int index = _stream.readInt();
+
+ if(index <= 0)
+ {
+ throw new Ice.MarshalException("invalid object id");
+ }
+
+ _sliceType = SliceType.ObjectSlice;
+ _skipFirstSlice = false;
+
+ //
+ // Read the first slice header.
+ //
+ startSlice();
+ string mostDerivedId = _typeId;
+ Ice.Object v = null;
+ while(true)
+ {
+ //
+ // For the 1.0 encoding, the type ID for the base Object class
+ // marks the last slice.
+ //
+ if(_typeId.Equals(Ice.ObjectImpl.ice_staticId()))
+ {
+ throw new NoValueFactoryException("", mostDerivedId);
+ }
+
+ v = newInstance(_typeId);
+
+ //
+ // We found a factory, we get out of this loop.
+ //
+ if(v != null)
+ {
+ break;
+ }
+
+ //
+ // If object slicing is disabled, stop un-marshalling.
+ //
+ if(!_sliceObjects)
+ {
+ throw new NoValueFactoryException("no value factory found and object slicing is disabled",
+ _typeId);
+ }
+
+ //
+ // Slice off what we don't understand.
+ //
+ skipSlice();
+ startSlice(); // Read next Slice header for next iteration.
+ }
+
+ //
+ // Un-marshal the object and add-it to the map of un-marshaled objects.
+ //
+ unmarshal(index, v);
+ }
+
+ // Object/exception attributes
+ private SliceType _sliceType;
+ private bool _skipFirstSlice;
+
+ // Slice attributes
+ private int _sliceSize;
+ private string _typeId;
+ }
+
+ private sealed class EncapsDecoder11 : EncapsDecoder
+ {
+ internal EncapsDecoder11(InputStream stream, Encaps encaps, bool sliceObjects, ValueFactoryManager f,
+ ClassResolver cr, CompactIdResolver r)
+ : base(stream, encaps, sliceObjects, f, cr)
+ {
+ _compactIdResolver = r;
+ _current = null;
+ _objectIdIndex = 1;
+ }
+
+ internal override void readObject(ReadObjectCallback cb)
+ {
+ int index = _stream.readSize();
+ if(index < 0)
+ {
+ throw new Ice.MarshalException("invalid object id");
+ }
+ else if(index == 0)
+ {
+ if(cb != null)
+ {
+ cb(null);
+ }
+ }
+ else if(_current != null && (_current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) != 0)
+ {
+ //
+ // When reading an object within a slice and there's an
+ // indirect object table, always read an indirect reference
+ // that points to an object from the indirect object table
+ // marshaled at the end of the Slice.
+ //
+ // Maintain a list of indirect references. Note that the
+ // indirect index starts at 1, so we decrement it by one to
+ // derive an index into the indirection table that we'll read
+ // at the end of the slice.
+ //
+ if(cb != null)
+ {
+ if(_current.indirectPatchList == null)
+ {
+ _current.indirectPatchList = new Stack<IndirectPatchEntry>();
+ }
+ IndirectPatchEntry e = new IndirectPatchEntry();
+ e.index = index - 1;
+ e.patcher = cb;
+ _current.indirectPatchList.Push(e);
+ }
+ }
+ else
+ {
+ readInstance(index, cb);
+ }
+ }
+
+ internal override void throwException(UserExceptionFactory factory)
+ {
+ Debug.Assert(_current == null);
+
+ push(SliceType.ExceptionSlice);
+
+ //
+ // Read the first slice header.
+ //
+ startSlice();
+ string mostDerivedId = _current.typeId;
+ while(true)
+ {
+ Ice.UserException userEx = null;
+
+ //
+ // Use a factory if one was provided.
+ //
+ if(factory != null)
+ {
+ try
+ {
+ factory(_current.typeId);
+ }
+ catch(Ice.UserException ex)
+ {
+ userEx = ex;
+ }
+ }
+
+ if(userEx == null)
+ {
+ userEx = _stream.createUserException(_current.typeId);
+ }
+
+ //
+ // We found the exception.
+ //
+ if(userEx != null)
+ {
+ userEx.read__(_stream);
+ throw userEx;
+
+ // Never reached.
+ }
+
+ //
+ // Slice off what we don't understand.
+ //
+ skipSlice();
+
+ if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0)
+ {
+ if(mostDerivedId.StartsWith("::", StringComparison.Ordinal))
+ {
+ throw new Ice.UnknownUserException(mostDerivedId.Substring(2));
+ }
+ else
+ {
+ throw new Ice.UnknownUserException(mostDerivedId);
+ }
+ }
+
+ startSlice();
+ }
+ }
+
+ internal override void startInstance(SliceType sliceType)
+ {
+ Debug.Assert(_current.sliceType == sliceType);
+ _current.skipFirstSlice = true;
+ }
+
+ internal override Ice.SlicedData endInstance(bool preserve)
+ {
+ Ice.SlicedData slicedData = null;
+ if(preserve)
+ {
+ slicedData = readSlicedData();
+ }
+ if(_current.slices != null)
+ {
+ _current.slices.Clear();
+ _current.indirectionTables.Clear();
+ }
+ _current = _current.previous;
+ return slicedData;
+ }
+
+ internal override string startSlice()
+ {
+ //
+ // If first slice, don't read the header, it was already read in
+ // readInstance or throwException to find the factory.
+ //
+ if(_current.skipFirstSlice)
+ {
+ _current.skipFirstSlice = false;
+ return _current.typeId;
+ }
+
+ _current.sliceFlags = _stream.readByte();
+
+ //
+ // Read the type ID, for object slices the type ID is encoded as a
+ // string or as an index, for exceptions it's always encoded as a
+ // string.
+ //
+ if(_current.sliceType == SliceType.ObjectSlice)
+ {
+ //
+ // Must be checked first!
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_TYPE_ID_COMPACT) == Protocol.FLAG_HAS_TYPE_ID_COMPACT)
+ {
+ _current.typeId = "";
+ _current.compactId = _stream.readSize();
+ }
+ else if((_current.sliceFlags &
+ (Protocol.FLAG_HAS_TYPE_ID_INDEX | Protocol.FLAG_HAS_TYPE_ID_STRING)) != 0)
+ {
+ _current.typeId = readTypeId((_current.sliceFlags & Protocol.FLAG_HAS_TYPE_ID_INDEX) != 0);
+ _current.compactId = -1;
+ }
+ else
+ {
+ // Only the most derived slice encodes the type ID for the compact format.
+ _current.typeId = "";
+ _current.compactId = -1;
+ }
+ }
+ else
+ {
+ _current.typeId = _stream.readString();
+ _current.compactId = -1;
+ }
+
+ //
+ // Read the slice size if necessary.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) != 0)
+ {
+ _current.sliceSize = _stream.readInt();
+ if(_current.sliceSize < 4)
+ {
+ throw new Ice.UnmarshalOutOfBoundsException();
+ }
+ }
+ else
+ {
+ _current.sliceSize = 0;
+ }
+
+ return _current.typeId;
+ }
+
+ internal override void endSlice()
+ {
+ if((_current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) != 0)
+ {
+ _stream.skipOptionals();
+ }
+
+ //
+ // Read the indirection table if one is present and transform the
+ // indirect patch list into patch entries with direct references.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) != 0)
+ {
+ //
+ // The table is written as a sequence<size> to conserve space.
+ //
+ int[] indirectionTable = new int[_stream.readAndCheckSeqSize(1)];
+ for(int i = 0; i < indirectionTable.Length; ++i)
+ {
+ indirectionTable[i] = readInstance(_stream.readSize(), null);
+ }
+
+ //
+ // Sanity checks. If there are optional members, it's possible
+ // that not all object references were read if they are from
+ // unknown optional data members.
+ //
+ if(indirectionTable.Length == 0)
+ {
+ throw new Ice.MarshalException("empty indirection table");
+ }
+ if((_current.indirectPatchList == null || _current.indirectPatchList.Count == 0) &&
+ (_current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) == 0)
+ {
+ throw new Ice.MarshalException("no references to indirection table");
+ }
+
+ //
+ // Convert indirect references into direct references.
+ //
+ if(_current.indirectPatchList != null)
+ {
+ foreach(IndirectPatchEntry e in _current.indirectPatchList)
+ {
+ Debug.Assert(e.index >= 0);
+ if(e.index >= indirectionTable.Length)
+ {
+ throw new Ice.MarshalException("indirection out of range");
+ }
+ addPatchEntry(indirectionTable[e.index], e.patcher);
+ }
+ _current.indirectPatchList.Clear();
+ }
+ }
+ }
+
+ internal override void skipSlice()
+ {
+ if(_stream.instance().traceLevels().slicing > 0)
+ {
+ Ice.Logger logger = _stream.instance().initializationData().logger;
+ string slicingCat = _stream.instance().traceLevels().slicingCat;
+ if(_current.sliceType == SliceType.ExceptionSlice)
+ {
+ IceInternal.TraceUtil.traceSlicing("exception", _current.typeId, slicingCat, logger);
+ }
+ else
+ {
+ IceInternal.TraceUtil.traceSlicing("object", _current.typeId, slicingCat, logger);
+ }
+ }
+
+ int start = _stream.pos();
+
+ if((_current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) != 0)
+ {
+ Debug.Assert(_current.sliceSize >= 4);
+ _stream.skip(_current.sliceSize - 4);
+ }
+ else
+ {
+ if(_current.sliceType == SliceType.ObjectSlice)
+ {
+ throw new NoValueFactoryException("no value factory found and compact format prevents " +
+ "slicing (the sender should use the sliced format " +
+ "instead)", _current.typeId);
+ }
+ else
+ {
+ if(_current.typeId.StartsWith("::", StringComparison.Ordinal))
+ {
+ throw new Ice.UnknownUserException(_current.typeId.Substring(2));
+ }
+ else
+ {
+ throw new Ice.UnknownUserException(_current.typeId);
+ }
+ }
+ }
+
+ //
+ // Preserve this slice.
+ //
+ Ice.SliceInfo info = new Ice.SliceInfo();
+ info.typeId = _current.typeId;
+ info.compactId = _current.compactId;
+ info.hasOptionalMembers = (_current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) != 0;
+ info.isLastSlice = (_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0;
+ IceInternal.ByteBuffer b = _stream.getBuffer().b;
+ int end = b.position();
+ int dataEnd = end;
+ if(info.hasOptionalMembers)
+ {
+ //
+ // Don't include the optional member end marker. It will be re-written by
+ // endSlice when the sliced data is re-written.
+ //
+ --dataEnd;
+ }
+ info.bytes = new byte[dataEnd - start];
+ b.position(start);
+ b.get(info.bytes);
+ b.position(end);
+
+ if(_current.slices == null)
+ {
+ _current.slices = new List<Ice.SliceInfo>();
+ _current.indirectionTables = new List<int[]>();
+ }
+
+ //
+ // Read the indirect object table. We read the instances or their
+ // IDs if the instance is a reference to an already un-marhsaled
+ // object.
+ //
+ // The SliceInfo object sequence is initialized only if
+ // readSlicedData is called.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) != 0)
+ {
+ int[] indirectionTable = new int[_stream.readAndCheckSeqSize(1)];
+ for(int i = 0; i < indirectionTable.Length; ++i)
+ {
+ indirectionTable[i] = readInstance(_stream.readSize(), null);
+ }
+ _current.indirectionTables.Add(indirectionTable);
+ }
+ else
+ {
+ _current.indirectionTables.Add(null);
+ }
+
+ _current.slices.Add(info);
+ }
+
+ internal override bool readOptional(int readTag, Ice.OptionalFormat expectedFormat)
+ {
+ if(_current == null)
+ {
+ return _stream.readOptImpl(readTag, expectedFormat);
+ }
+ else if((_current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) != 0)
+ {
+ return _stream.readOptImpl(readTag, expectedFormat);
+ }
+ return false;
+ }
+
+ private int readInstance(int index, ReadObjectCallback cb)
+ {
+ Debug.Assert(index > 0);
+
+ if(index > 1)
+ {
+ if(cb != null)
+ {
+ addPatchEntry(index, cb);
+ }
+ return index;
+ }
+
+ push(SliceType.ObjectSlice);
+
+ //
+ // Get the object ID before we start reading slices. If some
+ // slices are skiped, the indirect object table are still read and
+ // might read other objects.
+ //
+ index = ++_objectIdIndex;
+
+ //
+ // Read the first slice header.
+ //
+ startSlice();
+ string mostDerivedId = _current.typeId;
+ Ice.Object v = null;
+ while(true)
+ {
+ bool updateCache = false;
+
+ if(_current.compactId >= 0)
+ {
+ updateCache = true;
+
+ //
+ // Translate a compact (numeric) type ID into a class.
+ //
+ if(_compactIdCache == null)
+ {
+ _compactIdCache = new Dictionary<int, Type>(); // Lazy initialization.
+ }
+ else
+ {
+ //
+ // Check the cache to see if we've already translated the compact type ID into a class.
+ //
+ Type cls = null;
+ _compactIdCache.TryGetValue(_current.compactId, out cls);
+ if(cls != null)
+ {
+ try
+ {
+ Debug.Assert(!cls.IsAbstract && !cls.IsInterface);
+ v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls);
+ updateCache = false;
+ }
+ catch(Exception ex)
+ {
+ throw new NoValueFactoryException("no value factory", "compact ID " +
+ _current.compactId, ex);
+ }
+ }
+ }
+
+ //
+ // If we haven't already cached a class for the compact ID, then try to translate the
+ // compact ID into a type ID.
+ //
+ if(v == null)
+ {
+ _current.typeId = "";
+ if(_compactIdResolver != null)
+ {
+ try
+ {
+ _current.typeId = _compactIdResolver(_current.compactId);
+ }
+ catch(Ice.LocalException)
+ {
+ throw;
+ }
+ catch(System.Exception ex)
+ {
+ throw new Ice.MarshalException("exception in CompactIdResolver for ID " +
+ _current.compactId, ex);
+ }
+ }
+
+ if(_current.typeId.Length == 0)
+ {
+ _current.typeId = _stream.instance().resolveCompactId(_current.compactId);
+ }
+ }
+ }
+
+ if(v == null && _current.typeId.Length > 0)
+ {
+ v = newInstance(_current.typeId);
+ }
+
+ if(v != null)
+ {
+ if(updateCache)
+ {
+ Debug.Assert(_current.compactId >= 0);
+ _compactIdCache.Add(_current.compactId, v.GetType());
+ }
+
+ //
+ // We have an instance, get out of this loop.
+ //
+ break;
+ }
+
+ //
+ // If object slicing is disabled, stop un-marshalling.
+ //
+ if(!_sliceObjects)
+ {
+ throw new NoValueFactoryException("no value factory found and object slicing is disabled",
+ _current.typeId);
+ }
+
+ //
+ // Slice off what we don't understand.
+ //
+ skipSlice();
+
+ //
+ // If this is the last slice, keep the object as an opaque
+ // UnknownSlicedData object.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0)
+ {
+ //
+ // Provide a factory with an opportunity to supply the object.
+ // We pass the "::Ice::Object" ID to indicate that this is the
+ // last chance to preserve the object.
+ //
+ v = newInstance(Ice.ObjectImpl.ice_staticId());
+ if(v == null)
+ {
+ v = new Ice.UnknownSlicedObject(mostDerivedId);
+ }
+
+ break;
+ }
+
+ startSlice(); // Read next Slice header for next iteration.
+ }
+
+ //
+ // Un-marshal the object
+ //
+ unmarshal(index, v);
+
+ if(_current == null && _patchMap != null && _patchMap.Count > 0)
+ {
+ //
+ // If any entries remain in the patch map, the sender has sent an index for an object, but failed
+ // to supply the object.
+ //
+ throw new Ice.MarshalException("index for class received, but no instance");
+ }
+
+ if(cb != null)
+ {
+ cb(v);
+ }
+ return index;
+ }
+
+ private Ice.SlicedData readSlicedData()
+ {
+ if(_current.slices == null) // No preserved slices.
+ {
+ return null;
+ }
+
+ //
+ // The _indirectionTables member holds the indirection table for each slice
+ // in _slices.
+ //
+ Debug.Assert(_current.slices.Count == _current.indirectionTables.Count);
+ for(int n = 0; n < _current.slices.Count; ++n)
+ {
+ //
+ // We use the "objects" list in SliceInfo to hold references
+ // to the target objects. Note that the objects might not have
+ // been read yet in the case of a circular reference to an
+ // enclosing object.
+ //
+ int[] table = _current.indirectionTables[n];
+ Ice.SliceInfo info = _current.slices[n];
+ info.objects = new Ice.Object[table != null ? table.Length : 0];
+ for(int j = 0; j < info.objects.Length; ++j)
+ {
+ IceInternal.ArrayPatcher<Ice.Object> patcher =
+ new IceInternal.ArrayPatcher<Ice.Object>(Ice.ObjectImpl.ice_staticId(), info.objects, j);
+ addPatchEntry(table[j], patcher.patch);
+ }
+ }
+
+ return new Ice.SlicedData(_current.slices.ToArray());
+ }
+
+ private void push(SliceType sliceType)
+ {
+ if(_current == null)
+ {
+ _current = new InstanceData(null);
+ }
+ else
+ {
+ _current = _current.next == null ? new InstanceData(_current) : _current.next;
+ }
+ _current.sliceType = sliceType;
+ _current.skipFirstSlice = false;
+ }
+
+ private sealed class IndirectPatchEntry
+ {
+ public int index;
+ public ReadObjectCallback patcher;
+ }
+
+ private sealed class InstanceData
+ {
+ internal InstanceData(InstanceData previous)
+ {
+ if(previous != null)
+ {
+ previous.next = this;
+ }
+ this.previous = previous;
+ this.next = null;
+ }
+
+ // Instance attributes
+ internal SliceType sliceType;
+ internal bool skipFirstSlice;
+ internal List<Ice.SliceInfo> slices; // Preserved slices.
+ internal List<int[]> indirectionTables;
+
+ // Slice attributes
+ internal byte sliceFlags;
+ internal int sliceSize;
+ internal string typeId;
+ internal int compactId;
+ internal Stack<IndirectPatchEntry> indirectPatchList;
+
+ internal InstanceData previous;
+ internal InstanceData next;
+ }
+
+ private CompactIdResolver _compactIdResolver;
+ private InstanceData _current;
+ private int _objectIdIndex; // The ID of the next object to un-marshal.
+ private Dictionary<int, Type> _compactIdCache;
+ }
+
+ private sealed class Encaps
+ {
+ internal void reset()
+ {
+ decoder = null;
+ }
+
+ internal void setEncoding(Ice.EncodingVersion encoding)
+ {
+ this.encoding = encoding;
+ encoding_1_0 = encoding.Equals(Ice.Util.Encoding_1_0);
+ }
+
+ internal int start;
+ internal int sz;
+ internal Ice.EncodingVersion encoding;
+ internal bool encoding_1_0;
+
+ internal EncapsDecoder decoder;
+
+ internal Encaps next;
+ }
+
+ //
+ // The encoding version to use when there's no encapsulation to
+ // read from. This is for example used to read message headers.
+ //
+ private Ice.EncodingVersion _encoding;
+
+ private bool isEncoding_1_0()
+ {
+ return _encapsStack != null ? _encapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0);
+ }
+
+ private Encaps _encapsStack;
+ private Encaps _encapsCache;
+
+ private void initEncaps()
+ {
+ if(_encapsStack == null) // Lazy initialization
+ {
+ _encapsStack = _encapsCache;
+ if(_encapsStack != null)
+ {
+ _encapsCache = _encapsCache.next;
+ }
+ else
+ {
+ _encapsStack = new Encaps();
+ }
+ _encapsStack.setEncoding(_encoding);
+ _encapsStack.sz = _buf.b.limit();
+ }
+
+ if(_encapsStack.decoder == null) // Lazy initialization.
+ {
+ if(_encapsStack.encoding_1_0)
+ {
+ _encapsStack.decoder = new EncapsDecoder10(this, _encapsStack, _sliceObjects, _valueFactoryManager,
+ _classResolver);
+ }
+ else
+ {
+ _encapsStack.decoder = new EncapsDecoder11(this, _encapsStack, _sliceObjects, _valueFactoryManager,
+ _classResolver, _compactIdResolver);
+ }
+ }
+ }
+
+ private bool _sliceObjects;
+ private bool _traceSlicing;
+
+ private int _startSeq;
+ private int _minSeqSize;
+
+ private ValueFactoryManager _valueFactoryManager;
+ private Logger _logger;
+ private CompactIdResolver _compactIdResolver;
+ private ClassResolver _classResolver;
+ }
+
+ /// <summary>
+ /// Base class for extracting objects from an input stream.
+ /// </summary>
+ public abstract class ObjectReader : ObjectImpl
+ {
+ /// <summary>
+ /// Read the object's data members.
+ /// </summary>
+ /// <param name="inStream">The input stream to read from.</param>
+ public abstract void read(InputStream inStream);
+
+ public override void write__(OutputStream os)
+ {
+ Debug.Assert(false);
+ }
+
+ public override void read__(InputStream istr)
+ {
+ read(istr);
+ }
+ }
+
+}
diff --git a/csharp/src/Ice/Instance.cs b/csharp/src/Ice/Instance.cs
index 850fb12c984..a2fe6072a2c 100644
--- a/csharp/src/Ice/Instance.cs
+++ b/csharp/src/Ice/Instance.cs
@@ -174,20 +174,6 @@ namespace IceInternal
}
}
- public ObjectFactoryManager servantFactoryManager()
- {
- lock(this)
- {
- if(_state == StateDestroyed)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
- Debug.Assert(_servantFactoryManager != null);
- return _servantFactoryManager;
- }
- }
-
public ObjectAdapterFactory objectAdapterFactory()
{
lock(this)
@@ -689,6 +675,47 @@ namespace IceInternal
_initData.threadHook = threadHook;
}
+ public Type resolveClass(string id)
+ {
+ Type c = AssemblyUtil.findType(this, typeToClass(id));
+
+ //
+ // Ensure the class is instantiable.
+ //
+ if(c != null && !c.IsAbstract && !c.IsInterface)
+ {
+ return c;
+ }
+
+ return null;
+ }
+
+ public string resolveCompactId(int compactId)
+ {
+ String className = "IceCompactId.TypeId_" + compactId;
+ try
+ {
+ Type c = AssemblyUtil.findType(this, className);
+ if(c != null)
+ {
+ return (string)c.GetField("typeId").GetValue(null);
+ }
+ }
+ catch(Exception)
+ {
+ }
+ return "";
+ }
+
+ private static string typeToClass(string id)
+ {
+ if(!id.StartsWith("::", StringComparison.Ordinal))
+ {
+ throw new Ice.MarshalException("expected type id but received `" + id + "'");
+ }
+ return id.Substring(2).Replace("::", ".");
+ }
+
//
// Only for use by Ice.CommunicatorI
//
@@ -706,7 +733,7 @@ namespace IceInternal
#if !SILVERLIGHT && !UNITY
lock(_staticLock)
{
- if(!_oneOfDone)
+ if(!_oneOffDone)
{
string stdOut = _initData.properties.getProperty("Ice.StdOut");
string stdErr = _initData.properties.getProperty("Ice.StdErr");
@@ -754,7 +781,7 @@ namespace IceInternal
}
}
- _oneOfDone = true;
+ _oneOffDone = true;
}
}
#endif
@@ -914,9 +941,12 @@ namespace IceInternal
_pluginManager = new Ice.PluginManagerI(communicator);
#endif
- _outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this);
+ if(_initData.valueFactoryManager == null)
+ {
+ _initData.valueFactoryManager = new ValueFactoryManagerI();
+ }
- _servantFactoryManager = new ObjectFactoryManager();
+ _outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this);
_objectAdapterFactory = new ObjectAdapterFactory(this, communicator);
@@ -1264,10 +1294,14 @@ namespace IceInternal
}
#endif
- if(_servantFactoryManager != null)
+ foreach(Ice.ObjectFactory factory in _objectFactoryMap.Values)
{
- _servantFactoryManager.destroy();
+// Disable Obsolete warning/error
+#pragma warning disable 612, 618
+ factory.destroy();
+#pragma warning restore 612, 618
}
+ _objectFactoryMap.Clear();
if(_routerManager != null)
{
@@ -1321,7 +1355,6 @@ namespace IceInternal
#endif
_timer = null;
- _servantFactoryManager = null;
_referenceFactory = null;
_requestHandlerFactory = null;
_proxyFactory = null;
@@ -1382,6 +1415,32 @@ namespace IceInternal
}
}
+ public void addObjectFactory(Ice.ObjectFactory factory, string id)
+ {
+ lock(this)
+ {
+ //
+ // Create a ValueFactory wrapper around the given ObjectFactory and register the wrapper
+ // with the value factory manager. This may raise AlreadyRegisteredException.
+ //
+// Disable Obsolete warning/error
+#pragma warning disable 612, 618
+ _initData.valueFactoryManager.add((string type) => { return factory.create(type); }, id);
+#pragma warning restore 612, 618
+ _objectFactoryMap.Add(id, factory);
+ }
+ }
+
+ public Ice.ObjectFactory findObjectFactory(string id)
+ {
+ lock(this)
+ {
+ Ice.ObjectFactory factory = null;
+ _objectFactoryMap.TryGetValue(id, out factory);
+ return factory;
+ }
+ }
+
internal void updateConnectionObservers()
{
try
@@ -1546,7 +1605,6 @@ namespace IceInternal
private RequestHandlerFactory _requestHandlerFactory;
private ProxyFactory _proxyFactory;
private OutgoingConnectionFactory _outgoingConnectionFactory;
- private ObjectFactoryManager _servantFactoryManager;
private ObjectAdapterFactory _objectAdapterFactory;
private int _protocolSupport;
private bool _preferIPv6;
@@ -1573,9 +1631,11 @@ namespace IceInternal
#endif
#if !SILVERLIGHT && !UNITY
- private static bool _oneOfDone = false;
+ private static bool _oneOffDone = false;
#endif
+ private Dictionary<string, Ice.ObjectFactory> _objectFactoryMap = new Dictionary<string, Ice.ObjectFactory>();
+
private static System.Object _staticLock = new System.Object();
}
}
diff --git a/csharp/src/Ice/InstrumentationI.cs b/csharp/src/Ice/InstrumentationI.cs
index b9e74c5d05b..74cfc36382f 100644
--- a/csharp/src/Ice/InstrumentationI.cs
+++ b/csharp/src/Ice/InstrumentationI.cs
@@ -77,7 +77,7 @@ namespace IceInternal
}
protected O delegate_;
- };
+ }
public class ObserverFactoryWithDelegate<T, OImpl, O> : ObserverFactory<T, OImpl>
where T : Metrics, new()
@@ -171,7 +171,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public ConnectionHelper(Ice.ConnectionInfo con, Ice.Endpoint endpt, Ice.Instrumentation.ConnectionState state)
@@ -263,7 +263,7 @@ namespace IceInternal
readonly private Ice.Instrumentation.ConnectionState _state;
private string _id;
private Ice.EndpointInfo _endpointInfo;
- };
+ }
class DispatchHelper : MetricsHelper<DispatchMetrics>
{
@@ -291,7 +291,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public DispatchHelper(Ice.Current current, int size) : base(_attributes)
@@ -389,7 +389,7 @@ namespace IceInternal
readonly private int _size;
private string _id;
private Ice.EndpointInfo _endpointInfo;
- };
+ }
class InvocationHelper : MetricsHelper<InvocationMetrics>
{
@@ -417,7 +417,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public InvocationHelper(Ice.ObjectPrx proxy, string op, Dictionary<string, string> ctx) : base(_attributes)
@@ -538,7 +538,7 @@ namespace IceInternal
private string _id;
readonly static private Ice.Endpoint[] emptyEndpoints = new Ice.Endpoint[0];
- };
+ }
class ThreadHelper : MetricsHelper<ThreadMetrics>
{
@@ -557,7 +557,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public ThreadHelper(string parent, string id, Ice.Instrumentation.ThreadState state) : base(_attributes)
@@ -588,7 +588,7 @@ namespace IceInternal
readonly public string _parent;
readonly public string _id;
readonly private Ice.Instrumentation.ThreadState _state;
- };
+ }
class EndpointHelper : MetricsHelper<Metrics>
{
@@ -608,7 +608,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public EndpointHelper(Ice.Endpoint endpt, string id) : base(_attributes)
@@ -653,7 +653,7 @@ namespace IceInternal
readonly private Ice.Endpoint _endpoint;
private string _id;
private Ice.EndpointInfo _endpointInfo;
- };
+ }
public class RemoteInvocationHelper : MetricsHelper<RemoteMetrics>
{
@@ -674,7 +674,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public RemoteInvocationHelper(Ice.ConnectionInfo con, Ice.Endpoint endpt, int requestId, int size) :
@@ -746,7 +746,7 @@ namespace IceInternal
readonly private int _requestId;
private string _id;
private Ice.EndpointInfo _endpointInfo;
- };
+ }
public class CollocatedInvocationHelper : MetricsHelper<CollocatedMetrics>
{
@@ -766,7 +766,7 @@ namespace IceInternal
Debug.Assert(false);
}
}
- };
+ }
static AttributeResolver _attributes = new AttributeResolverI();
public CollocatedInvocationHelper(Ice.ObjectAdapter adapter, int requestId, int size) :
@@ -800,11 +800,11 @@ namespace IceInternal
readonly private int _size;
readonly private int _requestId;
readonly private string _id;
- };
+ }
public class ObserverWithDelegateI : ObserverWithDelegate<Metrics, Ice.Instrumentation.Observer>
{
- };
+ }
public class ConnectionObserverI : ObserverWithDelegate<ConnectionMetrics, Ice.Instrumentation.ConnectionObserver>,
Ice.Instrumentation.ConnectionObserver
@@ -841,7 +841,7 @@ namespace IceInternal
private int _sentBytes;
private int _receivedBytes;
- };
+ }
public class DispatchObserverI : ObserverWithDelegate<DispatchMetrics, Ice.Instrumentation.DispatchObserver>,
Ice.Instrumentation.DispatchObserver
@@ -1014,7 +1014,7 @@ namespace IceInternal
private Ice.Instrumentation.ThreadState _oldState;
private Ice.Instrumentation.ThreadState _newState;
- };
+ }
public class CommunicatorObserverI : Ice.Instrumentation.CommunicatorObserver
{
@@ -1219,4 +1219,4 @@ namespace IceInternal
readonly private ObserverFactoryWithDelegate<Metrics, ObserverWithDelegateI,
Ice.Instrumentation.Observer> _endpointLookups;
}
-} \ No newline at end of file
+}
diff --git a/csharp/src/Ice/LocatorInfo.cs b/csharp/src/Ice/LocatorInfo.cs
index 20f780dcb2f..92497315fa1 100644
--- a/csharp/src/Ice/LocatorInfo.cs
+++ b/csharp/src/Ice/LocatorInfo.cs
@@ -790,7 +790,7 @@ namespace IceInternal
private Ice.Identity _id;
private Ice.EncodingVersion _encoding;
- };
+ }
internal LocatorManager(Ice.Properties properties)
{
diff --git a/csharp/src/Ice/Makefile b/csharp/src/Ice/Makefile
index c1783a0c59d..01ebe94756c 100644
--- a/csharp/src/Ice/Makefile
+++ b/csharp/src/Ice/Makefile
@@ -24,11 +24,11 @@ SRCS = Acceptor.cs \
AsyncIOThread.cs \
AsyncResult.cs \
Base64.cs \
- BasicStream.cs \
BatchRequestInterceptor.cs \
BatchRequestQueue.cs \
Buffer.cs \
ByteBuffer.cs \
+ BZip2.cs \
CollectionBase.cs \
Collections.cs \
CollocatedRequestHandler.cs \
@@ -53,6 +53,7 @@ SRCS = Acceptor.cs \
ImplicitContextI.cs \
Incoming.cs \
IncomingAsync.cs \
+ InputStream.cs \
Instance.cs \
InstrumentationI.cs \
IPEndpointI.cs \
@@ -68,13 +69,13 @@ SRCS = Acceptor.cs \
Object.cs \
ObjectAdapterFactory.cs \
ObjectAdapterI.cs \
- ObjectFactoryManager.cs \
ObserverHelper.cs \
OpaqueEndpointI.cs \
Optional.cs \
Options.cs \
OutgoingAsync.cs \
OutputBase.cs \
+ OutputStream.cs \
Patcher.cs \
PluginManagerI.cs \
ProcessI.cs \
@@ -100,8 +101,6 @@ SRCS = Acceptor.cs \
SliceChecksums.cs \
SlicedData.cs \
SocketOperation.cs \
- Stream.cs \
- StreamI.cs \
StreamSocket.cs \
StreamWrapper.cs \
StringUtil.cs \
@@ -124,6 +123,7 @@ SRCS = Acceptor.cs \
UnknownSlicedObject.cs \
UserExceptionFactory.cs \
Util.cs \
+ ValueFactoryManager.cs \
ValueWriter.cs \
WSAcceptor.cs \
WSConnector.cs \
@@ -154,6 +154,7 @@ SLICE_SRCS = $(SDIR)/BuiltinSequences.ice \
$(SDIR)/Router.ice \
$(SDIR)/ServantLocator.ice \
$(SDIR)/SliceChecksumDict.ice \
+ $(SDIR)/ValueFactory.ice \
$(SDIR)/Version.ice \
SDIR = $(slicedir)/Ice
@@ -194,8 +195,3 @@ install:: all
clean::
echo $(GEN_SRCS)
-rm -f $(assembliesdir)/$(PKG).xml
-
-$(GDIR)/BuiltinSequences.cs: $(SDIR)/BuiltinSequences.ice $(SLICE2CPP) $(SLICEPARSERLIB)
- rm -f $(GDIR)/BuiltinSequences.cs
- $(SLICE2CS) $(SLICE2CSFLAGS) --stream $(SDIR)/BuiltinSequences.ice
- mv BuiltinSequences.cs $(GDIR)
diff --git a/csharp/src/Ice/Makefile.mak b/csharp/src/Ice/Makefile.mak
index 556d7fa85c2..7843d2512d4 100644
--- a/csharp/src/Ice/Makefile.mak
+++ b/csharp/src/Ice/Makefile.mak
@@ -24,11 +24,11 @@ SRCS = Acceptor.cs \
AsyncIOThread.cs \
AsyncResult.cs \
Base64.cs \
- BasicStream.cs \
BatchRequestInterceptor.cs \
BatchRequestQueue.cs \
Buffer.cs \
ByteBuffer.cs \
+ BZip2.cs \
CollectionBase.cs \
Collections.cs \
CollocatedRequestHandler.cs \
@@ -54,6 +54,7 @@ SRCS = Acceptor.cs \
ImplicitContextI.cs \
Incoming.cs \
IncomingAsync.cs \
+ InputStream.cs \
Instance.cs \
InstrumentationI.cs \
IPEndpointI.cs \
@@ -69,13 +70,13 @@ SRCS = Acceptor.cs \
Object.cs \
ObjectAdapterFactory.cs \
ObjectAdapterI.cs \
- ObjectFactoryManager.cs \
ObserverHelper.cs \
OpaqueEndpointI.cs \
Optional.cs \
Options.cs \
OutgoingAsync.cs \
OutputBase.cs \
+ OutputStream.cs \
Patcher.cs \
PluginManagerI.cs \
ProcessI.cs \
@@ -101,8 +102,6 @@ SRCS = Acceptor.cs \
SliceChecksums.cs \
SlicedData.cs \
SocketOperation.cs \
- Stream.cs \
- StreamI.cs \
StreamSocket.cs \
StreamWrapper.cs \
StringUtil.cs \
@@ -125,6 +124,7 @@ SRCS = Acceptor.cs \
UnknownSlicedObject.cs \
UserExceptionFactory.cs \
Util.cs \
+ ValueFactoryManager.cs \
ValueWriter.cs \
WSAcceptor.cs \
WSConnector.cs \
@@ -155,6 +155,7 @@ GEN_SRCS = $(GDIR)\BuiltinSequences.cs \
$(GDIR)\Router.cs \
$(GDIR)\ServantLocator.cs \
$(GDIR)\SliceChecksumDict.cs \
+ $(GDIR)\ValueFactory.cs \
$(GDIR)\Version.cs
SDIR = $(slicedir)\Ice
@@ -194,8 +195,3 @@ install:: all
!if "$(DEBUG)" == "yes"
copy $(assembliesdir)\$(PKG).pdb "$(install_assembliesdir)"
!endif
-
-$(GDIR)\BuiltinSequences.cs: "$(SDIR)\BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
- del /q $(GDIR)\BuiltinSequences.cs
- "$(SLICE2CS)" $(SLICE2CSFLAGS) --stream "$(SDIR)\BuiltinSequences.ice"
- move BuiltinSequences.cs $(GDIR)
diff --git a/csharp/src/Ice/MetricsAdminI.cs b/csharp/src/Ice/MetricsAdminI.cs
index 2945c962715..f949c593f3b 100644
--- a/csharp/src/Ice/MetricsAdminI.cs
+++ b/csharp/src/Ice/MetricsAdminI.cs
@@ -21,29 +21,29 @@ namespace IceInternal
IceMX.MetricsFailures[] getFailures();
IceMX.MetricsFailures getFailures(string id);
Dictionary<string, string> getProperties();
- };
+ }
interface ISubMap
{
void addSubMapToMetrics(IceMX.Metrics metrics);
- };
+ }
interface ISubMapCloneFactory
{
ISubMap create();
- };
+ }
interface ISubMapFactory
{
ISubMapCloneFactory createCloneFactory(string subMapPrefix, Ice.Properties properties);
- };
+ }
internal interface IMetricsMapFactory
{
void registerSubMap<S>(string subMap, System.Reflection.FieldInfo field) where S : IceMX.Metrics, new();
void update();
IMetricsMap create(string mapPrefix, Ice.Properties properties);
- };
+ }
internal class SubMap<S> : ISubMap where S : IceMX.Metrics, new()
{
@@ -72,7 +72,7 @@ namespace IceInternal
readonly private MetricsMap<S> _map;
readonly private System.Reflection.FieldInfo _field;
- };
+ }
internal class SubMapCloneFactory<S> : ISubMapCloneFactory where S : IceMX.Metrics, new()
{
@@ -89,7 +89,7 @@ namespace IceInternal
readonly private MetricsMap<S> _map;
readonly private System.Reflection.FieldInfo _field;
- };
+ }
class SubMapFactory<S> : ISubMapFactory where S : IceMX.Metrics, new()
{
@@ -104,7 +104,7 @@ namespace IceInternal
}
readonly private System.Reflection.FieldInfo _field;
- };
+ }
public class MetricsMap<T> : IMetricsMap where T : IceMX.Metrics, new()
{
@@ -231,7 +231,7 @@ namespace IceInternal
private T _object;
private Dictionary<string, int> _failures;
private Dictionary<string, ISubMap> _subMaps;
- };
+ }
internal MetricsMap(string mapPrefix, Ice.Properties props, Dictionary<string, ISubMapFactory> subMaps)
{
@@ -543,7 +543,7 @@ namespace IceInternal
readonly private Dictionary<string, Entry> _objects = new Dictionary<string, Entry>();
readonly private Dictionary<string, ISubMapCloneFactory> _subMaps;
private LinkedList<Entry> _detachedQueue;
- };
+ }
internal class MetricsViewI
{
@@ -661,7 +661,7 @@ namespace IceInternal
readonly private string _name;
readonly private Dictionary<string, IMetricsMap> _maps = new Dictionary<string, IMetricsMap>();
- };
+ }
public class MetricsAdminI : IceMX.MetricsAdminDisp_, Ice.PropertiesAdminUpdateCallback
{
@@ -745,7 +745,7 @@ namespace IceInternal
readonly private System.Action _updater;
#endif
readonly private Dictionary<string, ISubMapFactory> _subMaps = new Dictionary<string, ISubMapFactory>();
- };
+ }
public MetricsAdminI(Ice.Properties properties, Ice.Logger logger)
{
@@ -1045,4 +1045,4 @@ namespace IceInternal
private Dictionary<string, MetricsViewI> _views = new Dictionary<string, MetricsViewI>();
private List<string> _disabledViews = new List<string>();
}
-} \ No newline at end of file
+}
diff --git a/csharp/src/Ice/MetricsObserverI.cs b/csharp/src/Ice/MetricsObserverI.cs
index 174cbd0027c..bf7bc261362 100644
--- a/csharp/src/Ice/MetricsObserverI.cs
+++ b/csharp/src/Ice/MetricsObserverI.cs
@@ -53,7 +53,7 @@ namespace IceMX
}
readonly protected string _name;
- };
+ }
class FieldResolverI : Resolver
{
@@ -69,7 +69,7 @@ namespace IceMX
}
readonly private System.Reflection.FieldInfo _field;
- };
+ }
class MethodResolverI : Resolver
{
@@ -85,7 +85,7 @@ namespace IceMX
}
readonly private System.Reflection.MethodInfo _method;
- };
+ }
class MemberFieldResolverI : Resolver
{
@@ -110,7 +110,7 @@ namespace IceMX
readonly private System.Reflection.MethodInfo _method;
readonly private System.Reflection.FieldInfo _field;
- };
+ }
class MemberMethodResolverI : Resolver
{
@@ -135,7 +135,7 @@ namespace IceMX
readonly private System.Reflection.MethodInfo _method;
readonly private System.Reflection.MethodInfo _subMethod;
- };
+ }
protected AttributeResolver()
{
@@ -185,7 +185,7 @@ namespace IceMX
}
private Dictionary<string, Resolver> _attributes = new Dictionary<string, Resolver>();
- };
+ }
protected MetricsHelper(AttributeResolver attributes)
{
@@ -208,7 +208,7 @@ namespace IceMX
}
private AttributeResolver _attributes;
- };
+ }
public class Observer<T> : Stopwatch, Ice.Instrumentation.Observer where T : Metrics, new()
{
@@ -314,7 +314,7 @@ namespace IceMX
private List<MetricsMap<T>.Entry> _objects;
private long _previousDelay = 0;
- };
+ }
public class ObserverFactory<T, O> where T : Metrics, new() where O : Observer<T>, new()
{
@@ -450,5 +450,5 @@ namespace IceMX
#else
private System.Action _updater;
#endif
- };
-} \ No newline at end of file
+ }
+}
diff --git a/csharp/src/Ice/Object.cs b/csharp/src/Ice/Object.cs
index e9e14943c46..81dbdd655ba 100644
--- a/csharp/src/Ice/Object.cs
+++ b/csharp/src/Ice/Object.cs
@@ -147,11 +147,8 @@ namespace Ice
DispatchStatus dispatch__(IceInternal.Incoming inc, Current current);
- void write__(IceInternal.BasicStream os__);
- void read__(IceInternal.BasicStream is__);
-
- void write__(OutputStream outS__);
- void read__(InputStream inS__);
+ void write__(OutputStream os__);
+ void read__(InputStream is__);
}
/// <summary>
@@ -204,11 +201,11 @@ namespace Ice
public static DispatchStatus ice_isA___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current)
{
- IceInternal.BasicStream is__ = inS__.startReadParams();
+ InputStream is__ = inS__.startReadParams();
string __id = is__.readString();
inS__.endReadParams();
bool __ret = __obj.ice_isA(__id, __current);
- IceInternal.BasicStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
+ OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
os__.writeBool(__ret);
inS__.endWriteParams__(true);
return DispatchStatus.DispatchOK;
@@ -262,7 +259,7 @@ namespace Ice
{
inS__.readEmptyParams();
string[] ret__ = __obj.ice_ids(__current);
- IceInternal.BasicStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
+ OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
os__.writeStringSeq(ret__);
inS__.endWriteParams__(true);
return DispatchStatus.DispatchOK;
@@ -291,7 +288,7 @@ namespace Ice
{
inS__.readEmptyParams();
string __ret = __obj.ice_id(__current);
- IceInternal.BasicStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
+ OutputStream os__ = inS__.startWriteParams__(FormatType.DefaultFormat);
os__.writeString(__ret);
inS__.endWriteParams__(true);
return DispatchStatus.DispatchOK;
@@ -399,20 +396,6 @@ namespace Ice
throw new Ice.OperationNotExistException(current.id, current.facet, current.operation);
}
- public virtual void write__(IceInternal.BasicStream os__)
- {
- os__.startWriteObject(null);
- writeImpl__(os__);
- os__.endWriteObject();
- }
-
- public virtual void read__(IceInternal.BasicStream is__)
- {
- is__.startReadObject();
- readImpl__(is__);
- is__.endReadObject(false);
- }
-
public virtual void write__(OutputStream os__)
{
os__.startObject(null);
@@ -427,22 +410,12 @@ namespace Ice
is__.endObject(false);
}
- protected virtual void writeImpl__(IceInternal.BasicStream os__)
- {
- }
-
- protected virtual void readImpl__(IceInternal.BasicStream is__)
- {
- }
-
protected virtual void writeImpl__(OutputStream os__)
{
- throw new MarshalException("class was not generated with stream support");
}
protected virtual void readImpl__(InputStream is__)
{
- throw new MarshalException("class was not generated with stream support");
}
private static string operationModeToString(OperationMode mode)
diff --git a/csharp/src/Ice/ObjectFactoryManager.cs b/csharp/src/Ice/ObjectFactoryManager.cs
deleted file mode 100644
index e138fda4143..00000000000
--- a/csharp/src/Ice/ObjectFactoryManager.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-namespace IceInternal
-{
-
- using System.Collections.Generic;
-
- public sealed class ObjectFactoryManager
- {
- public void add(Ice.ObjectFactory factory, string id)
- {
- lock(this)
- {
- if(_factoryMap.ContainsKey(id))
- {
- Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
- ex.id = id;
- ex.kindOfObject = "object factory";
- throw ex;
- }
- _factoryMap[id] = factory;
- }
- }
-
- public void remove(string id)
- {
- object o = null;
- lock(this)
- {
- if(!_factoryMap.ContainsKey(id))
- {
- Ice.NotRegisteredException ex = new Ice.NotRegisteredException();
- ex.id = id;
- ex.kindOfObject = "object factory";
- throw ex;
- }
- _factoryMap.Remove(id);
- }
- ((Ice.ObjectFactory)o).destroy();
- }
-
- public Ice.ObjectFactory find(string id)
- {
- lock(this)
- {
- Ice.ObjectFactory factory = null;
- _factoryMap.TryGetValue(id, out factory);
- return factory;
- }
- }
-
- //
- // Only for use by Instance
- //
- internal ObjectFactoryManager()
- {
- _factoryMap = new Dictionary<string, Ice.ObjectFactory>();
- }
-
- internal void destroy()
- {
- Dictionary<string, Ice.ObjectFactory> oldMap = null;
-
- lock(this)
- {
- oldMap = _factoryMap;
- _factoryMap = new Dictionary<string, Ice.ObjectFactory>();
- }
-
- foreach(Ice.ObjectFactory factory in oldMap.Values)
- {
- factory.destroy();
- }
- }
-
- private Dictionary<string, Ice.ObjectFactory> _factoryMap;
- }
-
-}
diff --git a/csharp/src/Ice/OpaqueEndpointI.cs b/csharp/src/Ice/OpaqueEndpointI.cs
index ae9af6ece4e..020878a3e38 100644
--- a/csharp/src/Ice/OpaqueEndpointI.cs
+++ b/csharp/src/Ice/OpaqueEndpointI.cs
@@ -36,11 +36,11 @@ namespace IceInternal
calcHashValue();
}
- public OpaqueEndpointI(short type, BasicStream s)
+ public OpaqueEndpointI(short type, Ice.InputStream s)
{
_type = type;
- _rawEncoding = s.getReadEncoding();
- int sz = s.getReadEncapsSize();
+ _rawEncoding = s.getEncoding();
+ int sz = s.getEncapsulationSize();
_rawBytes = new byte[sz];
s.readBlob(_rawBytes);
@@ -50,11 +50,11 @@ namespace IceInternal
//
// Marshal the endpoint
//
- public override void streamWrite(BasicStream s)
+ public override void streamWrite(Ice.OutputStream s)
{
- s.startWriteEncaps(_rawEncoding, Ice.FormatType.DefaultFormat);
+ s.startEncapsulation(_rawEncoding, Ice.FormatType.DefaultFormat);
s.writeBlob(_rawBytes);
- s.endWriteEncaps();
+ s.endEncapsulation();
}
//
diff --git a/csharp/src/Ice/Optional.cs b/csharp/src/Ice/Optional.cs
index aaf98e5bfc4..84802723371 100644
--- a/csharp/src/Ice/Optional.cs
+++ b/csharp/src/Ice/Optional.cs
@@ -198,23 +198,23 @@ namespace Ice
/// <summary>
/// Handles callbacks for an optional object parameter.
/// </summary>
- public class OptionalPatcher<T> : IceInternal.Patcher
+ public class OptionalPatcher<T>
where T : Ice.Object
{
/// <summary>
/// Instantiates the class with the given optional.
/// </summary>
/// <param name="type">The Slice type ID corresponding to the formal type.</param>
- public OptionalPatcher(string type) :
- base(type)
+ public OptionalPatcher(string type)
{
+ _type = type;
}
/// <summary>
/// Sets the Ice object of the optional to the passed instance.
/// </summary>
/// <param name="v">The new object for the optional.</param>
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v == null || typeof(T).IsAssignableFrom(v.GetType()))
{
@@ -231,7 +231,7 @@ namespace Ice
}
else
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
}
@@ -239,6 +239,7 @@ namespace Ice
/// The target optional.
/// </summary>
public Optional<T> value = new Optional<T>();
+ private string _type;
}
/// <summary>
diff --git a/csharp/src/Ice/OutgoingAsync.cs b/csharp/src/Ice/OutgoingAsync.cs
index be387e64dae..22c8966020a 100644
--- a/csharp/src/Ice/OutgoingAsync.cs
+++ b/csharp/src/Ice/OutgoingAsync.cs
@@ -58,12 +58,12 @@ namespace IceInternal
}
}
- public IceInternal.BasicStream getOs()
+ public Ice.OutputStream getOs()
{
return os_;
}
- public virtual IceInternal.BasicStream getIs()
+ public virtual Ice.InputStream getIs()
{
return null; // Must be implemented by classes that handle responses
}
@@ -71,10 +71,11 @@ namespace IceInternal
protected OutgoingAsyncBase(Ice.Communicator com, Instance instance, string op, object cookie) :
base(com, instance, op, cookie)
{
- os_ = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
+ os_ = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding);
}
- protected OutgoingAsyncBase(Ice.Communicator com, Instance instance, string op, object cookie, BasicStream os) :
+ protected OutgoingAsyncBase(Ice.Communicator com, Instance instance, string op, object cookie,
+ Ice.OutputStream os) :
base(com, instance, op, cookie)
{
os_ = os;
@@ -97,14 +98,14 @@ namespace IceInternal
{
if(childObserver_ != null)
{
- childObserver_.failed(ex.ice_name());
+ childObserver_.failed(ex.ice_id());
childObserver_.detach();
childObserver_ = null;
}
return base.finished(ex);
}
- protected BasicStream os_;
+ protected Ice.OutputStream os_;
protected Ice.Instrumentation.ChildInvocationObserver childObserver_;
}
@@ -134,7 +135,7 @@ namespace IceInternal
{
if(childObserver_ != null)
{
- childObserver_.failed(exc.ice_name());
+ childObserver_.failed(exc.ice_id());
childObserver_.detach();
childObserver_ = null;
}
@@ -246,7 +247,7 @@ namespace IceInternal
_sent = false;
}
- protected ProxyOutgoingAsyncBase(Ice.ObjectPrxHelperBase prx, string op, object cookie, BasicStream os) :
+ protected ProxyOutgoingAsyncBase(Ice.ObjectPrxHelperBase prx, string op, object cookie, Ice.OutputStream os) :
base(prx.ice_getCommunicator(), prx.reference__().getInstance(), op, cookie, os)
{
proxy_ = prx;
@@ -321,7 +322,7 @@ namespace IceInternal
{
if(childObserver_ != null)
{
- childObserver_.failed(ex.ice_name());
+ childObserver_.failed(ex.ice_id());
childObserver_.detach();
childObserver_ = null;
}
@@ -414,7 +415,8 @@ namespace IceInternal
_is = null;
}
- public OutgoingAsync(Ice.ObjectPrx prx, string operation, object cookie, BasicStream istr, BasicStream ostr) :
+ public OutgoingAsync(Ice.ObjectPrx prx, string operation, object cookie, Ice.InputStream istr,
+ Ice.OutputStream ostr) :
base((Ice.ObjectPrxHelperBase)prx, operation, cookie, ostr)
{
_encoding = Protocol.getCompatibleEncoding(proxy_.reference__().getEncoding());
@@ -514,7 +516,7 @@ namespace IceInternal
public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB)
{
- // The BasicStream cannot be cached if the proxy is not a twoway or there is an invocation timeout set.
+ // The stream cannot be cached if the proxy is not a twoway or there is an invocation timeout set.
if(!proxy_.ice_isTwoway() || proxy_.reference__().getInvocationTimeout() != -1)
{
// Disable caching by marking the streams as cached!
@@ -706,62 +708,62 @@ namespace IceInternal
}
}
- public BasicStream startWriteParams(Ice.FormatType format)
+ public Ice.OutputStream startWriteParams(Ice.FormatType format)
{
- os_.startWriteEncaps(_encoding, format);
+ os_.startEncapsulation(_encoding, format);
return os_;
}
public void endWriteParams()
{
- os_.endWriteEncaps();
+ os_.endEncapsulation();
}
public void writeEmptyParams()
{
- os_.writeEmptyEncaps(_encoding);
+ os_.writeEmptyEncapsulation(_encoding);
}
public void writeParamEncaps(byte[] encaps)
{
if(encaps == null || encaps.Length == 0)
{
- os_.writeEmptyEncaps(_encoding);
+ os_.writeEmptyEncapsulation(_encoding);
}
else
{
- os_.writeEncaps(encaps);
+ os_.writeEncapsulation(encaps);
}
}
- public IceInternal.BasicStream startReadParams()
+ public Ice.InputStream startReadParams()
{
- _is.startReadEncaps();
+ _is.startEncapsulation();
return _is;
}
public void endReadParams()
{
- _is.endReadEncaps();
+ _is.endEncapsulation();
}
public void readEmptyParams()
{
- _is.skipEmptyEncaps();
+ _is.skipEmptyEncapsulation();
}
public byte[] readParamEncaps()
{
Ice.EncodingVersion encoding;
- return _is.readEncaps(out encoding);
+ return _is.readEncapsulation(out encoding);
}
- override public BasicStream getIs()
+ override public Ice.InputStream getIs()
{
// _is can already be initialized if the invocation is retried
if(_is == null)
{
- _is = new IceInternal.BasicStream(instance_, Ice.Util.currentProtocolEncoding);
+ _is = new Ice.InputStream(instance_, Ice.Util.currentProtocolEncoding);
}
return _is;
}
@@ -770,12 +772,12 @@ namespace IceInternal
{
try
{
- _is.startReadEncaps();
+ _is.startEncapsulation();
_is.throwException(null);
}
catch(Ice.UserException ex)
{
- _is.endReadEncaps();
+ _is.endEncapsulation();
throw ex;
}
}
@@ -807,7 +809,7 @@ namespace IceInternal
}
private Ice.EncodingVersion _encoding;
- private BasicStream _is;
+ private Ice.InputStream _is;
//
// If true this AMI request is being used for a generated synchronous invocation.
@@ -930,7 +932,7 @@ namespace IceInternal
{
if(childObserver_ != null)
{
- childObserver_.failed(ex.ice_name());
+ childObserver_.failed(ex.ice_id());
childObserver_.detach();
childObserver_ = null;
}
@@ -944,7 +946,7 @@ namespace IceInternal
}
private CommunicatorFlushBatch _outAsync;
- };
+ }
private int _useCount;
}
@@ -1157,8 +1159,8 @@ namespace IceInternal
{
}
- public OutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, object cookie, BasicStream iss,
- BasicStream os) :
+ public OutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, object cookie, Ice.InputStream iss,
+ Ice.OutputStream os) :
base(prx, operation, cookie, iss, os)
{
}
@@ -1208,7 +1210,7 @@ namespace IceInternal
}
public TwowayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyTwowayCallback<T> cb,
- object cookie, BasicStream iss, BasicStream os) :
+ object cookie, Ice.InputStream iss, Ice.OutputStream os) :
base(prx, operation, cookie, iss, os)
{
Debug.Assert(cb != null);
@@ -1234,7 +1236,7 @@ namespace IceInternal
}
public OnewayOutgoingAsync(Ice.ObjectPrxHelperBase prx, string operation, ProxyOnewayCallback<T> cb,
- object cookie, BasicStream iss, BasicStream os) :
+ object cookie, Ice.InputStream iss, Ice.OutputStream os) :
base(prx, operation, cookie, iss, os)
{
Debug.Assert(cb != null);
diff --git a/csharp/src/Ice/OutputStream.cs b/csharp/src/Ice/OutputStream.cs
new file mode 100644
index 00000000000..54ab4972379
--- /dev/null
+++ b/csharp/src/Ice/OutputStream.cs
@@ -0,0 +1,2844 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+namespace Ice
+{
+
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Reflection;
+#if !COMPACT && !SILVERLIGHT
+ using System.Runtime.Serialization;
+ using System.Runtime.Serialization.Formatters.Binary;
+#endif
+ using System.Threading;
+ using Protocol = IceInternal.Protocol;
+
+ /// <summary>
+ /// Interface for output streams used to write Slice types to a sequence
+ /// of bytes.
+ /// </summary>
+ public class OutputStream
+ {
+
+ /// <summary>
+ /// Constructing an OutputStream without providing a communicator means the stream will
+ /// use the default encoding version and the default format for class encoding.
+ /// You can supply a communicator later by calling initialize().
+ /// </summary>
+ public OutputStream()
+ {
+ _buf = new IceInternal.Buffer();
+ instance_ = null;
+ _closure = null;
+ _encoding = Util.currentEncoding;
+ _format = FormatType.CompactFormat;
+ }
+
+ /// <summary>
+ /// This constructor uses the communicator's default encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ public OutputStream(Communicator communicator)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, instance.defaultsAndOverrides().defaultEncoding);
+ }
+
+ /// <summary>
+ /// This constructor uses the given communicator and encoding version.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="encoding">The desired encoding version.</param>
+ public OutputStream(Communicator communicator, EncodingVersion encoding)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, encoding);
+ }
+
+ public OutputStream(IceInternal.Instance instance, EncodingVersion encoding)
+ {
+ initialize(instance, encoding);
+ }
+
+ public OutputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt)
+ {
+ initialize(instance, encoding, new IceInternal.Buffer(buf, adopt));
+ }
+
+ public OutputStream(IceInternal.Instance instance, EncodingVersion encoding, byte[] data)
+ {
+ initialize(instance, encoding);
+ _buf = new IceInternal.Buffer(data);
+ }
+
+ /// <summary>
+ /// Initializes the stream to use the communicator's default encoding version and class
+ /// encoding format.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ public void initialize(Communicator communicator)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, instance.defaultsAndOverrides().defaultEncoding);
+ }
+
+ /// <summary>
+ /// Initializes the stream to use the given encoding version and the communicator's
+ /// default class encoding format.
+ /// </summary>
+ /// <param name="communicator">The communicator to use when initializing the stream.</param>
+ /// <param name="encoding">The desired encoding version.</param>
+ public void initialize(Communicator communicator, EncodingVersion encoding)
+ {
+ Debug.Assert(communicator != null);
+ IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
+ initialize(instance, encoding);
+ }
+
+ private void initialize(IceInternal.Instance instance, EncodingVersion encoding)
+ {
+ initialize(instance, encoding, new IceInternal.Buffer());
+ }
+
+ private void initialize(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf)
+ {
+ Debug.Assert(instance != null);
+
+ instance_ = instance;
+ _buf = buf;
+ _closure = null;
+ _encoding = encoding;
+
+ _format = instance_.defaultsAndOverrides().defaultFormat;
+
+ _encapsStack = null;
+ _encapsCache = null;
+ }
+
+ /// <summary>
+ /// Resets this output stream. This method allows the stream to be reused, to avoid creating
+ /// unnecessary garbage.
+ /// </summary>
+ public void reset()
+ {
+ _buf.reset();
+ clear();
+ }
+
+ /// <summary>
+ /// Releases any data retained by encapsulations. The reset() method internally calls clear().
+ /// </summary>
+ public void clear()
+ {
+ if(_encapsStack != null)
+ {
+ Debug.Assert(_encapsStack.next == null);
+ _encapsStack.next = _encapsCache;
+ _encapsCache = _encapsStack;
+ _encapsStack = null;
+ _encapsCache.reset();
+ }
+ }
+
+ public IceInternal.Instance instance()
+ {
+ return instance_;
+ }
+
+ /// <summary>
+ /// Sets the encoding format for class and exception instances.
+ /// </summary>
+ /// <param name="fmt">The encoding format.</param>
+ public void setFormat(FormatType fmt)
+ {
+ _format = fmt;
+ }
+
+ /// <summary>
+ /// Retrieves the closure object associated with this stream.
+ /// </summary>
+ /// <returns>The closure object.</returns>
+ public object getClosure()
+ {
+ return _closure;
+ }
+
+ /// <summary>
+ /// Associates a closure object with this stream.
+ /// </summary>
+ /// <param name="p">The new closure object.</param>
+ /// <returns>The previous closure object, or null.</returns>
+ public object setClosure(object p)
+ {
+ object prev = _closure;
+ _closure = p;
+ return prev;
+ }
+
+ /// <summary>
+ /// Indicates that the marshaling of a request or reply is finished.
+ /// </summary>
+ /// <returns>The byte sequence containing the encoded request or reply.</returns>
+ public byte[] finished()
+ {
+ IceInternal.Buffer buf = prepareWrite();
+ byte[] result = new byte[buf.b.limit()];
+ buf.b.get(result);
+ return result;
+ }
+
+ /// <summary>
+ /// Swaps the contents of one stream with another.
+ /// </summary>
+ /// <param name="other">The other stream.</param>
+ public void swap(OutputStream other)
+ {
+ Debug.Assert(instance_ == other.instance_);
+
+ IceInternal.Buffer tmpBuf = other._buf;
+ other._buf = _buf;
+ _buf = tmpBuf;
+
+ EncodingVersion tmpEncoding = other._encoding;
+ other._encoding = _encoding;
+ _encoding = tmpEncoding;
+
+ object tmpClosure = other._closure;
+ other._closure = _closure;
+ _closure = tmpClosure;
+
+ //
+ // Swap is never called for streams that have encapsulations being written. However,
+ // encapsulations might still be set in case marshalling failed. We just
+ // reset the encapsulations if there are still some set.
+ //
+ resetEncapsulation();
+ other.resetEncapsulation();
+ }
+
+ private void resetEncapsulation()
+ {
+ _encapsStack = null;
+ }
+
+ /// <summary>
+ /// Resizes the stream to a new size.
+ /// </summary>
+ /// <param name="sz">The new size.</param>
+ public void resize(int sz)
+ {
+ _buf.resize(sz, false);
+ _buf.b.position(sz);
+ }
+
+ /// <summary>
+ /// Prepares the internal data buffer to be written to a socket.
+ /// </summary>
+ public IceInternal.Buffer prepareWrite()
+ {
+ _buf.b.limit(_buf.size());
+ _buf.b.position(0);
+ return _buf;
+ }
+
+ /// <summary>
+ /// Retrieves the internal data buffer.
+ /// </summary>
+ /// <returns>The buffer.</returns>
+ public IceInternal.Buffer getBuffer()
+ {
+ return _buf;
+ }
+
+ /// <summary>
+ /// Marks the start of an Ice object.
+ /// </summary>
+ /// <param name="data">Preserved slices for this object, or null.</param>
+ public void startObject(Ice.SlicedData data)
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.startInstance(SliceType.ObjectSlice, data);
+ }
+
+ /// <summary>
+ /// Marks the end of an Ice object.
+ /// </summary>
+ public void endObject()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.endInstance();
+ }
+
+ /// <summary>
+ /// Marks the start of a user exception.
+ /// </summary>
+ /// <param name="data">Preserved slices for this exception, or null.</param>
+ public void startException(Ice.SlicedData data)
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.startInstance(SliceType.ExceptionSlice, data);
+ }
+
+ /// <summary>
+ /// Marks the end of a user exception.
+ /// </summary>
+ public void endException()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.endInstance();
+ }
+
+ /// <summary>
+ /// Writes the start of an encapsulation to the stream.
+ /// </summary>
+ public void startEncapsulation()
+ {
+ //
+ // If no encoding version is specified, use the current write
+ // encapsulation encoding version if there's a current write
+ // encapsulation, otherwise, use the stream encoding version.
+ //
+
+ if(_encapsStack != null)
+ {
+ startEncapsulation(_encapsStack.encoding, _encapsStack.format);
+ }
+ else
+ {
+ startEncapsulation(_encoding, Ice.FormatType.DefaultFormat);
+ }
+ }
+
+ /// <summary>
+ /// Writes the start of an encapsulation to the stream.
+ /// </summary>
+ /// <param name="encoding">The encoding version of the encapsulation.</param>
+ /// <param name="format">Specify the compact or sliced format.</param>
+ public void startEncapsulation(EncodingVersion encoding, Ice.FormatType format)
+ {
+ Protocol.checkSupportedEncoding(encoding);
+
+ Encaps curr = _encapsCache;
+ if(curr != null)
+ {
+ curr.reset();
+ _encapsCache = _encapsCache.next;
+ }
+ else
+ {
+ curr = new Encaps();
+ }
+ curr.next = _encapsStack;
+ _encapsStack = curr;
+
+ _encapsStack.format = format;
+ _encapsStack.setEncoding(encoding);
+ _encapsStack.start = _buf.b.position();
+
+ writeInt(0); // Placeholder for the encapsulation length.
+ _encapsStack.encoding.write__(this);
+ }
+
+ /// <summary>
+ /// Ends the previous encapsulation.
+ /// </summary>
+ public void endEncapsulation()
+ {
+ Debug.Assert(_encapsStack != null);
+
+ // Size includes size and version.
+ int start = _encapsStack.start;
+ int sz = _buf.size() - start;
+ _buf.b.putInt(start, sz);
+
+ Encaps curr = _encapsStack;
+ _encapsStack = curr.next;
+ curr.next = _encapsCache;
+ _encapsCache = curr;
+ _encapsCache.reset();
+ }
+
+ /// <summary>
+ /// Writes an empty encapsulation using the given encoding version.
+ /// </summary>
+ /// <param name="encoding">The encoding version of the encapsulation.</param>
+ public void writeEmptyEncapsulation(EncodingVersion encoding)
+ {
+ Protocol.checkSupportedEncoding(encoding);
+ writeInt(6); // Size
+ encoding.write__(this);
+ }
+
+ /// <summary>
+ /// Writes a pre-encoded encapsulation.
+ /// </summary>
+ /// <param name="v">The encapsulation data.</param>
+ public void writeEncapsulation(byte[] v)
+ {
+ if(v.Length < 6)
+ {
+ throw new EncapsulationException();
+ }
+ expand(v.Length);
+ _buf.b.put(v);
+ }
+
+ /// <summary>
+ /// Determines the current encoding version.
+ /// </summary>
+ /// <returns>The encoding version.</returns>
+ public EncodingVersion getEncoding()
+ {
+ return _encapsStack != null ? _encapsStack.encoding : _encoding;
+ }
+
+ /// <summary>
+ /// Marks the start of a new slice for an Ice object or user exception.
+ /// </summary>
+ /// <param name="typeId">The Slice type ID corresponding to this slice.</param>
+ /// <param name="compactId">The Slice compact type ID corresponding to this slice or -1 if no compact ID
+ /// is defined for the type ID.</param>
+ /// <param name="last">True if this is the last slice, false otherwise.</param>
+ public void startSlice(string typeId, int compactId, bool last)
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.startSlice(typeId, compactId, last);
+ }
+
+ /// <summary>
+ /// Marks the end of a slice for an Ice object or user exception.
+ /// </summary>
+ public void endSlice()
+ {
+ Debug.Assert(_encapsStack != null && _encapsStack.encoder != null);
+ _encapsStack.encoder.endSlice();
+ }
+
+ /// <summary>
+ /// Writes the state of Slice classes whose index was previously written with writeObject() to the stream.
+ /// </summary>
+ public void writePendingObjects()
+ {
+ if(_encapsStack != null && _encapsStack.encoder != null)
+ {
+ _encapsStack.encoder.writePendingObjects();
+ }
+ else if(_encapsStack != null ?
+ _encapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0))
+ {
+ //
+ // If using the 1.0 encoding and no objects were written, we
+ // still write an empty sequence for pending objects if
+ // requested (i.e.: if this is called).
+ //
+ // This is required by the 1.0 encoding, even if no objects
+ // are written we do marshal an empty sequence if marshaled
+ // data types use classes.
+ //
+ writeSize(0);
+ }
+ }
+
+ /// <summary>
+ /// Writes a size to the stream.
+ /// </summary>
+ /// <param name="v">The size to write.</param>
+ public void writeSize(int v)
+ {
+ if(v > 254)
+ {
+ expand(5);
+ _buf.b.put((byte)255);
+ _buf.b.putInt(v);
+ }
+ else
+ {
+ expand(1);
+ _buf.b.put((byte)v);
+ }
+ }
+
+ /// <summary>
+ /// Returns the current position and allocates four bytes for a fixed-length (32-bit) size value.
+ /// </summary>
+ public int startSize()
+ {
+ int pos = _buf.b.position();
+ writeInt(0); // Placeholder for 32-bit size
+ return pos;
+ }
+
+ /// <summary>
+ /// Computes the amount of data written since the previous call to startSize and writes that value
+ /// at the saved position.
+ /// </summary>
+ /// <param name="pos">The saved position.</param>
+ public void endSize(int pos)
+ {
+ Debug.Assert(pos >= 0);
+ rewriteInt(_buf.b.position() - pos - 4, pos);
+ }
+
+ /// <summary>
+ /// Writes a blob of bytes to the stream.
+ /// </summary>
+ /// <param name="v">The byte array to be written. All of the bytes in the array are written.</param>
+ public void writeBlob(byte[] v)
+ {
+ if(v == null)
+ {
+ return;
+ }
+ expand(v.Length);
+ _buf.b.put(v);
+ }
+
+ /// <summary>
+ /// Writes a blob of bytes to the stream.
+ /// </summary>
+ /// <param name="v">The byte array to be written. All of the bytes in the array are written.</param>
+ /// <param name="off">The offset into the byte array from which to copy.</param>
+ /// <param name="len">The number of bytes from the byte array to copy.</param>
+ public void writeBlob(byte[] v, int off, int len)
+ {
+ if(v == null)
+ {
+ return;
+ }
+ expand(len);
+ _buf.b.put(v, off, len);
+ }
+
+ /// <summary>
+ /// Write the header information for an optional value.
+ /// </summary>
+ /// <param name="tag">The numeric tag associated with the value.</param>
+ /// <param name="format">The optional format of the value.</param>
+ public bool writeOptional(int tag, Ice.OptionalFormat format)
+ {
+ Debug.Assert(_encapsStack != null);
+ if(_encapsStack.encoder != null)
+ {
+ return _encapsStack.encoder.writeOptional(tag, format);
+ }
+ else
+ {
+ return writeOptionalImpl(tag, format);
+ }
+ }
+
+ /// <summary>
+ /// Writes a byte to the stream.
+ /// </summary>
+ /// <param name="v">The byte to write to the stream.</param>
+ public void writeByte(byte v)
+ {
+ expand(1);
+ _buf.b.put(v);
+ }
+
+ /// <summary>
+ /// Writes an optional byte to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional byte to write to the stream.</param>
+ public void writeByte(int tag, Ice.Optional<byte> v)
+ {
+ if(v.HasValue)
+ {
+ writeByte(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional byte to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The byte to write to the stream.</param>
+ public void writeByte(int tag, byte v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F1))
+ {
+ writeByte(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a byte to the stream at the given position. The current position of the stream is not modified.
+ /// </summary>
+ /// <param name="v">The byte to write to the stream.</param>
+ /// <param name="dest">The position at which to store the byte in the buffer.</param>
+ public void rewriteByte(byte v, int dest)
+ {
+ _buf.b.put(dest, v);
+ }
+
+ /// <summary>
+ /// Writes a byte sequence to the stream.
+ /// </summary>
+ /// <param name="v">The byte sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeByteSeq(byte[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length);
+ _buf.b.put(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a byte sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeByteSeq(int count, IEnumerable<byte> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<byte> value = v as List<byte>;
+ if(value != null)
+ {
+ writeByteSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<byte> value = v as LinkedList<byte>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count);
+ IEnumerator<byte> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.put(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<byte> value = v as Queue<byte>;
+ if(value != null)
+ {
+ writeByteSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<byte> value = v as Stack<byte>;
+ if(value != null)
+ {
+ writeByteSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count);
+ foreach(byte b in v)
+ {
+ _buf.b.put(b);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional byte sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional byte sequence to write to the stream.</param>
+ public void writeByteSeq(int tag, Ice.Optional<byte[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeByteSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional byte sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional byte sequence.</param>
+ public void writeByteSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<byte>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeByteSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional byte sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The byte sequence to write to the stream.</param>
+ public void writeByteSeq(int tag, byte[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeByteSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional byte sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the byte sequence.</param>
+ public void writeByteSeq(int tag, int count, IEnumerable<byte> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeByteSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a serializable object to the stream.
+ /// </summary>
+ /// <param name="o">The serializable object to write.</param>
+ public void writeSerializable(object o)
+ {
+#if !COMPACT && !SILVERLIGHT
+ if(o == null)
+ {
+ writeSize(0);
+ return;
+ }
+ try
+ {
+ IceInternal.OutputStreamWrapper w = new IceInternal.OutputStreamWrapper(this);
+ IFormatter f = new BinaryFormatter();
+ f.Serialize(w, o);
+ w.Close();
+ }
+ catch(System.Exception ex)
+ {
+ throw new Ice.MarshalException("cannot serialize object:", ex);
+ }
+#else
+ throw new Ice.MarshalException("serialization not supported");
+#endif
+ }
+
+ /// <summary>
+ /// Writes a boolean to the stream.
+ /// </summary>
+ /// <param name="v">The boolean to write to the stream.</param>
+ public void writeBool(bool v)
+ {
+ expand(1);
+ _buf.b.put(v ? (byte)1 : (byte)0);
+ }
+
+ /// <summary>
+ /// Writes an optional boolean to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional boolean to write to the stream.</param>
+ public void writeBool(int tag, Ice.Optional<bool> v)
+ {
+ if(v.HasValue)
+ {
+ writeBool(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional boolean to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The boolean to write to the stream.</param>
+ public void writeBool(int tag, bool v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F1))
+ {
+ writeBool(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a boolean to the stream at the given position. The current position of the stream is not modified.
+ /// </summary>
+ /// <param name="v">The boolean to write to the stream.</param>
+ /// <param name="dest">The position at which to store the boolean in the buffer.</param>
+ public void rewriteBool(bool v, int dest)
+ {
+ _buf.b.put(dest, v ? (byte)1 : (byte)0);
+ }
+
+ /// <summary>
+ /// Writes a boolean sequence to the stream.
+ /// </summary>
+ /// <param name="v">The boolean sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeBoolSeq(bool[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length);
+ _buf.b.putBoolSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a boolean sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeBoolSeq(int count, IEnumerable<bool> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<bool> value = v as List<bool>;
+ if(value != null)
+ {
+ writeBoolSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<bool> value = v as LinkedList<bool>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count);
+ IEnumerator<bool> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putBool(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<bool> value = v as Queue<bool>;
+ if(value != null)
+ {
+ writeBoolSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<bool> value = v as Stack<bool>;
+ if(value != null)
+ {
+ writeBoolSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count);
+ foreach(bool b in v)
+ {
+ _buf.b.putBool(b);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional boolean sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional boolean sequence to write to the stream.</param>
+ public void writeBoolSeq(int tag, Ice.Optional<bool[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeBoolSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional boolean sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional boolean sequence.</param>
+ public void writeBoolSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<bool>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeBoolSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional boolean sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The boolean sequence to write to the stream.</param>
+ public void writeBoolSeq(int tag, bool[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeBoolSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional boolean sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the boolean sequence.</param>
+ public void writeBoolSeq(int tag, int count, IEnumerable<bool> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeBoolSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a short to the stream.
+ /// </summary>
+ /// <param name="v">The short to write to the stream.</param>
+ public void writeShort(short v)
+ {
+ expand(2);
+ _buf.b.putShort(v);
+ }
+
+ /// <summary>
+ /// Writes an optional short to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional short to write to the stream.</param>
+ public void writeShort(int tag, Ice.Optional<short> v)
+ {
+ if(v.HasValue)
+ {
+ writeShort(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional short to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The short to write to the stream.</param>
+ public void writeShort(int tag, short v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F2))
+ {
+ writeShort(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a short sequence to the stream.
+ /// </summary>
+ /// <param name="v">The short sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeShortSeq(short[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length * 2);
+ _buf.b.putShortSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a short sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeShortSeq(int count, IEnumerable<short> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<short> value = v as List<short>;
+ if(value != null)
+ {
+ writeShortSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<short> value = v as LinkedList<short>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count * 2);
+ IEnumerator<short> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putShort(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<short> value = v as Queue<short>;
+ if(value != null)
+ {
+ writeShortSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<short> value = v as Stack<short>;
+ if(value != null)
+ {
+ writeShortSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count * 2);
+ foreach(short s in v)
+ {
+ _buf.b.putShort(s);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional short sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional short sequence to write to the stream.</param>
+ public void writeShortSeq(int tag, Ice.Optional<short[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeShortSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional short sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional short sequence.</param>
+ public void writeShortSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<short>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(count == 0 ? 1 : count * 2 + (count > 254 ? 5 : 1));
+ writeShortSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional short sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The short sequence to write to the stream.</param>
+ public void writeShortSeq(int tag, short[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || v.Length == 0 ? 1 : v.Length * 2 + (v.Length > 254 ? 5 : 1));
+ writeShortSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional short sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the short sequence.</param>
+ public void writeShortSeq(int tag, int count, IEnumerable<short> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || count == 0 ? 1 : count * 2 + (count > 254 ? 5 : 1));
+ writeShortSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an int to the stream.
+ /// </summary>
+ /// <param name="v">The int to write to the stream.</param>
+ public void writeInt(int v)
+ {
+ expand(4);
+ _buf.b.putInt(v);
+ }
+
+ /// <summary>
+ /// Writes an optional int to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional int to write to the stream.</param>
+ public void writeInt(int tag, Ice.Optional<int> v)
+ {
+ if(v.HasValue)
+ {
+ writeInt(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional int to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The int to write to the stream.</param>
+ public void writeInt(int tag, int v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F4))
+ {
+ writeInt(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an int to the stream at the given position. The current position of the stream is not modified.
+ /// </summary>
+ /// <param name="v">The int to write to the stream.</param>
+ /// <param name="dest">The position at which to store the int in the buffer.</param>
+ public void rewriteInt(int v, int dest)
+ {
+ _buf.b.putInt(dest, v);
+ }
+
+ /// <summary>
+ /// Writes an int sequence to the stream.
+ /// </summary>
+ /// <param name="v">The int sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeIntSeq(int[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length * 4);
+ _buf.b.putIntSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an int sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeIntSeq(int count, IEnumerable<int> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<int> value = v as List<int>;
+ if(value != null)
+ {
+ writeIntSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<int> value = v as LinkedList<int>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count * 4);
+ IEnumerator<int> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putInt(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<int> value = v as Queue<int>;
+ if(value != null)
+ {
+ writeIntSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<int> value = v as Stack<int>;
+ if(value != null)
+ {
+ writeIntSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count * 4);
+ foreach(int i in v)
+ {
+ _buf.b.putInt(i);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional int sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional int sequence to write to the stream.</param>
+ public void writeIntSeq(int tag, Ice.Optional<int[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeIntSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional int sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional byte sequence.</param>
+ public void writeIntSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<int>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
+ writeIntSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional int sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The int sequence to write to the stream.</param>
+ public void writeIntSeq(int tag, int[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || v.Length == 0 ? 1 : v.Length * 4 + (v.Length > 254 ? 5 : 1));
+ writeIntSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional int sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the int sequence.</param>
+ public void writeIntSeq(int tag, int count, IEnumerable<int> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
+ writeIntSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a long to the stream.
+ /// </summary>
+ /// <param name="v">The long to write to the stream.</param>
+ public void writeLong(long v)
+ {
+ expand(8);
+ _buf.b.putLong(v);
+ }
+
+ /// <summary>
+ /// Writes an optional long to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional long to write to the stream.</param>
+ public void writeLong(int tag, Ice.Optional<long> v)
+ {
+ if(v.HasValue)
+ {
+ writeLong(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional long to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The long to write to the stream.</param>
+ public void writeLong(int tag, long v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F8))
+ {
+ writeLong(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a long sequence to the stream.
+ /// </summary>
+ /// <param name="v">The long sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeLongSeq(long[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length * 8);
+ _buf.b.putLongSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a long sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeLongSeq(int count, IEnumerable<long> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<long> value = v as List<long>;
+ if(value != null)
+ {
+ writeLongSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<long> value = v as LinkedList<long>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count * 8);
+ IEnumerator<long> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putLong(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<long> value = v as Queue<long>;
+ if(value != null)
+ {
+ writeLongSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<long> value = v as Stack<long>;
+ if(value != null)
+ {
+ writeLongSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count * 8);
+ foreach(long l in v)
+ {
+ _buf.b.putLong(l);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional long sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional long sequence to write to the stream.</param>
+ public void writeLongSeq(int tag, Ice.Optional<long[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeLongSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional long sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional long sequence.</param>
+ public void writeLongSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<long>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
+ writeLongSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional long sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The long sequence to write to the stream.</param>
+ public void writeLongSeq(int tag, long[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || v.Length == 0 ? 1 : v.Length * 8 + (v.Length > 254 ? 5 : 1));
+ writeLongSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional long sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the long sequence.</param>
+ public void writeLongSeq(int tag, int count, IEnumerable<long> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
+ writeLongSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a float to the stream.
+ /// </summary>
+ /// <param name="v">The float to write to the stream.</param>
+ public void writeFloat(float v)
+ {
+ expand(4);
+ _buf.b.putFloat(v);
+ }
+
+ /// <summary>
+ /// Writes an optional float to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional float to write to the stream.</param>
+ public void writeFloat(int tag, Ice.Optional<float> v)
+ {
+ if(v.HasValue)
+ {
+ writeFloat(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional float to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The float to write to the stream.</param>
+ public void writeFloat(int tag, float v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F4))
+ {
+ writeFloat(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a float sequence to the stream.
+ /// </summary>
+ /// <param name="v">The float sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeFloatSeq(float[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length * 4);
+ _buf.b.putFloatSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a float sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeFloatSeq(int count, IEnumerable<float> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<float> value = v as List<float>;
+ if(value != null)
+ {
+ writeFloatSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<float> value = v as LinkedList<float>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count * 4);
+ IEnumerator<float> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putFloat(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<float> value = v as Queue<float>;
+ if(value != null)
+ {
+ writeFloatSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<float> value = v as Stack<float>;
+ if(value != null)
+ {
+ writeFloatSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count * 4);
+ foreach(float f in v)
+ {
+ _buf.b.putFloat(f);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional float sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional float sequence to write to the stream.</param>
+ public void writeFloatSeq(int tag, Ice.Optional<float[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeFloatSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional float sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional float sequence.</param>
+ public void writeFloatSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<float>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
+ writeFloatSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional float sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The float sequence to write to the stream.</param>
+ public void writeFloatSeq(int tag, float[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || v.Length == 0 ? 1 : v.Length * 4 + (v.Length > 254 ? 5 : 1));
+ writeFloatSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional float sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the float sequence.</param>
+ public void writeFloatSeq(int tag, int count, IEnumerable<float> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || count == 0 ? 1 : count * 4 + (count > 254 ? 5 : 1));
+ writeFloatSeq(count, v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a double to the stream.
+ /// </summary>
+ /// <param name="v">The double to write to the stream.</param>
+ public void writeDouble(double v)
+ {
+ expand(8);
+ _buf.b.putDouble(v);
+ }
+
+ /// <summary>
+ /// Writes an optional double to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional double to write to the stream.</param>
+ public void writeDouble(int tag, Ice.Optional<double> v)
+ {
+ if(v.HasValue)
+ {
+ writeDouble(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional double to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The double to write to the stream.</param>
+ public void writeDouble(int tag, double v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.F8))
+ {
+ writeDouble(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a double sequence to the stream.
+ /// </summary>
+ /// <param name="v">The double sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeDoubleSeq(double[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ expand(v.Length * 8);
+ _buf.b.putDoubleSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a double sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeDoubleSeq(int count, IEnumerable<double> v)
+ {
+ if(count == 0)
+ {
+ writeSize(0);
+ return;
+ }
+
+ {
+ List<double> value = v as List<double>;
+ if(value != null)
+ {
+ writeDoubleSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ LinkedList<double> value = v as LinkedList<double>;
+ if(value != null)
+ {
+ writeSize(count);
+ expand(count * 8);
+ IEnumerator<double> i = v.GetEnumerator();
+ while(i.MoveNext())
+ {
+ _buf.b.putDouble(i.Current);
+ }
+ return;
+ }
+ }
+
+ {
+ Queue<double> value = v as Queue<double>;
+ if(value != null)
+ {
+ writeDoubleSeq(value.ToArray());
+ return;
+ }
+ }
+
+ {
+ Stack<double> value = v as Stack<double>;
+ if (value != null)
+ {
+ writeDoubleSeq(value.ToArray());
+ return;
+ }
+ }
+
+ writeSize(count);
+ expand(count * 8);
+ foreach(double d in v)
+ {
+ _buf.b.putDouble(d);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional double sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional double sequence to write to the stream.</param>
+ public void writeDoubleSeq(int tag, Ice.Optional<double[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeDoubleSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional double sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional double sequence.</param>
+ public void writeDoubleSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<double>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
+ writeDoubleSeq(count, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional double sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The double sequence to write to the stream.</param>
+ public void writeDoubleSeq(int tag, double[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || v.Length == 0 ? 1 : v.Length * 8 + (v.Length > 254 ? 5 : 1));
+ writeDoubleSeq(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional double sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the double sequence.</param>
+ public void writeDoubleSeq(int tag, int count, IEnumerable<double> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeSize(v == null || count == 0 ? 1 : count * 8 + (count > 254 ? 5 : 1));
+ writeDoubleSeq(count, v);
+ }
+ }
+
+ private static System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding(false, true);
+
+ /// <summary>
+ /// Writes a string to the stream.
+ /// </summary>
+ /// <param name="v">The string to write to the stream. Passing null causes
+ /// an empty string to be written to the stream.</param>
+ public void writeString(string v)
+ {
+ if(v == null || v.Length == 0)
+ {
+ writeSize(0);
+ return;
+ }
+ byte[] arr = utf8.GetBytes(v);
+ writeSize(arr.Length);
+ expand(arr.Length);
+ _buf.b.put(arr);
+ }
+
+ /// <summary>
+ /// Writes an optional string to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional string to write to the stream.</param>
+ public void writeString(int tag, Ice.Optional<string> v)
+ {
+ if(v.HasValue)
+ {
+ writeString(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional string to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The string to write to the stream.</param>
+ public void writeString(int tag, string v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.VSize))
+ {
+ writeString(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a string sequence to the stream.
+ /// </summary>
+ /// <param name="v">The string sequence to write to the stream.
+ /// Passing null causes an empty sequence to be written to the stream.</param>
+ public void writeStringSeq(string[] v)
+ {
+ if(v == null)
+ {
+ writeSize(0);
+ }
+ else
+ {
+ writeSize(v.Length);
+ for(int i = 0; i < v.Length; i++)
+ {
+ writeString(v[i]);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Writes a string sequence to the stream.
+ /// </summary>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the container holding the sequence.</param>
+ public void writeStringSeq(int count, IEnumerable<string> v)
+ {
+ writeSize(count);
+ if(count != 0)
+ {
+ foreach(string s in v)
+ {
+ writeString(s);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional string sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional string sequence to write to the stream.</param>
+ public void writeStringSeq(int tag, Ice.Optional<String[]> v)
+ {
+ if(v.HasValue)
+ {
+ writeStringSeq(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional string sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the optional string sequence.</param>
+ public void writeStringSeq<T>(int tag, int count, Ice.Optional<T> v)
+ where T : IEnumerable<string>
+ {
+ if(v.HasValue && writeOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ int pos = startSize();
+ writeStringSeq(count, v.Value);
+ endSize(pos);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional string sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The string sequence to write to the stream.</param>
+ public void writeStringSeq(int tag, string[] v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ int pos = startSize();
+ writeStringSeq(v);
+ endSize(pos);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional string sequence to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="count">The number of elements in the sequence.</param>
+ /// <param name="v">An enumerator for the string sequence.</param>
+ public void writeStringSeq(int tag, int count, IEnumerable<string> v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ int pos = startSize();
+ writeStringSeq(count, v);
+ endSize(pos);
+ }
+ }
+
+ /// <summary>
+ /// Writes a proxy to the stream.
+ /// </summary>
+ /// <param name="v">The proxy to write.</param>
+ public void writeProxy(Ice.ObjectPrx v)
+ {
+ if(v != null)
+ {
+ v.write__(this);
+ }
+ else
+ {
+ Identity ident = new Identity();
+ ident.write__(this);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional proxy to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional proxy to write.</param>
+ public void writeProxy(int tag, Ice.Optional<Ice.ObjectPrx> v)
+ {
+ if(v.HasValue)
+ {
+ writeProxy(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional proxy to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The proxy to write.</param>
+ public void writeProxy(int tag, Ice.ObjectPrx v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.FSize))
+ {
+ int pos = startSize();
+ writeProxy(v);
+ endSize(pos);
+ }
+ }
+
+ /// <summary>
+ /// Writes an enumerated value.
+ /// </summary>
+ /// <param name="v">The enumerator.</param>
+ /// <param name="maxValue">The maximum enumerator value in the definition.</param>
+ public void writeEnum(int v, int maxValue)
+ {
+ if(isEncoding_1_0())
+ {
+ if(maxValue < 127)
+ {
+ writeByte((byte)v);
+ }
+ else if(maxValue < 32767)
+ {
+ writeShort((short)v);
+ }
+ else
+ {
+ writeInt(v);
+ }
+ }
+ else
+ {
+ writeSize(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional enumerator to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The enumerator.</param>
+ /// <param name="maxValue">The maximum enumerator value in the definition.</param>
+ public void writeEnum(int tag, int v, int maxValue)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.Size))
+ {
+ writeEnum(v, maxValue);
+ }
+ }
+
+ /// <summary>
+ /// Writes a Slice value to the stream.
+ /// </summary>
+ /// <param name="v">The value to write. This method writes the index of an instance; the state of the value is
+ /// written once writePendingObjects() is called.</param>
+ public void writeObject(Ice.Object v)
+ {
+ initEncaps();
+ _encapsStack.encoder.writeObject(v);
+ }
+
+ /// <summary>
+ /// Writes an optional value to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The optional value to write.</param>
+ public void writeObject<T>(int tag, Ice.Optional<T> v)
+ where T : Ice.Object
+ {
+ if(v.HasValue)
+ {
+ writeObject(tag, v.Value);
+ }
+ }
+
+ /// <summary>
+ /// Writes an optional value to the stream.
+ /// </summary>
+ /// <param name="tag">The optional tag.</param>
+ /// <param name="v">The value to write.</param>
+ public void writeObject(int tag, Ice.Object v)
+ {
+ if(writeOptional(tag, Ice.OptionalFormat.Class))
+ {
+ writeObject(v);
+ }
+ }
+
+ /// <summary>
+ /// Writes a user exception to the stream.
+ /// </summary>
+ /// <param name="v">The user exception to write.</param>
+ public void writeException(Ice.UserException v)
+ {
+ initEncaps();
+ _encapsStack.encoder.writeException(v);
+ }
+
+ private bool writeOptionalImpl(int tag, Ice.OptionalFormat format)
+ {
+ if(isEncoding_1_0())
+ {
+ return false; // Optional members aren't supported with the 1.0 encoding.
+ }
+
+ int v = (int)format;
+ if(tag < 30)
+ {
+ v |= tag << 3;
+ writeByte((byte)v);
+ }
+ else
+ {
+ v |= 0x0F0; // tag = 30
+ writeByte((byte)v);
+ writeSize(tag);
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Determines the current position in the stream.
+ /// </summary>
+ /// <returns>The current position.</returns>
+ public int pos()
+ {
+ return _buf.b.position();
+ }
+
+ /// <summary>
+ /// Sets the current position in the stream.
+ /// </summary>
+ /// <param name="n">The new position.</param>
+ public void pos(int n)
+ {
+ _buf.b.position(n);
+ }
+
+ /// <summary>
+ /// Determines the current size of the stream.
+ /// </summary>
+ /// <returns>The current size.</returns>
+ public int size()
+ {
+ return _buf.size();
+ }
+
+ /// <summary>
+ /// Determines whether the stream is empty.
+ /// </summary>
+ /// <returns>True if no data has been written yet, false otherwise.</returns>
+ public bool isEmpty()
+ {
+ return _buf.empty();
+ }
+
+ /// <summary>
+ /// Expand the stream to accept more data.
+ /// </summary>
+ /// <param name="n">The number of bytes to accommodate in the stream.</param>
+ public void expand(int n)
+ {
+ _buf.expand(n);
+ }
+
+ private IceInternal.Instance instance_;
+ private IceInternal.Buffer _buf;
+ private object _closure;
+ private FormatType _format;
+
+ private enum SliceType { NoSlice, ObjectSlice, ExceptionSlice }
+
+ abstract private class EncapsEncoder
+ {
+ protected EncapsEncoder(OutputStream stream, Encaps encaps)
+ {
+ _stream = stream;
+ _encaps = encaps;
+ _typeIdIndex = 0;
+ _marshaledMap = new Dictionary<Ice.Object, int>();
+ }
+
+ internal abstract void writeObject(Ice.Object v);
+ internal abstract void writeException(Ice.UserException v);
+
+ internal abstract void startInstance(SliceType type, Ice.SlicedData data);
+ internal abstract void endInstance();
+ internal abstract void startSlice(string typeId, int compactId, bool last);
+ internal abstract void endSlice();
+
+ internal virtual bool writeOptional(int tag, Ice.OptionalFormat format)
+ {
+ return false;
+ }
+
+ internal virtual void writePendingObjects()
+ {
+ }
+
+ protected int registerTypeId(string typeId)
+ {
+ if(_typeIdMap == null)
+ {
+ _typeIdMap = new Dictionary<string, int>();
+ }
+
+ int p;
+ if(_typeIdMap.TryGetValue(typeId, out p))
+ {
+ return p;
+ }
+ else
+ {
+ _typeIdMap.Add(typeId, ++_typeIdIndex);
+ return -1;
+ }
+ }
+
+ protected readonly OutputStream _stream;
+ protected readonly Encaps _encaps;
+
+ // Encapsulation attributes for object marshalling.
+ protected readonly Dictionary<Ice.Object, int> _marshaledMap;
+
+ // Encapsulation attributes for object marshalling.
+ private Dictionary<string, int> _typeIdMap;
+ private int _typeIdIndex;
+ }
+
+ private sealed class EncapsEncoder10 : EncapsEncoder
+ {
+ internal EncapsEncoder10(OutputStream stream, Encaps encaps) : base(stream, encaps)
+ {
+ _sliceType = SliceType.NoSlice;
+ _objectIdIndex = 0;
+ _toBeMarshaledMap = new Dictionary<Ice.Object, int>();
+ }
+
+ internal override void writeObject(Ice.Object v)
+ {
+ //
+ // Object references are encoded as a negative integer in 1.0.
+ //
+ if(v != null)
+ {
+ _stream.writeInt(-registerObject(v));
+ }
+ else
+ {
+ _stream.writeInt(0);
+ }
+ }
+
+ internal override void writeException(Ice.UserException v)
+ {
+ //
+ // User exception with the 1.0 encoding start with a bool
+ // flag that indicates whether or not the exception uses
+ // classes.
+ //
+ // This allows reading the pending objects even if some part of
+ // the exception was sliced.
+ //
+ bool usesClasses = v.usesClasses__();
+ _stream.writeBool(usesClasses);
+ v.write__(_stream);
+ if(usesClasses)
+ {
+ writePendingObjects();
+ }
+ }
+
+ internal override void startInstance(SliceType sliceType, Ice.SlicedData sliceData)
+ {
+ _sliceType = sliceType;
+ }
+
+ internal override void endInstance()
+ {
+ if(_sliceType == SliceType.ObjectSlice)
+ {
+ //
+ // Write the Object slice.
+ //
+ startSlice(Ice.ObjectImpl.ice_staticId(), -1, true);
+ _stream.writeSize(0); // For compatibility with the old AFM.
+ endSlice();
+ }
+ _sliceType = SliceType.NoSlice;
+ }
+
+ internal override void startSlice(string typeId, int compactId, bool last)
+ {
+ //
+ // For object slices, encode a bool to indicate how the type ID
+ // is encoded and the type ID either as a string or index. For
+ // exception slices, always encode the type ID as a string.
+ //
+ if(_sliceType == SliceType.ObjectSlice)
+ {
+ int index = registerTypeId(typeId);
+ if(index < 0)
+ {
+ _stream.writeBool(false);
+ _stream.writeString(typeId);
+ }
+ else
+ {
+ _stream.writeBool(true);
+ _stream.writeSize(index);
+ }
+ }
+ else
+ {
+ _stream.writeString(typeId);
+ }
+
+ _stream.writeInt(0); // Placeholder for the slice length.
+
+ _writeSlice = _stream.pos();
+ }
+
+ internal override void endSlice()
+ {
+ //
+ // Write the slice length.
+ //
+ int sz = _stream.pos() - _writeSlice + 4;
+ _stream.rewriteInt(sz, _writeSlice - 4);
+ }
+
+ internal override void writePendingObjects()
+ {
+ while(_toBeMarshaledMap.Count > 0)
+ {
+ //
+ // Consider the to be marshalled objects as marshalled now,
+ // this is necessary to avoid adding again the "to be
+ // marshalled objects" into _toBeMarshaledMap while writing
+ // objects.
+ //
+ foreach(KeyValuePair<Ice.Object, int> e in _toBeMarshaledMap)
+ {
+ _marshaledMap.Add(e.Key, e.Value);
+ }
+
+ Dictionary<Ice.Object, int> savedMap = _toBeMarshaledMap;
+ _toBeMarshaledMap = new Dictionary<Ice.Object, int>();
+ _stream.writeSize(savedMap.Count);
+ foreach(KeyValuePair<Ice.Object, int> p in savedMap)
+ {
+ //
+ // Ask the instance to marshal itself. Any new class
+ // instances that are triggered by the classes marshaled
+ // are added to toBeMarshaledMap.
+ //
+ _stream.writeInt(p.Value);
+
+ try
+ {
+ p.Key.ice_preMarshal();
+ }
+ catch(System.Exception ex)
+ {
+ string s = "exception raised by ice_preMarshal:\n" + ex;
+ _stream.instance().initializationData().logger.warning(s);
+ }
+
+ p.Key.write__(_stream);
+ }
+ }
+ _stream.writeSize(0); // Zero marker indicates end of sequence of sequences of instances.
+ }
+
+ private int registerObject(Ice.Object v)
+ {
+ Debug.Assert(v != null);
+
+ //
+ // Look for this instance in the to-be-marshaled map.
+ //
+ int p;
+ if(_toBeMarshaledMap.TryGetValue(v, out p))
+ {
+ return p;
+ }
+
+ //
+ // Didn't find it, try the marshaled map next.
+ //
+ if(_marshaledMap.TryGetValue(v, out p))
+ {
+ return p;
+ }
+
+ //
+ // We haven't seen this instance previously, create a new
+ // index, and insert it into the to-be-marshaled map.
+ //
+ _toBeMarshaledMap.Add(v, ++_objectIdIndex);
+ return _objectIdIndex;
+ }
+
+ // Instance attributes
+ private SliceType _sliceType;
+
+ // Slice attributes
+ private int _writeSlice; // Position of the slice data members
+
+ // Encapsulation attributes for object marshalling.
+ private int _objectIdIndex;
+ private Dictionary<Ice.Object, int> _toBeMarshaledMap;
+ }
+
+ private sealed class EncapsEncoder11 : EncapsEncoder
+ {
+ internal EncapsEncoder11(OutputStream stream, Encaps encaps) : base(stream, encaps)
+ {
+ _current = null;
+ _objectIdIndex = 1;
+ }
+
+ internal override void writeObject(Ice.Object v)
+ {
+ if(v == null)
+ {
+ _stream.writeSize(0);
+ }
+ else if(_current != null && _encaps.format == Ice.FormatType.SlicedFormat)
+ {
+ if(_current.indirectionTable == null)
+ {
+ _current.indirectionTable = new List<Ice.Object>();
+ _current.indirectionMap = new Dictionary<Ice.Object, int>();
+ }
+
+ //
+ // If writing an object within a slice and using the sliced
+ // format, write an index from the object indirection table.
+ //
+ int index;
+ if(!_current.indirectionMap.TryGetValue(v, out index))
+ {
+ _current.indirectionTable.Add(v);
+ int idx = _current.indirectionTable.Count; // Position + 1 (0 is reserved for nil)
+ _current.indirectionMap.Add(v, idx);
+ _stream.writeSize(idx);
+ }
+ else
+ {
+ _stream.writeSize(index);
+ }
+ }
+ else
+ {
+ writeInstance(v); // Write the instance or a reference if already marshaled.
+ }
+ }
+
+ internal override void writeException(Ice.UserException v)
+ {
+ v.write__(_stream);
+ }
+
+ internal override void startInstance(SliceType sliceType, Ice.SlicedData data)
+ {
+ if(_current == null)
+ {
+ _current = new InstanceData(null);
+ }
+ else
+ {
+ _current = _current.next == null ? new InstanceData(_current) : _current.next;
+ }
+ _current.sliceType = sliceType;
+ _current.firstSlice = true;
+
+ if(data != null)
+ {
+ writeSlicedData(data);
+ }
+ }
+
+ internal override void endInstance()
+ {
+ _current = _current.previous;
+ }
+
+ internal override void startSlice(string typeId, int compactId, bool last)
+ {
+ Debug.Assert((_current.indirectionTable == null || _current.indirectionTable.Count == 0) &&
+ (_current.indirectionMap == null || _current.indirectionMap.Count == 0));
+
+ _current.sliceFlagsPos = _stream.pos();
+
+ _current.sliceFlags = (byte)0;
+ if(_encaps.format == Ice.FormatType.SlicedFormat)
+ {
+ //
+ // Encode the slice size if using the sliced format.
+ //
+ _current.sliceFlags |= Protocol.FLAG_HAS_SLICE_SIZE;
+ }
+ if(last)
+ {
+ _current.sliceFlags |= Protocol.FLAG_IS_LAST_SLICE; // This is the last slice.
+ }
+
+ _stream.writeByte((byte)0); // Placeholder for the slice flags
+
+ //
+ // For object slices, encode the flag and the type ID either as a
+ // string or index. For exception slices, always encode the type
+ // ID a string.
+ //
+ if(_current.sliceType == SliceType.ObjectSlice)
+ {
+ //
+ // Encode the type ID (only in the first slice for the compact
+ // encoding).
+ //
+ if(_encaps.format == Ice.FormatType.SlicedFormat || _current.firstSlice)
+ {
+ if(compactId >= 0)
+ {
+ _current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_COMPACT;
+ _stream.writeSize(compactId);
+ }
+ else
+ {
+ int index = registerTypeId(typeId);
+ if(index < 0)
+ {
+ _current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_STRING;
+ _stream.writeString(typeId);
+ }
+ else
+ {
+ _current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_INDEX;
+ _stream.writeSize(index);
+ }
+ }
+ }
+ }
+ else
+ {
+ _stream.writeString(typeId);
+ }
+
+ if((_current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) != 0)
+ {
+ _stream.writeInt(0); // Placeholder for the slice length.
+ }
+
+ _current.writeSlice = _stream.pos();
+ _current.firstSlice = false;
+ }
+
+ internal override void endSlice()
+ {
+ //
+ // Write the optional member end marker if some optional members
+ // were encoded. Note that the optional members are encoded before
+ // the indirection table and are included in the slice size.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) != 0)
+ {
+ _stream.writeByte((byte)Protocol.OPTIONAL_END_MARKER);
+ }
+
+ //
+ // Write the slice length if necessary.
+ //
+ if((_current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) != 0)
+ {
+ int sz = _stream.pos() - _current.writeSlice + 4;
+ _stream.rewriteInt(sz, _current.writeSlice - 4);
+ }
+
+ //
+ // Only write the indirection table if it contains entries.
+ //
+ if(_current.indirectionTable != null && _current.indirectionTable.Count > 0)
+ {
+ Debug.Assert(_encaps.format == Ice.FormatType.SlicedFormat);
+ _current.sliceFlags |= Protocol.FLAG_HAS_INDIRECTION_TABLE;
+
+ //
+ // Write the indirection object table.
+ //
+ _stream.writeSize(_current.indirectionTable.Count);
+ foreach(Ice.Object v in _current.indirectionTable)
+ {
+ writeInstance(v);
+ }
+ _current.indirectionTable.Clear();
+ _current.indirectionMap.Clear();
+ }
+
+ //
+ // Finally, update the slice flags.
+ //
+ _stream.rewriteByte(_current.sliceFlags, _current.sliceFlagsPos);
+ }
+
+ internal override bool writeOptional(int tag, Ice.OptionalFormat format)
+ {
+ if(_current == null)
+ {
+ return _stream.writeOptionalImpl(tag, format);
+ }
+ else
+ {
+ if(_stream.writeOptionalImpl(tag, format))
+ {
+ _current.sliceFlags |= Protocol.FLAG_HAS_OPTIONAL_MEMBERS;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ private void writeSlicedData(Ice.SlicedData slicedData)
+ {
+ Debug.Assert(slicedData != null);
+
+ //
+ // We only remarshal preserved slices if we are using the sliced
+ // format. Otherwise, we ignore the preserved slices, which
+ // essentially "slices" the object into the most-derived type
+ // known by the sender.
+ //
+ if(_encaps.format != Ice.FormatType.SlicedFormat)
+ {
+ return;
+ }
+
+ foreach(Ice.SliceInfo info in slicedData.slices)
+ {
+ startSlice(info.typeId, info.compactId, info.isLastSlice);
+
+ //
+ // Write the bytes associated with this slice.
+ //
+ _stream.writeBlob(info.bytes);
+
+ if(info.hasOptionalMembers)
+ {
+ _current.sliceFlags |= Protocol.FLAG_HAS_OPTIONAL_MEMBERS;
+ }
+
+ //
+ // Make sure to also re-write the object indirection table.
+ //
+ if(info.objects != null && info.objects.Length > 0)
+ {
+ if(_current.indirectionTable == null)
+ {
+ _current.indirectionTable = new List<Ice.Object>();
+ _current.indirectionMap = new Dictionary<Ice.Object, int>();
+ }
+ foreach(Ice.Object o in info.objects)
+ {
+ _current.indirectionTable.Add(o);
+ }
+ }
+
+ endSlice();
+ }
+ }
+
+ private void writeInstance(Ice.Object v)
+ {
+ Debug.Assert(v != null);
+
+ //
+ // If the instance was already marshaled, just write it's ID.
+ //
+ int p;
+ if(_marshaledMap.TryGetValue(v, out p))
+ {
+ _stream.writeSize(p);
+ return;
+ }
+
+ //
+ // We haven't seen this instance previously, create a new ID,
+ // insert it into the marshaled map, and write the instance.
+ //
+ _marshaledMap.Add(v, ++_objectIdIndex);
+
+ try
+ {
+ v.ice_preMarshal();
+ }
+ catch(System.Exception ex)
+ {
+ string s = "exception raised by ice_preMarshal:\n" + ex;
+ _stream.instance().initializationData().logger.warning(s);
+ }
+
+ _stream.writeSize(1); // Object instance marker.
+ v.write__(_stream);
+ }
+
+ private sealed class InstanceData
+ {
+ internal InstanceData(InstanceData previous)
+ {
+ if(previous != null)
+ {
+ previous.next = this;
+ }
+ this.previous = previous;
+ this.next = null;
+ }
+
+ // Instance attributes
+ internal SliceType sliceType;
+ internal bool firstSlice;
+
+ // Slice attributes
+ internal byte sliceFlags;
+ internal int writeSlice; // Position of the slice data members
+ internal int sliceFlagsPos; // Position of the slice flags
+ internal List<Ice.Object> indirectionTable;
+ internal Dictionary<Ice.Object, int> indirectionMap;
+
+ internal InstanceData previous;
+ internal InstanceData next;
+ }
+
+ private InstanceData _current;
+
+ private int _objectIdIndex; // The ID of the next object to marhsal
+ }
+
+ private sealed class Encaps
+ {
+ internal void reset()
+ {
+ encoder = null;
+ }
+
+ internal void setEncoding(EncodingVersion encoding)
+ {
+ this.encoding = encoding;
+ encoding_1_0 = encoding.Equals(Ice.Util.Encoding_1_0);
+ }
+
+ internal int start;
+ internal EncodingVersion encoding;
+ internal bool encoding_1_0;
+ internal Ice.FormatType format = Ice.FormatType.DefaultFormat;
+
+ internal EncapsEncoder encoder;
+
+ internal Encaps next;
+ }
+
+ //
+ // The encoding version to use when there's no encapsulation to
+ // read from or write to. This is for example used to read message
+ // headers or when the user is using the streaming API with no
+ // encapsulation.
+ //
+ private EncodingVersion _encoding;
+
+ private bool isEncoding_1_0()
+ {
+ return _encapsStack != null ? _encapsStack.encoding_1_0 : _encoding.Equals(Ice.Util.Encoding_1_0);
+ }
+
+ private Encaps _encapsStack;
+ private Encaps _encapsCache;
+
+ private void initEncaps()
+ {
+ if(_encapsStack == null) // Lazy initialization
+ {
+ _encapsStack = _encapsCache;
+ if(_encapsStack != null)
+ {
+ _encapsCache = _encapsCache.next;
+ }
+ else
+ {
+ _encapsStack = new Encaps();
+ }
+ _encapsStack.setEncoding(_encoding);
+ }
+
+ if(_encapsStack.format == Ice.FormatType.DefaultFormat)
+ {
+ _encapsStack.format = instance_.defaultsAndOverrides().defaultFormat;
+ }
+
+ if(_encapsStack.encoder == null) // Lazy initialization.
+ {
+ if(_encapsStack.encoding_1_0)
+ {
+ _encapsStack.encoder = new EncapsEncoder10(this, _encapsStack);
+ }
+ else
+ {
+ _encapsStack.encoder = new EncapsEncoder11(this, _encapsStack);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Base class for writing objects to an output stream.
+ /// </summary>
+ public abstract class ObjectWriter : ObjectImpl
+ {
+ /// <summary>
+ /// Writes the state of this Slice class to an output stream.
+ /// </summary>
+ /// <param name="outStream">The stream to write to.</param>
+ public abstract void write(OutputStream outStream);
+
+ public override void write__(OutputStream os)
+ {
+ write(os);
+ }
+
+ public override void read__(InputStream istr)
+ {
+ Debug.Assert(false);
+ }
+ }
+
+}
diff --git a/csharp/src/Ice/Patcher.cs b/csharp/src/Ice/Patcher.cs
index 58c91c8d94c..f709d05194f 100644
--- a/csharp/src/Ice/Patcher.cs
+++ b/csharp/src/Ice/Patcher.cs
@@ -14,56 +14,31 @@ using System.Diagnostics;
namespace IceInternal
{
- public interface IPatcher
+ public sealed class ParamPatcher<T>
{
- void patch(Ice.Object v);
- string type();
- }
-
- public abstract class Patcher : IPatcher, Ice.ReadObjectCallback
- {
- public Patcher(string type)
+ public ParamPatcher(string type)
{
_type = type;
}
- public abstract void patch(Ice.Object v);
-
- public virtual string type()
- {
- return _type;
- }
-
- public virtual void invoke(Ice.Object v)
- {
- patch(v);
- }
-
- private string _type;
- }
-
- public sealed class ParamPatcher<T> : Patcher
- {
- public ParamPatcher(string type) : base(type)
- {
- }
-
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v != null && !typeof(T).IsAssignableFrom(v.GetType()))
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
value = (T)v;
}
public T value;
+ private string _type;
}
- public sealed class CustomSeqPatcher<T> : Patcher
+ public sealed class CustomSeqPatcher<T>
{
- public CustomSeqPatcher(string type, IEnumerable<T> seq, int index) : base(type)
+ public CustomSeqPatcher(string type, IEnumerable<T> seq, int index)
{
+ _type = type;
_seq = seq;
_seqType = seq.GetType();
_index = index;
@@ -71,11 +46,11 @@ namespace IceInternal
setInvokeInfo(_seqType);
}
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v != null && !typeof(T).IsAssignableFrom(v.GetType()))
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
InvokeInfo info = getInvokeInfo(_seqType);
@@ -205,46 +180,50 @@ namespace IceInternal
private static Type[] _params = new Type[] { typeof(T) };
private static Dictionary<Type, InvokeInfo> _methodTable = new Dictionary<Type, InvokeInfo>();
+ private string _type;
private IEnumerable<T> _seq;
private Type _seqType;
private int _index; // The index at which to patch the sequence.
}
- public sealed class ArrayPatcher<T> : Patcher
+ public sealed class ArrayPatcher<T>
{
- public ArrayPatcher(string type, T[] seq, int index) : base(type)
+ public ArrayPatcher(string type, T[] seq, int index)
{
+ _type = type;
_seq = seq;
_index = index;
}
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v != null && !typeof(T).IsAssignableFrom(v.GetType()))
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
_seq[_index] = (T)v;
}
+ private string _type;
private T[] _seq;
private int _index; // The index at which to patch the array.
}
- public sealed class SequencePatcher<T> : Patcher
+ public sealed class SequencePatcher<T>
{
- public SequencePatcher(string type, IceInternal.CollectionBase<T> seq, int index) : base(type)
+ public SequencePatcher(string type, IceInternal.CollectionBase<T> seq, int index)
{
+ _type = type;
_seq = seq;
_index = index;
}
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v != null && !typeof(T).IsAssignableFrom(v.GetType()))
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
int count = _seq.Count;
@@ -262,23 +241,25 @@ namespace IceInternal
}
}
+ private string _type;
private IceInternal.CollectionBase<T> _seq;
private int _index; // The index at which to patch the sequence.
}
- public sealed class ListPatcher<T> : Patcher
+ public sealed class ListPatcher<T>
{
- public ListPatcher(string type, List<T> seq, int index) : base(type)
+ public ListPatcher(string type, List<T> seq, int index)
{
+ _type = type;
_seq = seq;
_index = index;
}
- public override void patch(Ice.Object v)
+ public void patch(Ice.Object v)
{
if(v != null && !typeof(T).IsAssignableFrom(v.GetType()))
{
- IceInternal.Ex.throwUOE(type(), v.ice_id());
+ IceInternal.Ex.throwUOE(_type, v.ice_id());
}
int count = _seq.Count;
@@ -296,6 +277,7 @@ namespace IceInternal
}
}
+ private string _type;
private List<T> _seq;
private int _index; // The index at which to patch the sequence.
}
diff --git a/csharp/src/Ice/PropertyNames.cs b/csharp/src/Ice/PropertyNames.cs
index 4702b4f0ccc..5bd7dd9f904 100644
--- a/csharp/src/Ice/PropertyNames.cs
+++ b/csharp/src/Ice/PropertyNames.cs
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Tue Apr 28 22:03:41 2015
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Tue Nov 24 08:50:30 2015
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -708,7 +708,6 @@ namespace IceInternal
new Property(@"^IceGrid\.Registry\.Client\.ThreadPool\.ThreadPriority$", false, null),
new Property(@"^IceGrid\.Registry\.Client\.MessageSizeMax$", false, null),
new Property(@"^IceGrid\.Registry\.CryptPasswords$", false, null),
- new Property(@"^IceGrid\.Registry\.Data$", false, null),
new Property(@"^IceGrid\.Registry\.DefaultTemplates$", false, null),
new Property(@"^IceGrid\.Registry\.Discovery\.ACM\.Timeout$", false, null),
new Property(@"^IceGrid\.Registry\.Discovery\.ACM\.Heartbeat$", false, null),
@@ -789,6 +788,8 @@ namespace IceInternal
new Property(@"^IceGrid\.Registry\.Internal\.ThreadPool\.ThreadIdleTime$", false, null),
new Property(@"^IceGrid\.Registry\.Internal\.ThreadPool\.ThreadPriority$", false, null),
new Property(@"^IceGrid\.Registry\.Internal\.MessageSizeMax$", false, null),
+ new Property(@"^IceGrid\.Registry\.LMDB\.MapSize$", false, null),
+ new Property(@"^IceGrid\.Registry\.LMDB\.Path$", false, null),
new Property(@"^IceGrid\.Registry\.NodeSessionTimeout$", false, null),
new Property(@"^IceGrid\.Registry\.PermissionsVerifier\.EndpointSelection$", false, null),
new Property(@"^IceGrid\.Registry\.PermissionsVerifier\.ConnectionCached$", false, null),
@@ -903,13 +904,6 @@ namespace IceInternal
new Property(@"^IceGrid\.Registry\.Trace\.Topic$", false, null),
new Property(@"^IceGrid\.Registry\.Trace\.TopicManager$", false, null),
new Property(@"^IceGrid\.Registry\.UserAccounts$", false, null),
- new Property(@"^IceGrid\.SQL\.DatabaseType$", false, null),
- new Property(@"^IceGrid\.SQL\.EncodingVersion$", false, null),
- new Property(@"^IceGrid\.SQL\.HostName$", false, null),
- new Property(@"^IceGrid\.SQL\.Port$", false, null),
- new Property(@"^IceGrid\.SQL\.DatabaseName$", false, null),
- new Property(@"^IceGrid\.SQL\.UserName$", false, null),
- new Property(@"^IceGrid\.SQL\.Password$", false, null),
null
};
@@ -1025,6 +1019,13 @@ namespace IceInternal
null
};
+ public static Property[] IceBTProps =
+ {
+ new Property(@"^IceBT\.RcvSize$", false, null),
+ new Property(@"^IceBT\.SndSize$", false, null),
+ null
+ };
+
public static Property[] Glacier2Props =
{
new Property(@"^Glacier2\.AddConnectionContext$", false, null),
@@ -1224,6 +1225,7 @@ namespace IceInternal
IcePatch2ClientProps,
IceSSLProps,
IceStormAdminProps,
+ IceBTProps,
Glacier2Props,
Glacier2CryptPermissionsVerifierProps,
FreezeProps,
@@ -1244,6 +1246,7 @@ namespace IceInternal
"IcePatch2Client",
"IceSSL",
"IceStormAdmin",
+ "IceBT",
"Glacier2",
"Glacier2CryptPermissionsVerifier",
"Freeze",
diff --git a/csharp/src/Ice/Protocol.cs b/csharp/src/Ice/Protocol.cs
index ffc02090a13..d8144552b0f 100644
--- a/csharp/src/Ice/Protocol.cs
+++ b/csharp/src/Ice/Protocol.cs
@@ -10,7 +10,7 @@
namespace IceInternal
{
- sealed class Protocol
+ public sealed class Protocol
{
//
// Size of the Ice protocol header
@@ -42,6 +42,16 @@ namespace IceInternal
internal const byte encodingMajor = 1;
internal const byte encodingMinor = 1;
+
+ public const byte OPTIONAL_END_MARKER = 0xFF;
+
+ public const byte FLAG_HAS_TYPE_ID_STRING = (byte)(1<<0);
+ public const byte FLAG_HAS_TYPE_ID_INDEX = (byte)(1<<1);
+ public const byte FLAG_HAS_TYPE_ID_COMPACT = (byte)(1<<1 | 1<<0);
+ public const byte FLAG_HAS_OPTIONAL_MEMBERS = (byte)(1<<2);
+ public const byte FLAG_HAS_INDIRECTION_TABLE = (byte)(1<<3);
+ public const byte FLAG_HAS_SLICE_SIZE = (byte)(1<<4);
+ public const byte FLAG_IS_LAST_SLICE = (byte)(1<<5);
//
// The Ice protocol message types
@@ -96,7 +106,7 @@ namespace IceInternal
}
}
- internal static void
+ public static void
checkSupportedProtocolEncoding(Ice.EncodingVersion v)
{
if(v.major != protocolEncodingMajor || v.minor > protocolEncodingMinor)
diff --git a/csharp/src/Ice/Proxy.cs b/csharp/src/Ice/Proxy.cs
index ac2b072ae06..5c509216595 100644
--- a/csharp/src/Ice/Proxy.cs
+++ b/csharp/src/Ice/Proxy.cs
@@ -701,6 +701,8 @@ namespace Ice
AsyncResult begin_ice_flushBatchRequests(AsyncCallback cb__, object cookie__);
void end_ice_flushBatchRequests(AsyncResult r__);
+
+ void write__(OutputStream os);
}
/// <summary>
@@ -800,11 +802,11 @@ namespace Ice
}
catch(Ice.UserException ex__)
{
- throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
+ throw new Ice.UnknownUserException(ex__.ice_id(), ex__);
}
}
bool ret__;
- IceInternal.BasicStream is__ = outAsync__.startReadParams();
+ InputStream is__ = outAsync__.startReadParams();
ret__ = is__.readBool();
outAsync__.endReadParams();
return ret__;
@@ -837,7 +839,7 @@ namespace Ice
try
{
result__.prepare(__ice_isA_name, OperationMode.Nonmutating, context__, explicitCtx__, synchronous__);
- IceInternal.BasicStream os__ = result__.startWriteParams(FormatType.DefaultFormat);
+ OutputStream os__ = result__.startWriteParams(FormatType.DefaultFormat);
os__.writeString(id);
result__.endWriteParams();
result__.invoke();
@@ -850,11 +852,11 @@ namespace Ice
}
protected IceInternal.TwowayOutgoingAsync<T>
- getTwowayOutgoingAsync<T>(string operation, IceInternal.ProxyTwowayCallback<T> cb,
- object cookie) {
+ getTwowayOutgoingAsync<T>(string operation, IceInternal.ProxyTwowayCallback<T> cb, object cookie)
+ {
bool haveEntry = false;
- IceInternal.BasicStream iss = null;
- IceInternal.BasicStream os = null;
+ InputStream iss = null;
+ OutputStream os = null;
if(_reference.getInstance().cacheMessageBuffers() > 0)
{
@@ -881,11 +883,11 @@ namespace Ice
}
protected IceInternal.OnewayOutgoingAsync<T>
- getOnewayOutgoingAsync<T>(string operation, IceInternal.ProxyOnewayCallback<T> cb,
- object cookie) {
+ getOnewayOutgoingAsync<T>(string operation, IceInternal.ProxyOnewayCallback<T> cb, object cookie)
+ {
bool haveEntry = false;
- IceInternal.BasicStream iss = null;
- IceInternal.BasicStream os = null;
+ InputStream iss = null;
+ OutputStream os = null;
if(_reference.getInstance().cacheMessageBuffers() > 0)
{
@@ -911,7 +913,7 @@ namespace Ice
}
public void
- cacheMessageBuffers(IceInternal.BasicStream iss, IceInternal.BasicStream os)
+ cacheMessageBuffers(InputStream iss, OutputStream os)
{
lock(this)
{
@@ -1093,11 +1095,11 @@ namespace Ice
}
catch(Ice.UserException ex__)
{
- throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
+ throw new Ice.UnknownUserException(ex__.ice_id(), ex__);
}
}
string[] ret__;
- IceInternal.BasicStream is__ = outAsync__.startReadParams();
+ InputStream is__ = outAsync__.startReadParams();
ret__ = is__.readStringSeq();
outAsync__.endReadParams();
return ret__;
@@ -1220,11 +1222,11 @@ namespace Ice
}
catch(Ice.UserException ex__)
{
- throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
+ throw new Ice.UnknownUserException(ex__.ice_id(), ex__);
}
}
string ret__;
- IceInternal.BasicStream is__ = outAsync__.startReadParams();
+ InputStream is__ = outAsync__.startReadParams();
ret__ = is__.readString();
outAsync__.endReadParams();
return ret__;
@@ -2254,6 +2256,12 @@ namespace Ice
return !Equals(lhs, rhs);
}
+ public void write__(OutputStream os)
+ {
+ _reference.getIdentity().write__(os);
+ _reference.streamWrite(os);
+ }
+
public IceInternal.Reference reference__()
{
return _reference;
@@ -2359,7 +2367,7 @@ namespace Ice
}
catch(Ice.UserException ex)
{
- throw new Ice.UnknownUserException(ex.ice_name(), ex);
+ throw new Ice.UnknownUserException(ex.ice_id(), ex);
}
}
outAsync.readEmptyParams();
@@ -2468,8 +2476,8 @@ namespace Ice
private IceInternal.BatchRequestQueue _batchRequestQueue;
private struct StreamCacheEntry
{
- public IceInternal.BasicStream iss;
- public IceInternal.BasicStream os;
+ public InputStream iss;
+ public OutputStream os;
}
private LinkedList<StreamCacheEntry> _streamCache;
diff --git a/csharp/src/Ice/ProxyFactory.cs b/csharp/src/Ice/ProxyFactory.cs
index 5585f3526ba..11a204f7a10 100644
--- a/csharp/src/Ice/ProxyFactory.cs
+++ b/csharp/src/Ice/ProxyFactory.cs
@@ -20,7 +20,7 @@ namespace IceInternal
Reference r = instance_.referenceFactory().create(str, null);
return referenceToProxy(r);
}
-
+
public string proxyToString(Ice.ObjectPrx proxy)
{
if(proxy != null)
@@ -33,7 +33,7 @@ namespace IceInternal
return "";
}
}
-
+
public Ice.ObjectPrx propertyToProxy(string prefix)
{
string proxy = instance_.initializationData().properties.getProperty(prefix);
@@ -41,8 +41,7 @@ namespace IceInternal
return referenceToProxy(r);
}
- public Dictionary<string, string>
- proxyToProperty(Ice.ObjectPrx proxy, string prefix)
+ public Dictionary<string, string> proxyToProperty(Ice.ObjectPrx proxy, string prefix)
{
if(proxy != null)
{
@@ -54,16 +53,16 @@ namespace IceInternal
return new Dictionary<string, string>();
}
}
-
- public Ice.ObjectPrx streamToProxy(BasicStream s)
+
+ public Ice.ObjectPrx streamToProxy(Ice.InputStream s)
{
Ice.Identity ident = new Ice.Identity();
ident.read__(s);
-
+
Reference r = instance_.referenceFactory().create(ident, s);
return referenceToProxy(r);
}
-
+
public Ice.ObjectPrx referenceToProxy(Reference r)
{
if(r != null)
@@ -77,25 +76,7 @@ namespace IceInternal
return null;
}
}
-
- public void proxyToStream(Ice.ObjectPrx proxy, BasicStream s)
- {
- if(proxy != null)
- {
- Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)proxy;
- Reference r = h.reference__();
- r.getIdentity().write__(s);
- r.streamWrite(s);
- }
- else
- {
- Ice.Identity ident = new Ice.Identity();
- ident.name = "";
- ident.category = "";
- ident.write__(s);
- }
- }
-
+
public int checkRetryAfterException(Ice.LocalException ex, Reference @ref, ref int cnt)
{
TraceLevels traceLevels = instance_.traceLevels();
@@ -202,7 +183,7 @@ namespace IceInternal
//
// Don't retry invocation timeouts.
//
- if(ex is Ice.InvocationTimeoutException || ex is Ice.InvocationCanceledException)
+ if(ex is Ice.InvocationTimeoutException || ex is Ice.InvocationCanceledException)
{
throw ex;
}
@@ -253,17 +234,17 @@ namespace IceInternal
internal ProxyFactory(Instance instance)
{
instance_ = instance;
-
+
string[] arr = instance_.initializationData().properties.getPropertyAsList("Ice.RetryIntervals");
if(arr.Length > 0)
{
_retryIntervals = new int[arr.Length];
-
+
for (int i = 0; i < arr.Length; i++)
{
int v;
-
+
try
{
v = System.Int32.Parse(arr[i], CultureInfo.InvariantCulture);
@@ -272,16 +253,16 @@ namespace IceInternal
{
v = 0;
}
-
+
//
// If -1 is the first value, no retry and wait intervals.
- //
+ //
if(i == 0 && v == -1)
{
_retryIntervals = new int[0];
break;
}
-
+
_retryIntervals[i] = v > 0?v:0;
}
}
@@ -291,7 +272,7 @@ namespace IceInternal
_retryIntervals[0] = 0;
}
}
-
+
private Instance instance_;
private int[] _retryIntervals;
}
diff --git a/csharp/src/Ice/Reference.cs b/csharp/src/Ice/Reference.cs
index 2b87e474e47..0dd31858f3e 100644
--- a/csharp/src/Ice/Reference.cs
+++ b/csharp/src/Ice/Reference.cs
@@ -244,7 +244,7 @@ namespace IceInternal
//
// Marshal the reference.
//
- public virtual void streamWrite(BasicStream s)
+ public virtual void streamWrite(Ice.OutputStream s)
{
//
// Don't write the identity here. Operations calling streamWrite
@@ -268,7 +268,7 @@ namespace IceInternal
s.writeBool(secure_);
- if(!s.getWriteEncoding().Equals(Ice.Util.Encoding_1_0))
+ if(!s.getEncoding().Equals(Ice.Util.Encoding_1_0))
{
protocol_.write__(s);
encoding_.write__(s);
@@ -651,7 +651,7 @@ namespace IceInternal
return false;
}
- public override void streamWrite(BasicStream s)
+ public override void streamWrite(Ice.OutputStream s)
{
throw new Ice.FixedProxyException();
}
@@ -1005,7 +1005,7 @@ namespace IceInternal
return _endpoints.Length == 0 && _adapterId.Length == 0;
}
- public override void streamWrite(BasicStream s)
+ public override void streamWrite(Ice.OutputStream s)
{
base.streamWrite(s);
diff --git a/csharp/src/Ice/ReferenceFactory.cs b/csharp/src/Ice/ReferenceFactory.cs
index 1818de13c57..1a8aad17952 100644
--- a/csharp/src/Ice/ReferenceFactory.cs
+++ b/csharp/src/Ice/ReferenceFactory.cs
@@ -551,7 +551,7 @@ namespace IceInternal
throw ex;
}
- public Reference create(Ice.Identity ident, BasicStream s)
+ public Reference create(Ice.Identity ident, Ice.InputStream s)
{
//
// Don't read the identity here. Operations calling this
@@ -591,7 +591,7 @@ namespace IceInternal
Ice.ProtocolVersion protocol;
Ice.EncodingVersion encoding;
- if(!s.getReadEncoding().Equals(Ice.Util.Encoding_1_0))
+ if(!s.getEncoding().Equals(Ice.Util.Encoding_1_0))
{
protocol = new Ice.ProtocolVersion();
protocol.read__(s);
diff --git a/csharp/src/Ice/ResponseHandler.cs b/csharp/src/Ice/ResponseHandler.cs
index 10eb8973826..6025a2b7f07 100644
--- a/csharp/src/Ice/ResponseHandler.cs
+++ b/csharp/src/Ice/ResponseHandler.cs
@@ -14,9 +14,9 @@ namespace IceInternal
{
public interface ResponseHandler
{
- void sendResponse(int requestId, BasicStream os, byte status, bool amd);
+ void sendResponse(int requestId, Ice.OutputStream os, byte status, bool amd);
void sendNoResponse();
bool systemException(int requestId, Ice.SystemException ex, bool amd);
void invokeException(int requestId, Ice.LocalException ex, int invokeNum, bool amd);
- };
+ }
}
diff --git a/csharp/src/Ice/Stream.cs b/csharp/src/Ice/Stream.cs
deleted file mode 100644
index 8f1d6a799a9..00000000000
--- a/csharp/src/Ice/Stream.cs
+++ /dev/null
@@ -1,705 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-using System.Diagnostics;
-
-namespace Ice
-{
- /// <summary>
- /// Callback class to inform an application when a Slice class has been unmarshaled
- /// from an input stream.
- /// </summary>
- public interface ReadObjectCallback
- {
- /// <summary>
- /// The Ice run time calls this method when it has fully unmarshaled the state
- /// of a Slice class.
- /// </summary>
- /// <param name="obj">The unmarshaled Slice class.</param>
- void invoke(Ice.Object obj);
- }
-
- /// <summary>
- /// Interface for input streams used to extract Slice types from a sequence of bytes.
- /// </summary>
- public interface InputStream
- {
- /// <summary>
- /// Returns the communicator for this input stream.
- /// </summary>
- /// <returns>The communicator.</returns>
- Communicator communicator();
-
- /// <summary>
- /// Determines the behavior of the stream when extracting Slice objects.
- /// A Slice object is "sliced" when a factory cannot be found for a Slice type ID.
- /// </summary>
- /// <param name="slice">If true (the default), slicing is enabled; if false,
- /// slicing is disabled. If slicing is disabled and the stream encounters a Slice type ID
- /// during decoding for which no object factory is installed, it raises NoObjectFactoryException.</param>
- void sliceObjects(bool slice);
-
- /// <summary>
- /// Extracts a boolean value from the stream.
- /// </summary>
- /// <returns>The extracted boolean.</returns>
- bool readBool();
-
- /// <summary>
- /// Extracts a sequence of boolean values from the stream.
- /// </summary>
- /// <returns>The extracted boolean sequence.</returns>
- bool[] readBoolSeq();
-
- /// <summary>
- /// Extracts a byte value from the stream.
- /// </summary>
- /// <returns>The extracted byte.</returns>
- byte readByte();
-
- /// <summary>
- /// Extracts a sequence of byte values from the stream.
- /// </summary>
- /// <returns>The extracted byte sequence.</returns>
- byte[] readByteSeq();
-
- /// <summary>
- /// Extracts a serializable .NET object from the stream.
- /// </summary>
- /// <returns>The deserialized .NET object.</returns>
- object readSerializable();
-
- /// <summary>
- /// Extracts a short value from the stream.
- /// </summary>
- /// <returns>The extracted short value.</returns>
- short readShort();
-
- /// <summary>
- /// Extracts a sequence of short values from the stream.
- /// </summary>
- /// <returns>The extracted short sequence.</returns>
- short[] readShortSeq();
-
- /// <summary>
- /// Extracts an integer value from the stream.
- /// </summary>
- /// <returns>The extracted integer value.</returns>
- int readInt();
-
- /// <summary>
- /// Extracts a sequence of integer values from the stream.
- /// </summary>
- /// <returns>The extracted integer sequence.</returns>
- int[] readIntSeq();
-
- /// <summary>
- /// Extracts a long value from the stream.
- /// </summary>
- /// <returns>The extracted long value.</returns>
- long readLong();
-
- /// <summary>
- /// Extracts a sequence of long values from the stream.
- /// </summary>
- /// <returns>The extracted long sequence.</returns>
- long[] readLongSeq();
-
- /// <summary>
- /// Extracts a float value from the stream.
- /// </summary>
- /// <returns>The extracted float value.</returns>
- float readFloat();
-
- /// <summary>
- /// Extracts a sequence of float values from the stream.
- /// </summary>
- /// <returns>The extracted float sequence.</returns>
- float[] readFloatSeq();
-
- /// <summary>
- /// Extracts a double value from the stream.
- /// </summary>
- /// <returns>The extracted double value.</returns>
- double readDouble();
-
- /// <summary>
- /// Extracts a sequence of double values from the stream.
- /// </summary>
- /// <returns>The extracted double sequence.</returns>
- double[] readDoubleSeq();
-
- /// <summary>
- /// Extracts a string from the stream.
- /// </summary>
- /// <returns>The extracted double value.</returns>
- string readString();
-
- /// <summary>
- /// Extracts a sequence of strings from the stream.
- /// </summary>
- /// <returns>The extracted string sequence.</returns>
- string[] readStringSeq();
-
- /// <summary>
- /// Extracts a size from the stream.
- /// </summary>
- /// <returns>The extracted size.</returns>
- int readSize();
-
- /// <summary>
- /// Extracts and check a sequence size from the stream. The check ensures not too much memory will
- /// be pre-allocated for the sequence.
- /// </summary>
- /// <param name="minSize">The minimum size of an element of the sequence.</param>
- /// <returns>The extracted size.</returns>
- int readAndCheckSeqSize(int minSize);
-
- /// <summary>
- /// Extracts a proxy from the stream.
- /// </summary>
- /// <returns>The extracted proxy.</returns>
- ObjectPrx readProxy();
-
- /// <summary>
- /// Extracts the index of a Slice class from the stream.
- /// </summary>
- /// <param name="cb">The callback to notify the application when the extracted instance is available.
- /// The Ice run time extracts Slice classes in stages. The Ice run time calls ReadObjectCallback.invoke
- /// when the corresponding instance has been fully unmarshaled.</param>
- void readObject(ReadObjectCallback cb);
-
- /// <summary>
- /// Read an enumerated value.
- /// </summary>
- ///
- /// <param name="maxValue">The maximum enumerator value in the definition.</param>
- /// <returns>The enumerator.</returns>
- int readEnum(int maxValue);
-
- /// <summary>
- /// Extracts a user exception from the stream and throws it.
- /// </summary>
- void throwException();
-
- /// <summary>
- /// Extracts a user exception from the stream and throws it.
- /// Extracts a user exception from the stream and throws it, using the supplied
- /// factory to instantiate a UserExceptionReader.
- /// </summary>
- /// <param name="factory">A factory that creates UserExceptionReader instances.</param>
- void throwException(UserExceptionReaderFactory factory);
-
- /// <summary>
- /// Marks the start of an Ice object.
- /// </summary>
- void startObject();
-
- /// <summary>
- /// Marks the end of an Ice object.
- /// </summary>
- /// <param name="preserve">True if unknown slices should be preserved, false otherwise.</param>
- /// <returns>A SlicedData object containing the preserved slices for unknown types.</returns>
- SlicedData endObject(bool preserve);
-
- /// <summary>
- /// Marks the start of a user exception.
- /// </summary>
- void startException();
-
- /// <summary>
- /// Marks the end of a user exception.
- /// </summary>
- /// <param name="preserve">True if unknown slices should be preserved, false otherwise.</param>
- /// <returns>A SlicedData object containing the preserved slices for unknown types.</returns>
- SlicedData endException(bool preserve);
-
- /// <summary>
- /// Reads the start of an object or exception slice.
- /// </summary>
- /// <returns>The Slice type ID for this slice.</returns>
- string startSlice();
-
- /// <summary>
- /// Indicates that the end of an object or exception slice has been reached.
- /// </summary>
- void endSlice();
-
- /// <summary>
- /// Skips over an object or exception slice.
- /// </summary>
- void skipSlice();
-
- /// <summary>
- /// Reads the start of an encapsulation.
- /// </summary>
- /// <returns>The encapsulation encoding version.</returns>
- EncodingVersion startEncapsulation();
-
- /// <summary>
- /// Indicates that the end of an encapsulation has been reached.
- /// </summary>
- void endEncapsulation();
-
- /// <summary>
- /// Skips over an encapsulation.
- /// </summary>
- /// <returns>The encapsulation encoding version.</returns>
- EncodingVersion skipEncapsulation();
-
- /// <summary>
- /// Determines the current encoding version.
- /// </summary>
- /// <returns>The encoding version.</returns>
- EncodingVersion getEncoding();
-
- /// <summary>
- /// Indicates that unmarshaling is complete, except for any Slice objects. The application must
- /// call this method only if the stream actually contains Slice objects. Calling readPendingObjects
- /// triggers the calls to ReadObjectCallback.invoke that inform the application that unmarshaling
- /// of a Slice object is complete.
- /// </summary>
- void readPendingObjects();
-
- /// <summary>
- /// Resets the read position of the stream to the beginning.
- /// </summary>
- void rewind();
-
- /// <summary>
- /// Skips ahead in the stream.
- /// </summary>
- /// <param name="sz">The number of bytes to skip.</param>
- void skip(int sz);
-
- /// <summary>
- /// Skips over a size value.
- /// </summary>
- void skipSize();
-
- /// <summary>
- /// Determine if an optional value is available for reading.
- /// </summary>
- /// <param name="tag">The tag associated with the value.</param>
- /// <param name="format">The optional format for the value.</param>
- /// <returns>True if the value is present, false otherwise.</returns>
- bool readOptional(int tag, OptionalFormat format);
-
- /// <summary>
- /// Determine the current position in the stream.
- /// </summary>
- /// <returns>The current position.</returns>
- int pos();
-
- /// <summary>
- /// Destroys the stream and its associated resources. The application must call destroy prior
- /// to releasing the last reference to a stream; failure to do so may result in resource leaks.
- /// </summary>
- void destroy();
- }
-
- /// <summary>
- /// Interface for output streams used to write Slice types to a sequence
- /// of bytes.
- /// </summary>
- public interface OutputStream
- {
- /// <summary>
- /// Returns the communicator for this output stream.
- /// </summary>
- Communicator communicator();
-
- /// <summary>
- /// Writes a boolean to the stream.
- /// </summary>
- /// <param name="v">The boolean to write to the stream.</param>
- void writeBool(bool v);
-
- /// <summary>
- /// Writes a sequence of booleans to the stream.
- /// </summary>
- /// <param name="v">The sequence of booleans to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeBoolSeq(bool[] v);
-
- /// <summary>
- /// Writes a byte to the stream.
- /// </summary>
- /// <param name="v">The byte to write to the stream.</param>
- void writeByte(byte v);
-
- /// <summary>
- /// Writes a sequence of bytes to the stream.
- /// </summary>
- /// <param name="v">The sequence of bytes to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeByteSeq(byte[] v);
-
- /// <summary>
- /// Writes a serializable .NET object to the stream.
- /// </summary>
- /// <param name="v">The serializable object to write.</param>
- void writeSerializable(object v);
-
- /// <summary>
- /// Writes a short to the stream.
- /// </summary>
- /// <param name="v">The short to write to the stream.</param>
- void writeShort(short v);
-
- /// <summary>
- /// Writes a sequence of shorts to the stream.
- /// </summary>
- /// <param name="v">The sequence of shorts to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeShortSeq(short[] v);
-
- /// <summary>
- /// Writes an integer to the stream.
- /// </summary>
- /// <param name="v">The integer to write to the stream.</param>
- void writeInt(int v);
-
- /// <summary>
- /// Writes a sequence of integers to the stream.
- /// </summary>
- /// <param name="v">The sequence of integers to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeIntSeq(int[] v);
-
- /// <summary>
- /// Writes a long to the stream.
- /// </summary>
- /// <param name="v">The long to write to the stream.</param>
- void writeLong(long v);
-
- /// <summary>
- /// Writes a sequence of longs to the stream.
- /// </summary>
- /// <param name="v">The sequence of longs to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeLongSeq(long[] v);
-
- /// <summary>
- /// Writes a float to the stream.
- /// </summary>
- /// <param name="v">The float to write to the stream.</param>
- void writeFloat(float v);
-
- /// <summary>
- /// Writes a sequence of floats to the stream.
- /// </summary>
- /// <param name="v">The sequence of floats to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeFloatSeq(float[] v);
-
- /// <summary>
- /// Writes a double to the stream.
- /// </summary>
- /// <param name="v">The double to write to the stream.</param>
- void writeDouble(double v);
-
- /// <summary>
- /// Writes a sequence of doubles to the stream.
- /// </summary>
- /// <param name="v">The sequence of doubles to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeDoubleSeq(double[] v);
-
- /// <summary>
- /// Writes a string to the stream.
- /// </summary>
- /// <param name="v">The string to write to the stream.
- /// Passing null causes an empty string to be written to the stream.</param>
- void writeString(string v);
-
- /// <summary>
- /// Writes a sequence of strings to the stream.
- /// </summary>
- /// <param name="v">The sequence of strings to write.
- /// Passing null causes an empty sequence to be written to the stream.</param>
- void writeStringSeq(string[] v);
-
- /// <summary>
- /// Writes a size to the stream.
- /// </summary>
- /// <param name="sz">The size to write.</param>
- void writeSize(int sz);
-
- /// <summary>
- /// Writes a proxy to the stream.
- /// </summary>
- /// <param name="v">The proxy to write.</param>
- void writeProxy(ObjectPrx v);
-
- /// <summary>
- /// Writes a Slice class to the stream.
- /// </summary>
- /// <param name="v">The class to write. This method writes the index of a Slice class; the state of the
- /// class is written once writePendingObjects is called.</param>
- void writeObject(Ice.Object v);
-
- /// <summary>
- /// Write an enumerated value.
- /// </summary>
- /// <param name="v">The enumerator.</param>
- /// <param name="limit">The number of enumerators in the definition.</param>
- void writeEnum(int v, int limit);
-
- /// <summary>
- /// Writes a user exception to the stream.
- /// </summary>
- /// <param name="ex">The user exception to write.</param>
- void writeException(UserException ex);
-
- /// <summary>
- /// Marks the start of an Ice object.
- /// </summary>
- /// <param name="slicedData">Preserved slices for this object, or null.</param>
- void startObject(SlicedData slicedData);
-
- /// <summary>
- /// Marks the end of an Ice object.
- /// </summary>
- void endObject();
-
- /// <summary>
- /// Marks the start of a user exception.
- /// </summary>
- /// <param name="slicedData">Preserved slices for this object, or null.</param>
- void startException(SlicedData slicedData);
-
- /// <summary>
- /// Marks the end of a user exception.
- /// </summary>
- void endException();
-
- /// <summary>
- /// Marks the start of a new slice for an Ice object or user exception.
- /// </summary>
- /// <param name="typeId">The Slice type ID corresponding to this slice.</param>
- /// <param name="compactId">The Slice compact type ID corresponding to this slice.</param>
- /// <param name="last">True if this is the last slice, false otherwise.</param>
- void startSlice(string typeId, int compactId, bool last);
-
- /// <summary>
- /// Marks the end of a slice for an Ice object or user exception.
- /// </summary>
- void endSlice();
-
- /// <summary>
- /// Writes the start of an encapsulation to the stream.
- /// </summary>
- /// <param name="encoding">The encoding version of the encapsulation.</param>
- /// <param name="format">The format to use for encoding objects and user exceptions.</param>
- void startEncapsulation(EncodingVersion encoding, FormatType format);
-
- /// <summary>
- /// Writes the start of an encapsulation to the stream.
- /// </summary>
- void startEncapsulation();
-
- /// <summary>
- /// Ends the previous encapsulation.
- /// </summary>
- void endEncapsulation();
-
- /// <summary>
- /// Determines the current encoding version.
- /// </summary>
- /// <returns>The encoding version.</returns>
- EncodingVersion getEncoding();
-
- /// <summary>
- /// Writes the state of Slice classes whose index was previously
- /// written with writeObject to the stream.
- /// </summary>
- void writePendingObjects();
-
- /// <summary>
- /// Write the header information for an optional value.
- /// </summary>
- /// <param name="tag">The numeric tag associated with the value.</param>
- /// <param name="format">The optional format of the value.</param>
- /// <returns>True if the optional should be written, false otherwise.</returns>
- bool writeOptional(int tag, OptionalFormat format);
-
- /// <summary>
- /// Determines the current position in the stream.
- /// </summary>
- /// <returns>The current position.</returns>
- int pos();
-
- /// <summary>
- /// Inserts a fixed 32-bit size value into the stream at the given position.
- /// </summary>
- /// <param name="sz">The 32-bit size value.</param>
- /// <param name="pos">The position at which to write the value.</param>
- void rewrite(int sz, int pos);
-
- /// <summary>
- /// Returns the current position and allocates four bytes for a fixed-length (32-bit)
- /// size value.
- /// </summary>
- /// <returns>The current position.</returns>
- int startSize();
-
- /// <summary>
- /// Computes the amount of data written since the previous call to startSize and
- /// writes that value at the saved position.
- /// </summary>
- /// <param name="pos">The saved position at which to write the size.</param>
- void endSize(int pos);
-
- /// <summary>
- /// Indicates that the marshaling of a request or reply is finished.
- /// </summary>
- /// <returns>The byte sequence containing the encoded request or reply.</returns>
- byte[] finished();
-
- /// <summary>
- /// Resets this output stream. This method allows the stream to be reused, to avoid creating
- /// unnecessary garbage.
- /// </summary>
- ///
- /// <param name="clearBuffer">If true, the stream's internal buffer becomes eligible for
- /// garbage collection; if false, the stream's internal buffer is retained, to avoid
- /// creating unnecessary garbage. If retained, the internal buffer may be resized to a smaller
- /// capacity. Either way, reset resets the stream's writing position to zero.</param>
- void reset(bool clearBuffer);
-
- /// <summary>
- /// Destroys the stream and its associated resources. The application must call destroy prior
- /// to releasing the last reference to a stream; failure to do so may result in resource leaks.
- /// </summary>
- void destroy();
- }
-
- /// <summary>
- /// Base class for extracting objects from an input stream.
- /// </summary>
- public abstract class ObjectReader : ObjectImpl
- {
- /// <summary>
- /// Read the object's data members.
- /// </summary>
- /// <param name="inStream">The input stream to read from.</param>
- public abstract void read(InputStream inStream);
-
- public override void write__(IceInternal.BasicStream os)
- {
- Debug.Assert(false);
- }
-
- public override void read__(IceInternal.BasicStream istr)
- {
- InputStream stream = (InputStream)istr.closure();
- read(stream);
- }
- }
-
- /// <summary>
- /// Base class for writing objects to an output stream.
- /// </summary>
- public abstract class ObjectWriter : ObjectImpl
- {
- /// <summary>
- /// Writes the state of this Slice class to an output stream.
- /// </summary>
- /// <param name="outStream">The stream to write to.</param>
- public abstract void write(OutputStream outStream);
-
- public override void write__(IceInternal.BasicStream os)
- {
- OutputStream stream = (OutputStream)os.closure();
- write(stream);
- }
-
- public override void read__(IceInternal.BasicStream istr)
- {
- Debug.Assert(false);
- }
- }
-
- public abstract class UserExceptionReader : UserException
- {
- protected UserExceptionReader(Communicator communicator)
- {
- communicator_ = communicator;
- }
-
- public abstract void read(Ice.InputStream istr);
-
- public override void write__(IceInternal.BasicStream ostr)
- {
- Debug.Assert(false);
- }
-
- public override void read__(IceInternal.BasicStream istr)
- {
- InputStream stream = (InputStream)istr.closure();
- Debug.Assert(stream != null);
- read(stream);
- }
-
- public override void write__(Ice.OutputStream ostr)
- {
- Debug.Assert(false);
- }
-
- public override void read__(Ice.InputStream istr)
- {
- read(istr);
- }
-
- protected Communicator communicator_;
- }
-
- public interface UserExceptionReaderFactory
- {
- void createAndThrow(string typeId);
- }
-
- public abstract class UserExceptionWriter : UserException
- {
- public UserExceptionWriter(Communicator communicator)
- {
- communicator_ = communicator;
- }
-
- public abstract void write(OutputStream os);
-
- public override void write__(IceInternal.BasicStream os)
- {
- OutputStream stream = (OutputStream)os.closure();
- if(stream == null)
- {
- stream = new OutputStreamI(communicator_, os);
- }
- write(stream);
- }
-
- public override void read__(IceInternal.BasicStream istr)
- {
- Debug.Assert(false);
- }
-
- public override void write__(Ice.OutputStream ostr)
- {
- write(ostr);
- }
-
- public override void read__(Ice.InputStream istr)
- {
- Debug.Assert(false);
- }
-
- protected Communicator communicator_;
- }
-}
diff --git a/csharp/src/Ice/StreamI.cs b/csharp/src/Ice/StreamI.cs
deleted file mode 100644
index 253dbdbdbf7..00000000000
--- a/csharp/src/Ice/StreamI.cs
+++ /dev/null
@@ -1,570 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-namespace Ice
-{
- public class InputStreamI : InputStream
- {
- public InputStreamI(Communicator communicator, byte[] data, bool copyData)
- {
- _communicator = communicator;
- IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
- initialize(instance, data, instance.defaultsAndOverrides().defaultEncoding, copyData);
- }
-
- public InputStreamI(Communicator communicator, byte[] data, EncodingVersion v, bool copyData)
- {
- _communicator = communicator;
- initialize(IceInternal.Util.getInstance(communicator), data, v, copyData);
- }
-
- private void initialize(IceInternal.Instance instance, byte[] data, EncodingVersion v, bool copyData)
- {
- if(copyData)
- {
- _is = new IceInternal.BasicStream(instance, v);
- _is.resize(data.Length, true);
- IceInternal.Buffer buf = _is.getBuffer();
- buf.b.position(0);
- buf.b.put(data);
- buf.b.position(0);
- }
- else
- {
- _is = new IceInternal.BasicStream(instance, v, data);
- }
- _is.closure(this);
- }
-
- public Communicator communicator()
- {
- return _communicator;
- }
-
- public void sliceObjects(bool slice)
- {
- _is.sliceObjects(slice);
- }
-
- public bool readBool()
- {
- return _is.readBool();
- }
-
- public bool[] readBoolSeq()
- {
- return _is.readBoolSeq();
- }
-
- public byte readByte()
- {
- return _is.readByte();
- }
-
- public byte[] readByteSeq()
- {
- return _is.readByteSeq();
- }
-
- public object readSerializable()
- {
- return _is.readSerializable();
- }
-
- public short readShort()
- {
- return _is.readShort();
- }
-
- public short[] readShortSeq()
- {
- return _is.readShortSeq();
- }
-
- public int readInt()
- {
- return _is.readInt();
- }
-
- public int[] readIntSeq()
- {
- return _is.readIntSeq();
- }
-
- public long readLong()
- {
- return _is.readLong();
- }
-
- public long[] readLongSeq()
- {
- return _is.readLongSeq();
- }
-
- public float readFloat()
- {
- return _is.readFloat();
- }
-
- public float[] readFloatSeq()
- {
- return _is.readFloatSeq();
- }
-
- public double readDouble()
- {
- return _is.readDouble();
- }
-
- public double[] readDoubleSeq()
- {
- return _is.readDoubleSeq();
- }
-
- public string readString()
- {
- return _is.readString();
- }
-
- public string[] readStringSeq()
- {
- return _is.readStringSeq();
- }
-
- public int readSize()
- {
- return _is.readSize();
- }
-
- public int readAndCheckSeqSize(int minSize)
- {
- return _is.readAndCheckSeqSize(minSize);
- }
-
- public ObjectPrx readProxy()
- {
- return _is.readProxy();
- }
-
- private class Patcher<T> : IceInternal.Patcher
- {
- public Patcher(ReadObjectCallback cb) : base("unknown")
- {
- _cb = cb;
- }
-
- public override void patch(Ice.Object v)
- {
- _cb.invoke(v);
- }
-
- ReadObjectCallback _cb;
- }
-
- public void readObject(ReadObjectCallback cb)
- {
- _is.readObject(new Patcher<Ice.Object>(cb));
- }
-
- public int readEnum(int maxValue)
- {
- return _is.readEnum(maxValue);
- }
-
- public void throwException()
- {
- _is.throwException(null);
- }
-
- internal class UserExceptionFactoryI : IceInternal.UserExceptionFactory
- {
- internal UserExceptionFactoryI(UserExceptionReaderFactory factory)
- {
- _factory = factory;
- }
-
- public void createAndThrow(string id)
- {
- _factory.createAndThrow(id);
- }
-
- public void destroy()
- {
- }
-
- private UserExceptionReaderFactory _factory;
- }
-
- public void throwException(UserExceptionReaderFactory factory)
- {
- _is.throwException(new UserExceptionFactoryI(factory));
- }
-
- public void startObject()
- {
- _is.startReadObject();
- }
-
- public SlicedData endObject(bool preserve)
- {
- return _is.endReadObject(preserve);
- }
-
- public void startException()
- {
- _is.startReadException();
- }
-
- public SlicedData endException(bool preserve)
- {
- return _is.endReadException(preserve);
- }
-
- public string startSlice()
- {
- return _is.startReadSlice();
- }
-
- public void endSlice()
- {
- _is.endReadSlice();
- }
-
- public void skipSlice()
- {
- _is.skipSlice();
- }
-
- public EncodingVersion startEncapsulation()
- {
- return _is.startReadEncaps();
- }
-
- public void endEncapsulation()
- {
- _is.endReadEncapsChecked();
- }
-
- public EncodingVersion skipEncapsulation()
- {
- return _is.skipEncaps();
- }
-
- public EncodingVersion getEncoding()
- {
- return _is.getReadEncoding();
- }
-
- public void readPendingObjects()
- {
- _is.readPendingObjects();
- }
-
- public void rewind()
- {
- _is.clear();
- _is.getBuffer().b.position(0);
- }
-
- public void skip(int sz)
- {
- _is.skip(sz);
- }
-
- public void skipSize()
- {
- _is.skipSize();
- }
-
- public bool readOptional(int tag, OptionalFormat format)
- {
- return _is.readOpt(tag, format);
- }
-
- public int pos()
- {
- return _is.pos();
- }
-
- public void destroy()
- {
- if(_is != null)
- {
- _is = null;
- }
- }
-
- private Communicator _communicator;
- private IceInternal.BasicStream _is;
- }
-
- public class OutputStreamI : OutputStream
- {
- public OutputStreamI(Communicator communicator)
- {
- _communicator = communicator;
-
- IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
- _os = new IceInternal.BasicStream(instance, instance.defaultsAndOverrides().defaultEncoding);
- _os.closure(this);
- }
-
- public OutputStreamI(Communicator communicator, EncodingVersion v)
- {
- _communicator = communicator;
-
- IceInternal.Instance instance = IceInternal.Util.getInstance(communicator);
- _os = new IceInternal.BasicStream(instance, v);
- _os.closure(this);
- }
-
- public OutputStreamI(Communicator communicator, IceInternal.BasicStream os)
- {
- _communicator = communicator;
- _os = os;
- _os.closure(this);
- }
-
- public Communicator communicator()
- {
- return _communicator;
- }
-
- public void writeBool(bool v)
- {
- _os.writeBool(v);
- }
-
- public void writeBoolSeq(bool[] v)
- {
- _os.writeBoolSeq(v);
- }
-
- public void writeByte(byte v)
- {
- _os.writeByte(v);
- }
-
- public void writeByteSeq(byte[] v)
- {
- _os.writeByteSeq(v);
- }
-
- public void writeSerializable(object v)
- {
- _os.writeSerializable(v);
- }
-
- public void writeShort(short v)
- {
- _os.writeShort(v);
- }
-
- public void writeShortSeq(short[] v)
- {
- _os.writeShortSeq(v);
- }
-
- public void writeInt(int v)
- {
- _os.writeInt(v);
- }
-
- public void writeIntSeq(int[] v)
- {
- _os.writeIntSeq(v);
- }
-
- public void writeLong(long v)
- {
- _os.writeLong(v);
- }
-
- public void writeLongSeq(long[] v)
- {
- _os.writeLongSeq(v);
- }
-
- public void writeFloat(float v)
- {
- _os.writeFloat(v);
- }
-
- public void writeFloatSeq(float[] v)
- {
- _os.writeFloatSeq(v);
- }
-
- public void writeDouble(double v)
- {
- _os.writeDouble(v);
- }
-
- public void writeDoubleSeq(double[] v)
- {
- _os.writeDoubleSeq(v);
- }
-
- public void writeString(string v)
- {
- _os.writeString(v);
- }
-
- public void writeStringSeq(string[] v)
- {
- _os.writeStringSeq(v);
- }
-
- public void writeSize(int sz)
- {
- if(sz < 0)
- {
- throw new MarshalException();
- }
-
- _os.writeSize(sz);
- }
-
- public void writeProxy(ObjectPrx v)
- {
- _os.writeProxy(v);
- }
-
- public void writeObject(Ice.Object v)
- {
- _os.writeObject(v);
- }
-
- public void writeEnum(int v, int maxValue)
- {
- _os.writeEnum(v, maxValue);
- }
-
- public void writeException(UserException v)
- {
- _os.writeUserException(v);
- }
-
- public void startObject(SlicedData slicedData)
- {
- _os.startWriteObject(slicedData);
- }
-
- public void endObject()
- {
- _os.endWriteObject();
- }
-
- public void startException(SlicedData slicedData)
- {
- _os.startWriteException(slicedData);
- }
-
- public void endException()
- {
- _os.endWriteException();
- }
-
- public void startSlice(string typeId, int compactId, bool last)
- {
- _os.startWriteSlice(typeId, compactId, last);
- }
-
- public void endSlice()
- {
- _os.endWriteSlice();
- }
-
- public void startEncapsulation(EncodingVersion encoding, FormatType format)
- {
- _os.startWriteEncaps(encoding, format);
- }
-
- public void startEncapsulation()
- {
- _os.startWriteEncaps();
- }
-
- public void endEncapsulation()
- {
- _os.endWriteEncapsChecked();
- }
-
- public EncodingVersion getEncoding()
- {
- return _os.getWriteEncoding();
- }
-
- public void writePendingObjects()
- {
- _os.writePendingObjects();
- }
-
- public bool writeOptional(int tag, OptionalFormat format)
- {
- return _os.writeOpt(tag, format);
- }
-
- public int pos()
- {
- return _os.pos();
- }
-
- public void rewrite(int sz, int pos)
- {
- _os.rewriteInt(sz, pos);
- }
-
- public int startSize()
- {
- return _os.startSize();
- }
-
- public void endSize(int pos)
- {
- _os.endSize(pos);
- }
-
- public byte[] finished()
- {
- IceInternal.Buffer buf = _os.prepareWrite();
- byte[] result = new byte[buf.b.limit()];
- buf.b.get(result);
-
- return result;
- }
-
- public void reset(bool clearBuffer)
- {
- _os.clear();
-
- IceInternal.Buffer buf = _os.getBuffer();
- if(clearBuffer)
- {
- buf.clear();
- }
- else
- {
- buf.reset();
- }
- buf.b.position(0);
- }
-
- public void destroy()
- {
- if(_os != null)
- {
- _os = null;
- }
- }
-
- private Communicator _communicator;
- private IceInternal.BasicStream _os;
- }
-}
diff --git a/csharp/src/Ice/StreamWrapper.cs b/csharp/src/Ice/StreamWrapper.cs
index 8a27307a449..5bb5d653de6 100644
--- a/csharp/src/Ice/StreamWrapper.cs
+++ b/csharp/src/Ice/StreamWrapper.cs
@@ -17,36 +17,30 @@ namespace IceInternal
using System.Text;
//
- // Class to provide a System.IO.Stream interface on top of a BasicStream.
+ // Classes to provide a System.IO.Stream interface on top of an Ice stream.
// We use this to serialize arbitrary .NET serializable classes into
// a Slice byte sequence.
//
- // For input streams, this class is a wrapper around the BasicStream
+ // For input streams, this class is a wrapper around the InputStream
// class that passes all methods through.
//
- // For output streams, we use a different stragegy:
+ // For output streams, we use a different strategy:
// Slice sequences are encoded on the wire as a count of elements, followed
// by the sequence contents. For arbitrary .NET classes, we do not know how
// big the sequence that is eventually written will be. To avoid excessive
- // data copying, this class mantains a private bytes_ array of 254 bytes and,
+ // data copying, this class maintains a private bytes_ array of 254 bytes and,
// initially, writes data into that array. If more than 254 bytes end up being
// written, we write a dummy sequence size of 255 (which occupies five bytes
- // on the wire) into the BasicStream and, once this class is disposed, patch
+ // on the wire) into the stream and, once this class is disposed, patch
// that size to match the actual size. Otherwise, if the bytes_ buffer contains
// fewer than 255 bytes when this class is disposed, we write the sequence size
// as a single byte, followed by the contents of the bytes_ buffer.
//
- enum StreamType { Read, Write };
-
- public class StreamWrapper : System.IO.Stream, System.IDisposable
+ public class OutputStreamWrapper : System.IO.Stream, System.IDisposable
{
- //
- // Writeable stream constructor
- //
- public StreamWrapper(BasicStream s)
+ public OutputStreamWrapper(Ice.OutputStream s)
{
- type_ = StreamType.Write;
s_ = s;
spos_ = s.pos();
bytes_ = new byte[254];
@@ -54,48 +48,20 @@ namespace IceInternal
length_ = 0;
}
- //
- // Readable stream constructor
- //
- public StreamWrapper(int size, BasicStream s)
- {
- type_ = StreamType.Read;
- s_ = s;
- spos_ = 0;
- bytes_ = null;
- pos_ = 0;
- length_ = size;
- }
-
public override int Read(byte[] buffer, int offset, int count)
{
- Debug.Assert(buffer != null && offset >= 0 && count >= 0 && offset + count <= buffer.Length);
- try
- {
- s_.getBuffer().b.get(buffer, offset, count);
- }
- catch(System.Exception ex)
- {
- throw new IOException("could not read from stream", ex);
- }
- return count;
+ Debug.Assert(false);
+ return 0;
}
public override int ReadByte()
{
- try
- {
- return s_.getBuffer().b.get();
- }
- catch(System.Exception ex)
- {
- throw new IOException("could not read from stream", ex);
- }
+ Debug.Assert(false);
+ return 0;
}
public override void Write(byte[] array, int offset, int count)
{
- Debug.Assert(type_ == StreamType.Write);
Debug.Assert(array != null && offset >= 0 && count >= 0 && offset + count <= array.Length);
try
{
@@ -140,7 +106,6 @@ namespace IceInternal
public override void WriteByte(byte value)
{
- Debug.Assert(type_ == StreamType.Write);
try
{
if(bytes_ != null)
@@ -185,7 +150,7 @@ namespace IceInternal
{
get
{
- return true;
+ return false;
}
}
@@ -193,7 +158,7 @@ namespace IceInternal
{
get
{
- return type_ == StreamType.Write;
+ return true;
}
}
@@ -201,18 +166,7 @@ namespace IceInternal
{
get
{
- if(AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono)
- {
- //
- // The Mono deserialization implementation has a bug that causes a call to Seek() such
- // that the reading position is set to -1.
- //
- return false;
- }
- else
- {
- return type_ == StreamType.Read;
- }
+ return false;
}
}
@@ -265,8 +219,130 @@ namespace IceInternal
public override long Seek(long offset, SeekOrigin origin)
{
- Debug.Assert(type_ != StreamType.Write);
+ Debug.Assert(false);
+ return 0;
+ }
+
+ public override void SetLength(long value)
+ {
+ Debug.Assert(value >= 0);
+ length_ = value;
+ }
+
+ private Ice.OutputStream s_;
+ private int spos_;
+ private byte[] bytes_;
+ private int pos_;
+ private long length_;
+ }
+
+ public class InputStreamWrapper : System.IO.Stream, System.IDisposable
+ {
+ public InputStreamWrapper(int size, Ice.InputStream s)
+ {
+ s_ = s;
+ pos_ = 0;
+ length_ = size;
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ Debug.Assert(buffer != null && offset >= 0 && count >= 0 && offset + count <= buffer.Length);
+ try
+ {
+ s_.getBuffer().b.get(buffer, offset, count);
+ }
+ catch(System.Exception ex)
+ {
+ throw new IOException("could not read from stream", ex);
+ }
+ return count;
+ }
+
+ public override int ReadByte()
+ {
+ try
+ {
+ return s_.getBuffer().b.get();
+ }
+ catch(System.Exception ex)
+ {
+ throw new IOException("could not read from stream", ex);
+ }
+ }
+
+ public override void Write(byte[] array, int offset, int count)
+ {
+ Debug.Assert(false);
+ }
+
+ public override void WriteByte(byte value)
+ {
+ Debug.Assert(false);
+ }
+ public override bool CanRead
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public override bool CanWrite
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ public override bool CanSeek
+ {
+ get
+ {
+ if(AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono)
+ {
+ //
+ // The Mono deserialization implementation has a bug that causes a call to Seek() such
+ // that the reading position is set to -1.
+ //
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
+ public override void Flush()
+ {
+ }
+
+ public override long Length
+ {
+ get
+ {
+ return length_;
+ }
+ }
+
+ public override long Position
+ {
+ get
+ {
+ return pos_;
+ }
+
+ set
+ {
+ Seek(value, SeekOrigin.Begin);
+ }
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
// Deliberately no size check here--positioning beyond the limit of the stream is legal.
switch(origin)
{
@@ -297,14 +373,10 @@ namespace IceInternal
public override void SetLength(long value)
{
- Debug.Assert(type_ == StreamType.Write && value >= 0);
- length_ = value;
+ Debug.Assert(false);
}
- private StreamType type_;
- private BasicStream s_;
- private int spos_;
- private byte[] bytes_;
+ private Ice.InputStream s_;
private int pos_;
private long length_;
}
diff --git a/csharp/src/Ice/TcpEndpointI.cs b/csharp/src/Ice/TcpEndpointI.cs
index b0a09671cd5..6541470e53b 100644
--- a/csharp/src/Ice/TcpEndpointI.cs
+++ b/csharp/src/Ice/TcpEndpointI.cs
@@ -32,7 +32,7 @@ namespace IceInternal
_compress = false;
}
- public TcpEndpointI(ProtocolInstance instance, BasicStream s) :
+ public TcpEndpointI(ProtocolInstance instance, Ice.InputStream s) :
base(instance, s)
{
_timeout = s.readInt();
@@ -227,7 +227,7 @@ namespace IceInternal
return base.CompareTo(p);
}
- public override void streamWriteImpl(BasicStream s)
+ public override void streamWriteImpl(Ice.OutputStream s)
{
base.streamWriteImpl(s);
s.writeInt(_timeout);
@@ -350,7 +350,7 @@ namespace IceInternal
return endpt;
}
- public EndpointI read(BasicStream s)
+ public EndpointI read(Ice.InputStream s)
{
return new TcpEndpointI(_instance, s);
}
diff --git a/csharp/src/Ice/TraceUtil.cs b/csharp/src/Ice/TraceUtil.cs
index 26637636ad8..1e74629e761 100644
--- a/csharp/src/Ice/TraceUtil.cs
+++ b/csharp/src/Ice/TraceUtil.cs
@@ -16,16 +16,17 @@ namespace IceInternal
sealed class TraceUtil
{
- internal static void traceSend(BasicStream str, Ice.Logger logger, TraceLevels tl)
+ internal static void traceSend(Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
{
if(tl.protocol >= 1)
{
int p = str.pos();
- str.pos(0);
+ Ice.InputStream iss = new Ice.InputStream(str.instance(), str.getEncoding(), str.getBuffer(), false);
+ iss.pos(0);
using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
{
- byte type = printMessage(s, str);
+ byte type = printMessage(s, iss);
logger.trace(tl.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.ToString());
}
@@ -33,7 +34,7 @@ namespace IceInternal
}
}
- internal static void traceRecv(BasicStream str, Ice.Logger logger, TraceLevels tl)
+ internal static void traceRecv(Ice.InputStream str, Ice.Logger logger, TraceLevels tl)
{
if(tl.protocol >= 1)
{
@@ -50,7 +51,26 @@ namespace IceInternal
}
}
- internal static void trace(string heading, BasicStream str, Ice.Logger logger, TraceLevels tl)
+ internal static void trace(string heading, Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
+ {
+ if(tl.protocol >= 1)
+ {
+ int p = str.pos();
+ Ice.InputStream iss = new Ice.InputStream(str.instance(), str.getEncoding(), str.getBuffer(), false);
+ iss.pos(0);
+
+ using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
+ {
+ s.Write(heading);
+ printMessage(s, iss);
+
+ logger.trace(tl.protocolCat, s.ToString());
+ }
+ str.pos(p);
+ }
+ }
+
+ internal static void trace(string heading, Ice.InputStream str, Ice.Logger logger, TraceLevels tl)
{
if(tl.protocol >= 1)
{
@@ -85,7 +105,7 @@ namespace IceInternal
}
}
- public static void dumpStream(BasicStream stream)
+ public static void dumpStream(Ice.InputStream stream)
{
int pos = stream.pos();
stream.pos(0);
@@ -152,7 +172,7 @@ namespace IceInternal
}
}
- private static void printIdentityFacetOperation(System.IO.StringWriter s, BasicStream str)
+ private static void printIdentityFacetOperation(System.IO.StringWriter s, Ice.InputStream str)
{
try
{
@@ -176,7 +196,7 @@ namespace IceInternal
}
}
- private static void printRequest(System.IO.StringWriter s, BasicStream str)
+ private static void printRequest(System.IO.StringWriter s, Ice.InputStream str)
{
int requestId = str.readInt();
s.Write("\nrequest id = " + requestId);
@@ -188,7 +208,7 @@ namespace IceInternal
printRequestHeader(s, str);
}
- private static void printBatchRequest(System.IO.StringWriter s, BasicStream str)
+ private static void printBatchRequest(System.IO.StringWriter s, Ice.InputStream str)
{
int batchRequestNum = str.readInt();
s.Write("\nnumber of requests = " + batchRequestNum);
@@ -200,7 +220,7 @@ namespace IceInternal
}
}
- private static void printReply(System.IO.StringWriter s, BasicStream str)
+ private static void printReply(System.IO.StringWriter s, Ice.InputStream str)
{
int requestId = str.readInt();
s.Write("\nrequest id = " + requestId);
@@ -302,7 +322,7 @@ namespace IceInternal
if(replyStatus == ReplyStatus.replyOK || replyStatus == ReplyStatus.replyUserException)
{
- Ice.EncodingVersion v = str.skipEncaps();
+ Ice.EncodingVersion v = str.skipEncapsulation();
if(!v.Equals(Ice.Util.Encoding_1_0))
{
s.Write("\nencoding = ");
@@ -311,7 +331,7 @@ namespace IceInternal
}
}
- private static void printRequestHeader(System.IO.StringWriter s, BasicStream str)
+ private static void printRequestHeader(System.IO.StringWriter s, Ice.InputStream str)
{
printIdentityFacetOperation(s, str);
@@ -359,7 +379,7 @@ namespace IceInternal
}
}
- Ice.EncodingVersion v = str.skipEncaps();
+ Ice.EncodingVersion v = str.skipEncapsulation();
if(!v.Equals(Ice.Util.Encoding_1_0))
{
s.Write("\nencoding = ");
@@ -372,7 +392,7 @@ namespace IceInternal
}
}
- private static byte printHeader(System.IO.StringWriter s, BasicStream str)
+ private static byte printHeader(System.IO.StringWriter s, Ice.InputStream str)
{
try
{
@@ -432,7 +452,7 @@ namespace IceInternal
}
}
- private static byte printMessage(System.IO.StringWriter s, BasicStream str)
+ private static byte printMessage(System.IO.StringWriter s, Ice.InputStream str)
{
byte type = printHeader(s, str);
@@ -473,7 +493,7 @@ namespace IceInternal
return type;
}
- internal static void traceHeader(string heading, BasicStream str, Ice.Logger logger, TraceLevels tl)
+ internal static void traceHeader(string heading, Ice.InputStream str, Ice.Logger logger, TraceLevels tl)
{
if(tl.protocol >= 1)
{
diff --git a/csharp/src/Ice/UdpEndpointI.cs b/csharp/src/Ice/UdpEndpointI.cs
index 744f990e2f9..28807066dd3 100644
--- a/csharp/src/Ice/UdpEndpointI.cs
+++ b/csharp/src/Ice/UdpEndpointI.cs
@@ -36,10 +36,10 @@ namespace IceInternal
_compress = false;
}
- public UdpEndpointI(ProtocolInstance instance, BasicStream s) :
+ public UdpEndpointI(ProtocolInstance instance, Ice.InputStream s) :
base(instance, s)
{
- if(s.getReadEncoding().Equals(Ice.Util.Encoding_1_0))
+ if(s.getEncoding().Equals(Ice.Util.Encoding_1_0))
{
s.readByte();
s.readByte();
@@ -254,10 +254,10 @@ namespace IceInternal
//
// Marshal the endpoint
//
- public override void streamWriteImpl(BasicStream s)
+ public override void streamWriteImpl(Ice.OutputStream s)
{
base.streamWriteImpl(s);
- if(s.getWriteEncoding().Equals(Ice.Util.Encoding_1_0))
+ if(s.getEncoding().Equals(Ice.Util.Encoding_1_0))
{
Ice.Util.Protocol_1_0.write__(s);
Ice.Util.Encoding_1_0.write__(s);
@@ -428,7 +428,7 @@ namespace IceInternal
return endpt;
}
- public EndpointI read(BasicStream s)
+ public EndpointI read(Ice.InputStream s)
{
return new UdpEndpointI(_instance, s);
}
diff --git a/csharp/src/Ice/UnknownSlicedObject.cs b/csharp/src/Ice/UnknownSlicedObject.cs
index 2ef850e87c3..55dd851f036 100644
--- a/csharp/src/Ice/UnknownSlicedObject.cs
+++ b/csharp/src/Ice/UnknownSlicedObject.cs
@@ -32,16 +32,16 @@ namespace Ice
return _unknownTypeId;
}
- public override void write__(IceInternal.BasicStream os__)
+ public override void write__(OutputStream os__)
{
- os__.startWriteObject(_slicedData);
- os__.endWriteObject();
+ os__.startObject(_slicedData);
+ os__.endObject();
}
- public override void read__(IceInternal.BasicStream is__)
+ public override void read__(InputStream is__)
{
- is__.startReadObject();
- _slicedData = is__.endReadObject(true);
+ is__.startObject();
+ _slicedData = is__.endObject(true);
}
private string _unknownTypeId;
diff --git a/csharp/src/Ice/Util.cs b/csharp/src/Ice/Util.cs
index f1f6d2170ca..0cae06cbb2d 100644
--- a/csharp/src/Ice/Util.cs
+++ b/csharp/src/Ice/Util.cs
@@ -113,6 +113,11 @@ namespace Ice
/// The batch request interceptor.
/// </summary>
public BatchRequestInterceptor batchRequestInterceptor;
+
+ /// <summary>
+ /// The value factory manager.
+ /// </summary>
+ public ValueFactoryManager valueFactoryManager;
}
/// <summary>
@@ -447,79 +452,6 @@ namespace Ice
}
/// <summary>
- /// Creates an input stream for dynamic invocation and dispatch. The stream uses
- /// the communicator's default encoding version. The given data is copied.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <param name="bytes">An encoded request or reply.</param>
- /// <returns>The input stream.</returns>
- public static InputStream createInputStream(Communicator communicator, byte[] bytes)
- {
- return new InputStreamI(communicator, bytes, true);
- }
-
- /// <summary>
- /// Creates an input stream for dynamic invocation and dispatch. The stream uses
- /// the given encoding version.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <param name="bytes">An encoded request or reply.</param>
- /// <param name="v">The desired encoding version.</param>
- /// <returns>The input stream.</returns>
- public static InputStream createInputStream(Communicator communicator, byte[] bytes, EncodingVersion v)
- {
- return new InputStreamI(communicator, bytes, v, true);
- }
-
- /// <summary>
- /// Wraps encoded data with an input stream for dynamic invocation and dispatch.
- /// The stream uses the communicator's default encoding version.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <param name="bytes">An encoded request or reply.</param>
- /// <returns>The input stream.</returns>
- public static InputStream wrapInputStream(Communicator communicator, byte[] bytes)
- {
- return new InputStreamI(communicator, bytes, false);
- }
-
- /// <summary>
- /// Wraps encoded data with an input stream for dynamic invocation and dispatch.
- /// The stream uses the given encoding version.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <param name="bytes">An encoded request or reply.</param>
- /// <param name="v">The desired encoding version.</param>
- /// <returns>The input stream.</returns>
- public static InputStream wrapInputStream(Communicator communicator, byte[] bytes, EncodingVersion v)
- {
- return new InputStreamI(communicator, bytes, v, false);
- }
-
- /// <summary>
- /// Creates an output stream for dynamic invocation and dispatch. The stream uses
- /// the communicator's default encoding version.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <returns>The output stream.</returns>
- public static OutputStream createOutputStream(Communicator communicator)
- {
- return new OutputStreamI(communicator);
- }
-
- /// <summary>
- /// Creates an output stream for dynamic invocation and dispatch. The stream uses
- /// the given encoding version.
- /// </summary>
- /// <param name="communicator">The communicator for the stream.</param>
- /// <param name="v">The desired encoding version.</param>
- /// <returns>The output stream.</returns>
- public static OutputStream createOutputStream(Communicator communicator, EncodingVersion v)
- {
- return new OutputStreamI(communicator, v);
- }
-
- /// <summary>
/// Returns the process-wide logger.
/// </summary>
/// <returns>The process-wide logger.</returns>
@@ -555,7 +487,7 @@ namespace Ice
/// <returns>The Ice version.</returns>
public static string stringVersion()
{
- return "3.6.1"; // "A.B.C", with A=major, B=minor, C=patch
+ return "3.7.0"; // "A.B.C", with A=major, B=minor, C=patch
}
/// <summary>
@@ -566,7 +498,7 @@ namespace Ice
/// <returns>The Ice version.</returns>
public static int intVersion()
{
- return 30601; // AABBCC, with AA=major, BB=minor, CC=patch
+ return 30700; // AABBCC, with AA=major, BB=minor, CC=patch
}
/// <summary>
diff --git a/csharp/src/Ice/ValueFactoryManager.cs b/csharp/src/Ice/ValueFactoryManager.cs
new file mode 100644
index 00000000000..c8b7b73e045
--- /dev/null
+++ b/csharp/src/Ice/ValueFactoryManager.cs
@@ -0,0 +1,45 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+namespace IceInternal
+{
+
+ using System.Collections.Generic;
+
+ public sealed class ValueFactoryManagerI : Ice.ValueFactoryManager
+ {
+ public void add(Ice.ValueFactory factory, string id)
+ {
+ lock(this)
+ {
+ if(_factoryMap.ContainsKey(id))
+ {
+ Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
+ ex.id = id;
+ ex.kindOfObject = "value factory";
+ throw ex;
+ }
+ _factoryMap[id] = factory;
+ }
+ }
+
+ public Ice.ValueFactory find(string id)
+ {
+ lock(this)
+ {
+ Ice.ValueFactory factory = null;
+ _factoryMap.TryGetValue(id, out factory);
+ return factory;
+ }
+ }
+
+ private Dictionary<string, Ice.ValueFactory> _factoryMap = new Dictionary<string, Ice.ValueFactory>();
+ }
+
+}
diff --git a/csharp/src/Ice/WSEndpoint.cs b/csharp/src/Ice/WSEndpoint.cs
index 1aecc788f0f..be0e2d9dbb7 100644
--- a/csharp/src/Ice/WSEndpoint.cs
+++ b/csharp/src/Ice/WSEndpoint.cs
@@ -21,7 +21,7 @@ namespace IceInternal
public interface WSEndpointDelegate
{
Ice.EndpointInfo getWSInfo(string resource);
- };
+ }
sealed class WSEndpoint : EndpointI
{
@@ -45,7 +45,7 @@ namespace IceInternal
}
}
- internal WSEndpoint(ProtocolInstance instance, EndpointI del, BasicStream s)
+ internal WSEndpoint(ProtocolInstance instance, EndpointI del, Ice.InputStream s)
{
_instance = instance;
_delegate = (IPEndpointI)del;
@@ -94,12 +94,12 @@ namespace IceInternal
return _delegate.protocol();
}
- public override void streamWrite(BasicStream s)
+ public override void streamWrite(Ice.OutputStream s)
{
- s.startWriteEncaps();
+ s.startEncapsulation();
_delegate.streamWriteImpl(s);
s.writeString(_resource);
- s.endWriteEncaps();
+ s.endEncapsulation();
}
public override int timeout()
@@ -356,7 +356,7 @@ namespace IceInternal
return new WSEndpoint(_instance, _delegate.create(args, oaEndpoint), args);
}
- public EndpointI read(BasicStream s)
+ public EndpointI read(Ice.InputStream s)
{
return new WSEndpoint(_instance, _delegate.read(s), s);
}
diff --git a/csharp/src/Ice/WSTransceiver.cs b/csharp/src/Ice/WSTransceiver.cs
index c84f3018ab4..4c83b0148cb 100644
--- a/csharp/src/Ice/WSTransceiver.cs
+++ b/csharp/src/Ice/WSTransceiver.cs
@@ -23,7 +23,7 @@ namespace IceInternal
public interface WSTransceiverDelegate
{
Ice.ConnectionInfo getWSInfo(Dictionary<string, string> headers);
- };
+ }
sealed class WSTransceiver : Transceiver
{
diff --git a/csharp/src/IceBox/AssemblyInfo.cs b/csharp/src/IceBox/AssemblyInfo.cs
index a7c46f82547..7fcc7ab9a7b 100644
--- a/csharp/src/IceBox/AssemblyInfo.cs
+++ b/csharp/src/IceBox/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceBox/AssemblyInfoExe.cs b/csharp/src/IceBox/AssemblyInfoExe.cs
index 12002ab1129..77de9773cd5 100644
--- a/csharp/src/IceBox/AssemblyInfoExe.cs
+++ b/csharp/src/IceBox/AssemblyInfoExe.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceBox/Makefile.mak b/csharp/src/IceBox/Makefile.mak
index 744421f30e9..59fd20b307d 100644
--- a/csharp/src/IceBox/Makefile.mak
+++ b/csharp/src/IceBox/Makefile.mak
@@ -74,11 +74,11 @@ iceboxnetconfig:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Ice" culture="neutral" publicKeyToken="$(publicKeyToken)"/>
- <codeBase version="3.6.1.0" href="..\Assemblies\Ice.dll"/>
+ <codeBase version="3.7.0.0" href="..\Assemblies\Ice.dll"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="IceBox" culture="neutral" publicKeyToken="$(publicKeyToken)"/>
- <codeBase version="3.6.1.0" href="..\Assemblies\IceBox.dll"/>
+ <codeBase version="3.7.0.0" href="..\Assemblies\IceBox.dll"/>
</dependentAssembly>
<!--
This allows iceboxnet to load the IceSSL plug-in using a strong name. We omit the
@@ -87,7 +87,7 @@ iceboxnetconfig:
-->
<dependentAssembly>
<assemblyIdentity name="IceSSL"/>
- <codeBase version="3.6.1.0" href="..\Assemblies\IceSSL.dll"/>
+ <codeBase version="3.7.0.0" href="..\Assemblies\IceSSL.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
diff --git a/csharp/src/IceDiscovery/AssemblyInfo.cs b/csharp/src/IceDiscovery/AssemblyInfo.cs
index 74b46242d3a..08a6750bbf0 100644
--- a/csharp/src/IceDiscovery/AssemblyInfo.cs
+++ b/csharp/src/IceDiscovery/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceGrid/AssemblyInfo.cs b/csharp/src/IceGrid/AssemblyInfo.cs
index 329efe5a1e1..a981c429ad8 100644
--- a/csharp/src/IceGrid/AssemblyInfo.cs
+++ b/csharp/src/IceGrid/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceGrid/Makefile b/csharp/src/IceGrid/Makefile
index f57e5ae9483..61ffca05a4f 100644
--- a/csharp/src/IceGrid/Makefile
+++ b/csharp/src/IceGrid/Makefile
@@ -20,9 +20,6 @@ SLICE_SRCS = $(SDIR)/Admin.ice \
$(SDIR)/Descriptor.ice \
$(SDIR)/Exception.ice \
$(SDIR)/FileParser.ice \
- $(SDIR)/Locator.ice \
- $(SDIR)/Observer.ice \
- $(SDIR)/Query.ice \
$(SDIR)/Registry.ice \
$(SDIR)/Session.ice \
$(SDIR)/UserAccountMapper.ice
diff --git a/csharp/src/IceGrid/Makefile.mak b/csharp/src/IceGrid/Makefile.mak
index 521e5f7f6f1..e9dc6c4c528 100644
--- a/csharp/src/IceGrid/Makefile.mak
+++ b/csharp/src/IceGrid/Makefile.mak
@@ -20,9 +20,6 @@ GEN_SRCS = $(GDIR)\Admin.cs \
$(GDIR)\Descriptor.cs \
$(GDIR)\Exception.cs \
$(GDIR)\FileParser.cs \
- $(GDIR)\Locator.cs \
- $(GDIR)\Observer.cs \
- $(GDIR)\Query.cs \
$(GDIR)\Registry.cs \
$(GDIR)\Session.cs \
$(GDIR)\UserAccountMapper.cs
diff --git a/csharp/src/IceLocatorDiscovery/AssemblyInfo.cs b/csharp/src/IceLocatorDiscovery/AssemblyInfo.cs
index 88ff5fd97ba..1644199cea6 100644
--- a/csharp/src/IceLocatorDiscovery/AssemblyInfo.cs
+++ b/csharp/src/IceLocatorDiscovery/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IcePatch2/AssemblyInfo.cs b/csharp/src/IcePatch2/AssemblyInfo.cs
index 1145a373114..2583684ee9e 100644
--- a/csharp/src/IcePatch2/AssemblyInfo.cs
+++ b/csharp/src/IcePatch2/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceSSL/AssemblyInfo.cs b/csharp/src/IceSSL/AssemblyInfo.cs
index ca2d824f8d7..fcf239d3ea8 100644
--- a/csharp/src/IceSSL/AssemblyInfo.cs
+++ b/csharp/src/IceSSL/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]
diff --git a/csharp/src/IceSSL/EndpointI.cs b/csharp/src/IceSSL/EndpointI.cs
index 35090ab612f..998c604c367 100644
--- a/csharp/src/IceSSL/EndpointI.cs
+++ b/csharp/src/IceSSL/EndpointI.cs
@@ -33,7 +33,7 @@ namespace IceSSL
_compress = false;
}
- internal EndpointI(Instance instance, IceInternal.BasicStream s) :
+ internal EndpointI(Instance instance, Ice.InputStream s) :
base(instance, s)
{
_instance = instance;
@@ -261,7 +261,7 @@ namespace IceSSL
return base.CompareTo(p);
}
- public override void streamWriteImpl(IceInternal.BasicStream s)
+ public override void streamWriteImpl(Ice.OutputStream s)
{
base.streamWriteImpl(s);
s.writeInt(_timeout);
@@ -386,7 +386,7 @@ namespace IceSSL
return endpt;
}
- public IceInternal.EndpointI read(IceInternal.BasicStream s)
+ public IceInternal.EndpointI read(Ice.InputStream s)
{
return new EndpointI(_instance, s);
}
diff --git a/csharp/src/IceSSL/RFC2253.cs b/csharp/src/IceSSL/RFC2253.cs
index 46841e1303a..c535cd5b34b 100644
--- a/csharp/src/IceSSL/RFC2253.cs
+++ b/csharp/src/IceSSL/RFC2253.cs
@@ -32,9 +32,9 @@ namespace IceSSL
}
internal string
- ice_name()
+ ice_id()
{
- return "RFC2253::ParseException";
+ return "::RFC2253::ParseException";
}
internal string reason;
diff --git a/csharp/src/IceStorm/AssemblyInfo.cs b/csharp/src/IceStorm/AssemblyInfo.cs
index da89e57a0b3..881d17e2c5e 100644
--- a/csharp/src/IceStorm/AssemblyInfo.cs
+++ b/csharp/src/IceStorm/AssemblyInfo.cs
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyProduct("Ice")]
[assembly: AssemblyCopyright("© 2003-2015 ZeroC, Inc.")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("3.6.1")]
+[assembly: AssemblyVersion("3.7.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: ComVisible(false)]