From 10c57a6079f3ec05cb1ba189a05f6b33167db057 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 31 Jul 2024 16:47:59 -0400 Subject: [PATCH] Remove DefaultFormat, use null for unspecified class format --- cpp/src/slice2cs/Gen.cpp | 2 +- csharp/src/Ice/CurrentExtensions.cs | 2 +- csharp/src/Ice/FormatType.cs | 1 - csharp/src/Ice/Internal/OpaqueEndpointI.cs | 2 +- csharp/src/Ice/Internal/OutgoingAsync.cs | 4 +-- csharp/src/Ice/OutputStream.cs | 32 +++++-------------- csharp/src/Ice/Proxy.cs | 8 ++--- .../objects/UnexpectedObjectExceptionTestI.cs | 2 +- 8 files changed, 18 insertions(+), 35 deletions(-) diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index a03156f7daa..befe1839a10 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -59,7 +59,7 @@ namespace { case DefaultFormat: { - return "Ice.FormatType.DefaultFormat"; + return "null"; } case CompactFormat: { diff --git a/csharp/src/Ice/CurrentExtensions.cs b/csharp/src/Ice/CurrentExtensions.cs index e2fcce67a42..3bbbda49f48 100644 --- a/csharp/src/Ice/CurrentExtensions.cs +++ b/csharp/src/Ice/CurrentExtensions.cs @@ -25,7 +25,7 @@ public static OutgoingResponse createOutgoingResponse( this Current current, TResult result, Action marshal, - FormatType formatType = FormatType.DefaultFormat) + FormatType? formatType = null) { OutputStream ostr = current.startReplyStream(); if (current.requestId != 0) diff --git a/csharp/src/Ice/FormatType.cs b/csharp/src/Ice/FormatType.cs index ea66cf23d8b..5d7be910ae4 100644 --- a/csharp/src/Ice/FormatType.cs +++ b/csharp/src/Ice/FormatType.cs @@ -9,7 +9,6 @@ namespace Ice; /// public enum FormatType { - DefaultFormat, CompactFormat, SlicedFormat } diff --git a/csharp/src/Ice/Internal/OpaqueEndpointI.cs b/csharp/src/Ice/Internal/OpaqueEndpointI.cs index 9a2285e9976..10b98ec5c4b 100644 --- a/csharp/src/Ice/Internal/OpaqueEndpointI.cs +++ b/csharp/src/Ice/Internal/OpaqueEndpointI.cs @@ -40,7 +40,7 @@ public OpaqueEndpointI(short type, Ice.InputStream s) // public override void streamWrite(Ice.OutputStream s) { - s.startEncapsulation(_rawEncoding, Ice.FormatType.DefaultFormat); + s.startEncapsulation(_rawEncoding); s.writeBlob(_rawBytes); s.endEncapsulation(); } diff --git a/csharp/src/Ice/Internal/OutgoingAsync.cs b/csharp/src/Ice/Internal/OutgoingAsync.cs index 8a00472c8c7..159ff10b296 100644 --- a/csharp/src/Ice/Internal/OutgoingAsync.cs +++ b/csharp/src/Ice/Internal/OutgoingAsync.cs @@ -1058,7 +1058,7 @@ protected void invoke(string operation, bool synchronous) public void invoke(string operation, Ice.OperationMode mode, - Ice.FormatType format, + Ice.FormatType? format, Dictionary context, bool synchronous, System.Action write) @@ -1144,7 +1144,7 @@ public OutgoingAsyncT(Ice.ObjectPrxHelperBase prx, public void invoke(string operation, Ice.OperationMode mode, - Ice.FormatType format, + Ice.FormatType? format, Dictionary context, bool synchronous, System.Action write = null, diff --git a/csharp/src/Ice/OutputStream.cs b/csharp/src/Ice/OutputStream.cs index 310975d2739..94d1b042758 100644 --- a/csharp/src/Ice/OutputStream.cs +++ b/csharp/src/Ice/OutputStream.cs @@ -3,8 +3,7 @@ #nullable enable using System.Diagnostics; -using System.Net.Http.Headers; -using System.Text; + using Protocol = Ice.Internal.Protocol; namespace Ice; @@ -22,8 +21,6 @@ public sealed class OutputStream /// The class format. public OutputStream(EncodingVersion? encoding = null, FormatType format = FormatType.CompactFormat) { - Debug.Assert(format != FormatType.DefaultFormat); // TODO: remove default format from enum - _buf = new Internal.Buffer(); _encoding = encoding ?? Util.currentEncoding; _format = format; @@ -68,15 +65,6 @@ public void clear() } } - /// - /// Sets the encoding format for class and exception instances. - /// - /// The encoding format. - public void setFormat(FormatType fmt) - { - _format = fmt; - } - /// /// Retrieves the closure object associated with this stream. /// @@ -225,7 +213,7 @@ public void startEncapsulation() } else { - startEncapsulation(_encoding, FormatType.DefaultFormat); + startEncapsulation(_encoding, format: null); } } @@ -233,8 +221,9 @@ public void startEncapsulation() /// Writes the start of an encapsulation to the stream. /// /// The encoding version of the encapsulation. - /// Specify the compact or sliced format. - public void startEncapsulation(EncodingVersion encoding, FormatType format) + /// Specify the compact or sliced format. When null, use the OutputStream's class format. + /// + public void startEncapsulation(EncodingVersion encoding, FormatType? format = null) { Protocol.checkSupportedEncoding(encoding); @@ -251,7 +240,7 @@ public void startEncapsulation(EncodingVersion encoding, FormatType format) curr.next = _encapsStack; _encapsStack = curr; - _encapsStack.format = format; + _encapsStack.format = format ?? _format; _encapsStack.setEncoding(encoding); _encapsStack.start = _buf.b.position(); @@ -1771,7 +1760,7 @@ public void expand(int n) private Ice.Internal.Buffer _buf; private object? _closure; - private FormatType _format; + private readonly FormatType _format; private enum SliceType { NoSlice, ValueSlice, ExceptionSlice } @@ -2341,7 +2330,7 @@ internal void setEncoding(EncodingVersion encoding) internal int start; internal EncodingVersion encoding; internal bool encoding_1_0; - internal FormatType format = FormatType.DefaultFormat; + internal FormatType format; internal EncapsEncoder? encoder; @@ -2380,11 +2369,6 @@ private void initEncaps() _encapsStack.setEncoding(_encoding); } - if (_encapsStack.format == FormatType.DefaultFormat) - { - _encapsStack.format = _format; - } - if (_encapsStack.encoder == null) // Lazy initialization. { if (_encapsStack.encoding_1_0) diff --git a/csharp/src/Ice/Proxy.cs b/csharp/src/Ice/Proxy.cs index cc544ca27dc..ddea8c04f99 100644 --- a/csharp/src/Ice/Proxy.cs +++ b/csharp/src/Ice/Proxy.cs @@ -594,7 +594,7 @@ private void iceI_ice_isA(string id, iceCheckAsyncTwowayOnly(_ice_isA_name); getOutgoingAsync(completed).invoke(_ice_isA_name, OperationMode.Idempotent, - FormatType.DefaultFormat, + FormatType.CompactFormat, context, synchronous, (OutputStream os) => { os.writeString(id); }, @@ -647,7 +647,7 @@ private void iceI_ice_ping(Dictionary? context, OutgoingAsyncCom { getOutgoingAsync(completed).invoke(_ice_ping_name, OperationMode.Idempotent, - FormatType.DefaultFormat, + FormatType.CompactFormat, context, synchronous); } @@ -702,7 +702,7 @@ private void iceI_ice_ids(Dictionary? context, OutgoingAsyncComp iceCheckAsyncTwowayOnly(_ice_ids_name); getOutgoingAsync(completed).invoke(_ice_ids_name, OperationMode.Idempotent, - FormatType.DefaultFormat, + FormatType.CompactFormat, context, synchronous, read: (InputStream iss) => { return iss.readStringSeq(); }); @@ -755,7 +755,7 @@ private void iceI_ice_id(Dictionary? context, { getOutgoingAsync(completed).invoke(_ice_id_name, OperationMode.Idempotent, - FormatType.DefaultFormat, + FormatType.CompactFormat, context, synchronous, read: (InputStream iss) => { return iss.readString(); }); diff --git a/csharp/test/Ice/objects/UnexpectedObjectExceptionTestI.cs b/csharp/test/Ice/objects/UnexpectedObjectExceptionTestI.cs index 8ec1eab2157..9875c6a4c4c 100644 --- a/csharp/test/Ice/objects/UnexpectedObjectExceptionTestI.cs +++ b/csharp/test/Ice/objects/UnexpectedObjectExceptionTestI.cs @@ -10,7 +10,7 @@ public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Curre { var communicator = current.adapter.getCommunicator(); var @out = new Ice.OutputStream(communicator); - @out.startEncapsulation(current.encoding, Ice.FormatType.DefaultFormat); + @out.startEncapsulation(current.encoding, FormatType.SlicedFormat); var ae = new Test.AlsoEmpty(); @out.writeValue(ae); @out.writePendingValues();