// **********************************************************************
//
// Copyright (c) 2003-2017 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
{
///
/// Callback class to inform an application when a Slice class has been unmarshaled
/// from an input stream.
///
public interface ReadObjectCallback
{
///
/// The Ice run time calls this method when it has fully unmarshaled the state
/// of a Slice class.
///
/// The unmarshaled Slice class.
void invoke(Ice.Object obj);
}
///
/// Interface for input streams used to extract Slice types from a sequence of bytes.
///
public interface InputStream
{
///
/// Returns the communicator for this input stream.
///
/// The communicator.
Communicator communicator();
///
/// 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.
///
/// 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.
void sliceObjects(bool slice);
///
/// Extracts a boolean value from the stream.
///
/// The extracted boolean.
bool readBool();
///
/// Extracts a sequence of boolean values from the stream.
///
/// The extracted boolean sequence.
bool[] readBoolSeq();
///
/// Extracts a byte value from the stream.
///
/// The extracted byte.
byte readByte();
///
/// Extracts a sequence of byte values from the stream.
///
/// The extracted byte sequence.
byte[] readByteSeq();
///
/// Extracts a serializable .NET object from the stream.
///
/// The deserialized .NET object.
object readSerializable();
///
/// Extracts a short value from the stream.
///
/// The extracted short value.
short readShort();
///
/// Extracts a sequence of short values from the stream.
///
/// The extracted short sequence.
short[] readShortSeq();
///
/// Extracts an integer value from the stream.
///
/// The extracted integer value.
int readInt();
///
/// Extracts a sequence of integer values from the stream.
///
/// The extracted integer sequence.
int[] readIntSeq();
///
/// Extracts a long value from the stream.
///
/// The extracted long value.
long readLong();
///
/// Extracts a sequence of long values from the stream.
///
/// The extracted long sequence.
long[] readLongSeq();
///
/// Extracts a float value from the stream.
///
/// The extracted float value.
float readFloat();
///
/// Extracts a sequence of float values from the stream.
///
/// The extracted float sequence.
float[] readFloatSeq();
///
/// Extracts a double value from the stream.
///
/// The extracted double value.
double readDouble();
///
/// Extracts a sequence of double values from the stream.
///
/// The extracted double sequence.
double[] readDoubleSeq();
///
/// Extracts a string from the stream.
///
/// The extracted double value.
string readString();
///
/// Extracts a sequence of strings from the stream.
///
/// The extracted string sequence.
string[] readStringSeq();
///
/// Extracts a size from the stream.
///
/// The extracted size.
int readSize();
///
/// Extracts and check a sequence size from the stream. The check ensures not too much memory will
/// be pre-allocated for the sequence.
///
/// The minimum size of an element of the sequence.
/// The extracted size.
int readAndCheckSeqSize(int minSize);
///
/// Extracts a proxy from the stream.
///
/// The extracted proxy.
ObjectPrx readProxy();
///
/// Extracts the index of a Slice class from the stream.
///
/// 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.
void readObject(ReadObjectCallback cb);
///
/// Read an enumerated value.
///
///
/// The maximum enumerator value in the definition.
/// The enumerator.
int readEnum(int maxValue);
///
/// Extracts a user exception from the stream and throws it.
///
void throwException();
///
/// 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.
///
/// A factory that creates UserExceptionReader instances.
void throwException(UserExceptionReaderFactory factory);
///
/// Marks the start of an Ice object.
///
void startObject();
///
/// Marks the end of an Ice object.
///
/// True if unknown slices should be preserved, false otherwise.
/// A SlicedData object containing the preserved slices for unknown types.
SlicedData endObject(bool preserve);
///
/// Marks the start of a user exception.
///
void startException();
///
/// Marks the end of a user exception.
///
/// True if unknown slices should be preserved, false otherwise.
/// A SlicedData object containing the preserved slices for unknown types.
SlicedData endException(bool preserve);
///
/// Reads the start of an object or exception slice.
///
/// The Slice type ID for this slice.
string startSlice();
///
/// Indicates that the end of an object or exception slice has been reached.
///
void endSlice();
///
/// Skips over an object or exception slice.
///
void skipSlice();
///
/// Reads the start of an encapsulation.
///
/// The encapsulation encoding version.
EncodingVersion startEncapsulation();
///
/// Indicates that the end of an encapsulation has been reached.
///
void endEncapsulation();
///
/// Skips over an encapsulation.
///
/// The encapsulation encoding version.
EncodingVersion skipEncapsulation();
///
/// Determines the current encoding version.
///
/// The encoding version.
EncodingVersion getEncoding();
///
/// 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.
///
void readPendingObjects();
///
/// Resets the read position of the stream to the beginning.
///
void rewind();
///
/// Skips ahead in the stream.
///
/// The number of bytes to skip.
void skip(int sz);
///
/// Skips over a size value.
///
void skipSize();
///
/// Determine if an optional value is available for reading.
///
/// The tag associated with the value.
/// The optional format for the value.
/// True if the value is present, false otherwise.
bool readOptional(int tag, OptionalFormat format);
///
/// Determine the current position in the stream.
///
/// The current position.
int pos();
///
/// 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.
///
void destroy();
}
///
/// Interface for output streams used to write Slice types to a sequence
/// of bytes.
///
public interface OutputStream
{
///
/// Returns the communicator for this output stream.
///
Communicator communicator();
///
/// Writes a boolean to the stream.
///
/// The boolean to write to the stream.
void writeBool(bool v);
///
/// Writes a sequence of booleans to the stream.
///
/// The sequence of booleans to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeBoolSeq(bool[] v);
///
/// Writes a byte to the stream.
///
/// The byte to write to the stream.
void writeByte(byte v);
///
/// Writes a sequence of bytes to the stream.
///
/// The sequence of bytes to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeByteSeq(byte[] v);
///
/// Writes a serializable .NET object to the stream.
///
/// The serializable object to write.
void writeSerializable(object v);
///
/// Writes a short to the stream.
///
/// The short to write to the stream.
void writeShort(short v);
///
/// Writes a sequence of shorts to the stream.
///
/// The sequence of shorts to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeShortSeq(short[] v);
///
/// Writes an integer to the stream.
///
/// The integer to write to the stream.
void writeInt(int v);
///
/// Writes a sequence of integers to the stream.
///
/// The sequence of integers to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeIntSeq(int[] v);
///
/// Writes a long to the stream.
///
/// The long to write to the stream.
void writeLong(long v);
///
/// Writes a sequence of longs to the stream.
///
/// The sequence of longs to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeLongSeq(long[] v);
///
/// Writes a float to the stream.
///
/// The float to write to the stream.
void writeFloat(float v);
///
/// Writes a sequence of floats to the stream.
///
/// The sequence of floats to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeFloatSeq(float[] v);
///
/// Writes a double to the stream.
///
/// The double to write to the stream.
void writeDouble(double v);
///
/// Writes a sequence of doubles to the stream.
///
/// The sequence of doubles to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeDoubleSeq(double[] v);
///
/// Writes a string to the stream.
///
/// The string to write to the stream.
/// Passing null causes an empty string to be written to the stream.
void writeString(string v);
///
/// Writes a sequence of strings to the stream.
///
/// The sequence of strings to write.
/// Passing null causes an empty sequence to be written to the stream.
void writeStringSeq(string[] v);
///
/// Writes a size to the stream.
///
/// The size to write.
void writeSize(int sz);
///
/// Writes a proxy to the stream.
///
/// The proxy to write.
void writeProxy(ObjectPrx v);
///
/// Writes a Slice class to the stream.
///
/// The class to write. This method writes the index of a Slice class; the state of the
/// class is written once writePendingObjects is called.
void writeObject(Ice.Object v);
///
/// Write an enumerated value.
///
/// The enumerator.
/// The number of enumerators in the definition.
void writeEnum(int v, int limit);
///
/// Writes a user exception to the stream.
///
/// The user exception to write.
void writeException(UserException ex);
///
/// Marks the start of an Ice object.
///
/// Preserved slices for this object, or null.
void startObject(SlicedData slicedData);
///
/// Marks the end of an Ice object.
///
void endObject();
///
/// Marks the start of a user exception.
///
/// Preserved slices for this object, or null.
void startException(SlicedData slicedData);
///
/// Marks the end of a user exception.
///
void endException();
///
/// Marks the start of a new slice for an Ice object or user exception.
///
/// The Slice type ID corresponding to this slice.
/// The Slice compact type ID corresponding to this slice.
/// True if this is the last slice, false otherwise.
void startSlice(string typeId, int compactId, bool last);
///
/// Marks the end of a slice for an Ice object or user exception.
///
void endSlice();
///
/// Writes the start of an encapsulation to the stream.
///
/// The encoding version of the encapsulation.
/// The format to use for encoding objects and user exceptions.
void startEncapsulation(EncodingVersion encoding, FormatType format);
///
/// Writes the start of an encapsulation to the stream.
///
void startEncapsulation();
///
/// Ends the previous encapsulation.
///
void endEncapsulation();
///
/// Determines the current encoding version.
///
/// The encoding version.
EncodingVersion getEncoding();
///
/// Writes the state of Slice classes whose index was previously
/// written with writeObject to the stream.
///
void writePendingObjects();
///
/// Write the header information for an optional value.
///
/// The numeric tag associated with the value.
/// The optional format of the value.
/// True if the optional should be written, false otherwise.
bool writeOptional(int tag, OptionalFormat format);
///
/// Determines the current position in the stream.
///
/// The current position.
int pos();
///
/// Inserts a fixed 32-bit size value into the stream at the given position.
///
/// The 32-bit size value.
/// The position at which to write the value.
void rewrite(int sz, int pos);
///
/// Returns the current position and allocates four bytes for a fixed-length (32-bit)
/// size value.
///
/// The current position.
int startSize();
///
/// Computes the amount of data written since the previous call to startSize and
/// writes that value at the saved position.
///
/// The saved position at which to write the size.
void endSize(int pos);
///
/// Indicates that the marshaling of a request or reply is finished.
///
/// The byte sequence containing the encoded request or reply.
byte[] finished();
///
/// Resets this output stream. This method allows the stream to be reused, to avoid creating
/// unnecessary garbage.
///
///
/// 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.
void reset(bool clearBuffer);
///
/// 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.
///
void destroy();
}
///
/// Base class for extracting objects from an input stream.
///
public abstract class ObjectReader : ObjectImpl
{
///
/// Read the object's data members.
///
/// The input stream to read from.
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);
}
}
///
/// Base class for writing objects to an output stream.
///
public abstract class ObjectWriter : ObjectImpl
{
///
/// Writes the state of this Slice class to an output stream.
///
/// The stream to write to.
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_;
}
}