public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { if (current.Operation.Equals("opOneway")) { if (!current.IsOneway) { // If called two-way, return exception to caller. throw new MyException(); } return(new ValueTask <OutgoingResponseFrame>(OutgoingResponseFrame.WithVoidReturnValue(current))); } else if (current.Operation.Equals("opString")) { string s = request.ReadArgs(current.Communicator, InputStream.IceReaderIntoString); var responseFrame = OutgoingResponseFrame.WithReturnValue(current, compress: false, format: default,
/// <summary>The <see cref="RequestReader{T}"/> for the parameter of operation ice_isA.</summary> /// <summary>Decodes the ice_id operation parameters from an <see cref="IncomingRequestFrame"/>.</summary> /// <param name="connection">The used to receive the frame.</param> /// <param name="request">The request frame.</param> /// <returns>The return value decoded from the frame.</returns> public static string IceIsA(Connection connection, IncomingRequestFrame request) => request.ReadArgs(connection, InputStream.IceReaderIntoString);
public ValueTask <OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) { OutgoingResponseFrame?response = null; if (current.Operation == "printString") { string message = request.ReadArgs(current.Connection, istr => istr.ReadString()); Console.WriteLine($"Printing string `{message}'"); } else if (current.Operation == "printStringSequence") { string[] messages = request.ReadArgs(current.Connection, istr => istr.ReadArray(1, istr => istr.ReadString())); Console.Write("Printing string sequence {"); Console.Write(string.Join(", ", messages)); Console.WriteLine("}"); } else if (current.Operation == "printDictionary") { Dictionary <string, string> dict = request.ReadArgs(current.Connection, istr => istr.ReadDictionary(1, 1, istr => istr.ReadString(), istr => istr.ReadString())); Console.Write("Printing dictionary {"); bool first = true; foreach ((string key, string value) in dict) { if (!first) { Console.Write(", "); } first = false; Console.Write($"{key} = {value}"); } Console.WriteLine("}"); } else if (current.Operation == "printEnum") { Color color = request.ReadArgs(current.Connection, ColorHelper.IceReader); Console.WriteLine($"Printing enum {color}"); } else if (current.Operation == "printStruct") { Structure s = request.ReadArgs(current.Connection, Structure.IceReader); Console.WriteLine($"Printing struct: name={s.Name}, value={s.Value}"); } else if (current.Operation == "printStructSequence") { Structure[] seq = request.ReadArgs( current.Connection, istr => istr.ReadArray(minElementSize: 2, Structure.IceReader)); Console.Write("Printing struct sequence: {"); bool first = true; foreach (Structure s in seq) { if (!first) { Console.Write(", "); } first = false; Console.Write($"{s.Name} = {s.Value}"); } Console.WriteLine("}"); } else if (current.Operation == "printClass") { C c = request.ReadArgs(current.Connection, istr => istr.ReadClass <C>(C.IceTypeId)); Console.WriteLine($"Printing class: s.name={c.S.Name}, s.value={c.S.Value}"); } else if (current.Operation == "getValues") { var c = new C(new Structure("green", Color.green)); response = OutgoingResponseFrame.WithReturnValue <(string, C)>( current, false, FormatType.Compact, ("hello", c), (OutputStream ostr, (string s, C c)value) => { ostr.WriteString(value.s); ostr.WriteClass(value.c, C.IceTypeId); });