/// <summary> /// Pack an Rpc defintion in to a byte array /// </summary> /// <param name="def">The definition to pack</param> /// <returns>The packed data</returns> public static byte[] PackRpcDefinition(RpcDefinition def) { WireEncoder enc = new WireEncoder(0x0300); enc.Write8((byte)def.Version); enc.WriteString(def.Name); int paramsSize = def.Params.Count; if (paramsSize > 0xff) { paramsSize = 0xff; } enc.Write8((byte)paramsSize); for (int i = 0; i < paramsSize; i++) { enc.WriteType(def.Params[i].DefValue.Type); enc.WriteString(def.Params[i].Name); enc.WriteValue(def.Params[i].DefValue); } int resultsSize = def.Results.Count; if (resultsSize > 0xff) { resultsSize = 0xff; } enc.Write8((byte)resultsSize); for (int i = 0; i < resultsSize; i++) { enc.WriteType(def.Results[i].Type); enc.WriteString(def.Results[i].Name); } return(enc.Buffer); }
/// <summary> /// Creates an procedure called by a remote client that can be polled by the server /// </summary> /// <remarks> /// Note that this can only be called by a server. /// </remarks> /// <param name="name">The name for this Rpc</param> /// <param name="def">The definition for this Rpc</param> public static void CreatePolledRpc(string name, RpcDefinition def) { #if CORE CreatePolledRpc(name, PackRpcDefinition(def)); #else Storage.Instance.CreatePolledRpc(name, PackRpcDefinition(def)); #endif }
/// <summary> /// Creates an procedure that can be called by a remote client /// </summary> /// <remarks> /// Note that this can only be called by a server. /// </remarks> /// <param name="name">The name for this Rpc</param> /// <param name="def">The definition for this Rpc</param> /// <param name="callback">The callback to use the the procedure is called from a remote</param> public static void CreateRpc(string name, RpcDefinition def, RpcCallback callback) { #if CORE CreateRpc(name, PackRpcDefinition(def), callback); #else Storage.Instance.CreateRpc(name, PackRpcDefinition(def), callback); #endif }
/// <summary> /// Unpack an Rpc definition from a byte array /// </summary> /// <param name="packed">The data array</param> /// <param name="def">The definition to unpack to</param> /// <returns>True if the data was unpacked successfully</returns> public static bool UnpackRpcDefinition(IList <byte> packed, ref RpcDefinition def) { ListStream iStream = new ListStream(packed); WireDecoder dec = new WireDecoder(iStream, 0x0300); byte ref8 = 0; string str = ""; if (!dec.Read8(ref ref8)) { return(false); } def.SetVersion(ref8); if (!dec.ReadString(ref str)) { return(false); } def.SetName(str); if (!dec.Read8(ref ref8)) { return(false); } int paramsSize = ref8; def.Params.Clear(); NtType type = 0; for (int i = 0; i < paramsSize; i++) { if (!dec.ReadType(ref type)) { return(false); } if (!dec.ReadString(ref str)) { return(false); } var val = dec.ReadValue(type); if (val == null) { return(false); } def.Params.Add(new RpcParamDef(str, val)); } if (!dec.Read8(ref ref8)) { return(false); } int resultsSize = ref8; def.Results.Clear(); for (int i = 0; i < resultsSize; i++) { type = 0; if (!dec.ReadType(ref type)) { return(false); } if (!dec.ReadString(ref str)) { return(false); } def.Results.Add(new RpcResultsDef(str, type)); } return(true); }