示例#1
0
文件: Util.cs 项目: mksmbrtsh/llrp
        public static object ParseArrayTypeFromString(string rawval, string type, string format)
        {
            string str = rawval.Trim();

            try
            {
                switch (type)
                {
                case "u1v":
                case "u96":
                    switch (format)
                    {
                    case "Hex":
                        return((object)LLRPBitArray.FromHexString(str));

                    default:
                        return((object)LLRPBitArray.FromString(str));
                    }

                case "bytesToEnd":
                case "u8v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)ByteArray.FromHexString(str));

                    default:
                        return((object)ByteArray.FromString(str));
                    }

                case "s8v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)SignedByteArray.FromHexString(str));

                    default:
                        return((object)SignedByteArray.FromString(str));
                    }

                case "u16v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)UInt16Array.FromHexString(str));

                    default:
                        return((object)UInt16Array.FromString(str));
                    }

                case "s16v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)Int16Array.FromHexString(str));

                    default:
                        return((object)Int16Array.FromString(str));
                    }

                case "u32v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)UInt32Array.FromHexString(str));

                    default:
                        return((object)UInt32Array.FromString(str));
                    }

                case "s32v":
                    switch (format)
                    {
                    case "Hex":
                        return((object)Int32Array.FromHexString(str));

                    default:
                        return((object)Int32Array.FromString(str));
                    }

                case "utf8v":
                    return((object)str);

                default:
                    throw new Exception(string.Format("{0} is unsupported type.", (object)type));
                }
            }
            catch
            {
                throw new Exception(string.Format("Can't parse {0} to {1} as format {2}", (object)str, (object)type, (object)format));
            }
        }
示例#2
0
文件: LLRPUtil.cs 项目: DenvyShi/LLRP
        /// <summary>
        /// Parse array type supported by LLRP protocol
        /// </summary>
        /// <param name="val">input string value</param>
        /// <param name="type">array type (string), defined in LLRP protocol</param>
        /// <param name="format">format (string), defined in LLRP protocol</param>
        /// <returns></returns>
        public static object ParseArrayTypeFromString(string val, string type, string format)
        {
            try
            {
                switch (type)
                {
                case "u1v":
                case "u96":
                    switch (format)
                    {
                    case "Hex":
                        return(LLRPBitArray.FromHexString(val));

                    case "Dec":
                    default:
                        return(LLRPBitArray.FromString(val));
                    }
                    break;

                case "bytesToEnd":
                case "u8v":
                    switch (format)
                    {
                    case "Hex":
                        return(ByteArray.FromHexString(val));

                    case "Dec":
                    default:
                        return(ByteArray.FromString(val));
                    }
                    break;

                case "u16v":
                    switch (format)
                    {
                    case "Hex":
                        return(UInt16Array.FromHexString(val));

                    case "Dec":
                    default:
                        return(UInt16Array.FromString(val));
                    }
                    break;

                case "u32v":
                    switch (format)
                    {
                    case "Hex":
                        return(UInt32Array.FromHexString(val));

                    case "Dec":
                    default:
                        return(UInt32Array.FromString(val));
                    }
                    break;

                case "utf8v":
                    return(val);

                    break;

                default:
                    throw new Exception(string.Format("{0} is unsupported type.", type));
                }
            }
            catch
            {
                throw new Exception(string.Format("Can't parse {0} to {1} as format {2}", val, type, format));
            }
        }