Beispiel #1
0
        /// <summary>
        /// 根据tag获取tlv的值
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public static TLVEntity GetValueByTag(List <TLVEntity> entities, string tag)
        {
            TLVEntity resultEntity = null;
            var       query        = entities.SingleOrDefault(e => CodeConvert.ToHexString(e.Tag).ToUpper() == tag);

            if (query == null)
            {
                foreach (var tlv in entities)
                {
                    if (tlv.SubTLVEntity != null)
                    {
                        TLVEntity result = GetValueByTag(tlv.SubTLVEntity, tag);

                        if (result != null && result.Length.Length > 0)
                        {
                            return(result);
                        }
                    }
                }
            }
            else
            {
                resultEntity = query;
            }
            return(resultEntity);
        }
Beispiel #2
0
        /// <summary>
        /// 16进制数据转化为TVL实体
        /// </summary>
        /// <param name="resultData"></param>
        /// <returns></returns>
        public static List <TLVEntity> ToTLVEntityList(string data)
        {
            byte[] dataBytes = CodeConvert.HexStringToByteArray(data);
            var    tlvList   = TLVPackage.Construct(dataBytes);

            return(tlvList);
        }
Beispiel #3
0
        /// <summary>
        /// 转化成TL格式的字符串
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static List <string> ToTLStringList(byte[] bytes)
        {
            List <string> list = new List <string>();

            for (int i = 0; i < bytes.Length; i++)
            {
                List <byte> pdo = new List <byte>();
                if ((bytes[i] & 0xF) == 0xF)//判断tag是否占两位
                {
                    pdo.AddRange(new byte[] { bytes[i++], bytes[i++] });
                }
                else
                {
                    pdo.Add(bytes[i++]);
                }
                if ((bytes[i] & 0x80) == 0x80)//判读length是否占两位
                {
                    pdo.AddRange(new byte[] { bytes[i++], bytes[i++] });
                }
                else
                {
                    pdo.Add(bytes[i]);
                }
                list.Add(CodeConvert.ToHexString(pdo.ToArray()));
            }
            return(list);
        }