public void EncodeMessage () { var request = new Request ("TestService", "ProcedureNoArgsNoReturn"); var data = Encoder.Encode (request); const string expected = "0a0b5465737453657276696365121750726f6365647572654e6f417267734e6f52657475726e"; Assert.AreEqual (expected, data.ToHexString ()); }
static Request Req (string service, string procedure, params Argument[] args) { var request = new Request (service, procedure); foreach (var arg in args) request.Arguments.Add (arg); return request; }
public StreamRequest (Request request) { Identifier = NextIdentifier; var services = Services.Instance; Procedure = services.GetProcedureSignature (request.Service, request.Procedure); Arguments = services.GetArguments (Procedure, request.Arguments); Response = new StreamResponse (Identifier); }
protected override int Read (ref Request request, byte[] data, int offset, int length) { try { var codedStream = new CodedInputStream (data, offset, length); // Get the protobuf message size int size = (int)codedStream.ReadUInt32 (); int totalSize = (int)codedStream.Position + size; // Check if enough data is available, if not then delay the decoding if (length < totalSize) return 0; // Decode the request request = Schema.KRPC.Request.Parser.ParseFrom (codedStream).ToMessage (); return totalSize; } catch (InvalidProtocolBufferException e) { throw new MalformedRequestException (e.Message); } }
public void SetUp () { // Create a request object and get the binary representation of it expectedRequest = new Request ("TestService", "ProcedureNoArgsNoReturn"); using (var stream = new MemoryStream ()) { var codedStream = new CodedOutputStream (stream, true); codedStream.WriteInt32 (expectedRequest.ToProtobufMessage ().CalculateSize ()); expectedRequest.ToProtobufMessage ().WriteTo (codedStream); codedStream.Flush (); requestBytes = stream.ToArray (); } // Create a response object and get the binary representation of it expectedResponse = new Response (); expectedResponse.Error = "SomeErrorMessage"; expectedResponse.Time = 42; using (var stream = new MemoryStream ()) { var codedStream = new CodedOutputStream (stream, true); codedStream.WriteInt32 (expectedResponse.ToProtobufMessage ().CalculateSize ()); expectedResponse.ToProtobufMessage ().WriteTo (codedStream); codedStream.Flush (); responseBytes = stream.ToArray (); } }
public static void ProcedureThreeArgsNoReturn (Response x, Request y, Response z) { Service.ProcedureThreeArgsNoReturn (x, y, z); }
/// <summary> /// Add a stream to the server /// </summary> internal uint AddStream (IClient rpcClient, Request request) { var id = rpcClient.Guid; if (!streamClients.ContainsKey (id)) throw new InvalidOperationException ("No stream client is connected for this RPC client"); var streamClient = streamClients [id]; // Check for an existing stream for the request var services = Service.Services.Instance; var procedure = services.GetProcedureSignature (request.Service, request.Procedure); var arguments = services.GetArguments (procedure, request.Arguments); foreach (var streamRequest in streamRequests[streamClient]) { if (streamRequest.Procedure == procedure && streamRequest.Arguments.SequenceEqual (arguments)) return streamRequest.Identifier; } // Create a new stream { var streamRequest = new StreamRequest (request); streamRequests [streamClient].Add (streamRequest); streamResultCache [streamRequest.Identifier] = null; return streamRequest.Identifier; } }
static Response Run (Request request) { var procedure = KRPC.Service.Services.Instance.GetProcedureSignature (request.Service, request.Procedure); return KRPC.Service.Services.Instance.HandleRequest (procedure, request); }
public static uint AddStream (Request request) { return Core.Instance.AddStream (CallContext.Client, request); }
/// <summary> /// Executes the given request and returns a response builder with the relevant /// fields populated. Throws YieldException, containing a continuation, if the request yields. /// Throws RPCException if processing the request fails. /// </summary> public Response HandleRequest (ProcedureSignature procedure, Request request) { return HandleRequest (procedure, GetArguments (procedure, request.Arguments)); }
public static Request ToMessage (this Schema.KRPC.Request request) { var procedureSignature = KRPC.Service.Services.Instance.GetProcedureSignature (request.Service, request.Procedure); var result = new Request (request.Service, request.Procedure); foreach (var argument in request.Arguments) { var type = procedureSignature.Parameters [(int)argument.Position].Type; result.Arguments.Add (argument.ToMessage (type)); } return result; }