コード例 #1
0
ファイル: Services.cs プロジェクト: pipi1226/krpc
 /// <summary>
 /// Decode a serialized value
 /// </summary>
 object Decode(ProcedureSignature procedure, int i, Type type, ByteString value)
 {
     if (TypeUtils.IsAClassType(type))
     {
         return(ObjectStore.Instance.GetInstance((ulong)ProtocolBuffers.ReadValue(value, typeof(ulong))));
     }
     else if (TypeUtils.IsACollectionType(type))
     {
         return(DecodeCollection(procedure, i, type, value));
     }
     else if (ProtocolBuffers.IsAMessageType(type))
     {
         return(ProtocolBuffers.ParseFrom(type, value));
     }
     else if (TypeUtils.IsAnEnumType(type))
     {
         // TODO: Assumes it's underlying type is int
         var enumValue = ProtocolBuffers.ReadValue(value, typeof(int));
         if (!Enum.IsDefined(type, enumValue))
         {
             throw new RPCException(procedure, "Failed to convert value " + enumValue + " to enumeration type " + type);
         }
         return(Enum.ToObject(type, enumValue));
     }
     else
     {
         return(ProtocolBuffers.ReadValue(value, type));
     }
 }