예제 #1
0
        /// <summary>
        /// Unpack a list of values
        /// </summary>
        /// <param name="packed">The packed data</param>
        /// <param name="types">The types the packed data should be</param>
        /// <returns>A list of the unpacked values</returns>
        public static List <Value> UnpackRpcValues(IList <byte> packed, IList <NtType> types)
        {
            ListStream   iStream = new ListStream(packed);
            WireDecoder  dec     = new WireDecoder(iStream, 0x0300);
            List <Value> vec     = new List <Value>();

            foreach (var ntType in types)
            {
                var item = dec.ReadValue(ntType);
                if (item == null)
                {
                    return(new List <Value>());
                }
                vec.Add(item);
            }
            return(vec);
        }
예제 #2
0
        /// <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);
        }