Exemplo n.º 1
0
 static object DecodeMessage(CodedInputStream stream, Type type)
 {
     if (type == typeof(ProcedureCall))
     {
         var message = new Schema.KRPC.ProcedureCall();
         message.MergeFrom(stream);
         return(message.ToMessage());
     }
     throw new ArgumentException("Cannot decode protocol buffer messages of type " + type);
 }
Exemplo n.º 2
0
        public void EncodeMessage()
        {
            var call = new Schema.KRPC.ProcedureCall();

            call.Service   = "ServiceName";
            call.Procedure = "ProcedureName";
            var          data     = Encoder.Encode(call, typeof(Schema.KRPC.ProcedureCall));
            const string expected = "0a0b536572766963654e616d65120d50726f6365647572654e616d65";

            Assert.AreEqual(expected, data.ToHexString());
        }
Exemplo n.º 3
0
 public static ProcedureCall ToMessage(this Schema.KRPC.ProcedureCall call)
 {
     // Note: this method must not throw an exception, if the call is to an invalid
     // procedure. If the ProcedureSignature cannot be obtained, returns a
     // ProcedureCall with no decoded arguments
     try {
         var procedureSignature = Service.Services.Instance.GetProcedureSignature(call.Service, call.Procedure);
         var result             = new ProcedureCall(call.Service, call.Procedure);
         foreach (var argument in call.Arguments)
         {
             var position = (int)argument.Position;
             // Ignore the argument if its position is not valid
             if (position >= procedureSignature.Parameters.Count)
             {
                 continue;
             }
             var type = procedureSignature.Parameters [position].Type;
             result.Arguments.Add(argument.ToMessage(type));
         }
         return(result);
     } catch (RPCException) {
         return(new ProcedureCall(call.Service, call.Procedure));
     }
 }