Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public JT808_0x8103 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x8103 value = new JT808_0x8103
            {
                ParamList       = new List <JT808_0x8103_BodyBase>(),
                CustomParamList = new List <JT808_0x8103_CustomBodyBase>()
            };
            var paramCount = reader.ReadByte();//参数总数

            try
            {
                for (int i = 0; i < paramCount; i++)
                {
                    var paramId = reader.ReadVirtualUInt32();//参数ID
                    if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance))
                    {
                        dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config);
                        value.ParamList.Add(attachImpl);
                    }
                    else if (config.JT808_0X8103_Custom_Factory.Map.TryGetValue(paramId, out object customInstance))
                    {
                        dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(customInstance, ref reader, config);
                        value.CustomParamList.Add(attachImpl);
                    }
                }
            }
            catch
            {
            }
            return(value);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="writer"></param>
        /// <param name="config"></param>
        public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
        {
            var paramCount = reader.ReadByte();//参数总数

            writer.WriteNumber($"[{paramCount.ReadNumber()}]参数总数", paramCount);
            try
            {
                writer.WriteStartArray("参数项");
                for (int i = 0; i < paramCount; i++)
                {
                    var paramId = reader.ReadVirtualUInt32();//参数ID
                    if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance))
                    {
                        writer.WriteStartObject();
                        instance.Analyze(ref reader, writer, config);
                        writer.WriteEndObject();
                    }
                    else if (config.JT808_0X8103_Custom_Factory.Map.TryGetValue(paramId, out object customInstance))
                    {
                        writer.WriteStartObject();
                        customInstance.Analyze(ref reader, writer, config);
                        writer.WriteEndObject();
                    }
                }
                writer.WriteEndArray();
            }
            catch (Exception ex)
            {
                writer.WriteString($"异常信息", ex.StackTrace);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public JT808_0x0104 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x0104 jT808_0x0104 = new JT808_0x0104();

            jT808_0x0104.MsgNum            = reader.ReadUInt16();
            jT808_0x0104.AnswerParamsCount = reader.ReadByte();
            for (int i = 0; i < jT808_0x0104.AnswerParamsCount; i++)
            {
                var paramId = reader.ReadVirtualUInt32();//参数ID
                if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance))
                {
                    if (jT808_0x0104.ParamList != null)
                    {
                        jT808_0x0104.ParamList.Add(JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config));
                    }
                    else
                    {
                        jT808_0x0104.ParamList = new List <JT808_0x8103_BodyBase> {
                            JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config)
                        };
                    }
                }
                else
                {
                    //对于未能解析的自定义项,过滤其长度,以保证后续解析正常
                    reader.Skip(4);              //跳过参数id长度
                    var len = reader.ReadByte(); //获取协议长度
                    reader.Skip(len);            //跳过协议内容
                }
            }
            return(jT808_0x0104);
        }
Esempio n. 4
0
        public JT808_0x8103 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x8103 jT808_0x8103 = new JT808_0x8103
            {
                ParamList       = new List <JT808_0x8103_BodyBase>(),
                CustomParamList = new List <JT808_0x8103_CustomBodyBase>()
            };
            var paramCount = reader.ReadByte();//参数总数

            try
            {
                for (int i = 0; i < paramCount; i++)
                {
                    var paramId = reader.ReadVirtualUInt32();//参数ID
                    if (config.JT808_0X8103_Factory.ParamMethods.TryGetValue(paramId, out Type type))
                    {
                        object  attachImplObj = config.GetMessagePackFormatterByType(type);
                        dynamic attachImpl    = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(attachImplObj, ref reader, config);
                        jT808_0x8103.ParamList.Add(attachImpl);
                    }
                    else if (config.JT808_0X8103_Custom_Factory.ParamMethods.TryGetValue(paramId, out Type customType))
                    {
                        object  attachImplObj = config.GetMessagePackFormatterByType(customType);
                        dynamic attachImpl    = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(attachImplObj, ref reader, config);
                        jT808_0x8103.CustomParamList.Add(attachImpl);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(jT808_0x8103);
        }
Esempio n. 5
0
        public JT808_0x0104 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
        {
            JT808_0x0104 jT808_0x0104 = new JT808_0x0104();

            jT808_0x0104.MsgNum            = reader.ReadUInt16();
            jT808_0x0104.AnswerParamsCount = reader.ReadByte();
            for (int i = 0; i < jT808_0x0104.AnswerParamsCount; i++)
            {
                var paramId = reader.ReadVirtualUInt32();//参数ID
                if (config.JT808_0X8103_Factory.ParamMethods.TryGetValue(paramId, out Type type))
                {
                    if (jT808_0x0104.ParamList != null)
                    {
                        jT808_0x0104.ParamList.Add(JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(
                                                       config.GetMessagePackFormatterByType(type), ref reader, config));
                    }
                    else
                    {
                        jT808_0x0104.ParamList = new List <JT808_0x8103_BodyBase> {
                            JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(
                                config.GetMessagePackFormatterByType(type), ref reader, config)
                        };
                    }
                }
            }
            return(jT808_0x0104);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="writer"></param>
        /// <param name="config"></param>
        public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
        {
            JT808_0x0104 jT808_0x0104 = new JT808_0x0104();

            jT808_0x0104.MsgNum            = reader.ReadUInt16();
            jT808_0x0104.AnswerParamsCount = reader.ReadByte();
            writer.WriteNumber($"[{jT808_0x0104.MsgNum.ReadNumber()}]应答流水号", jT808_0x0104.MsgNum);
            writer.WriteNumber($"[{ jT808_0x0104.AnswerParamsCount.ReadNumber()}]应答参数个数", jT808_0x0104.AnswerParamsCount);
            writer.WriteStartArray($"参数列表");
            for (int i = 0; i < jT808_0x0104.AnswerParamsCount; i++)
            {
                writer.WriteStartObject();
                var paramId = reader.ReadVirtualUInt32();//参数ID
                if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance))
                {
                    if (instance is IJT808Analyze analyze)
                    {
                        analyze.Analyze(ref reader, writer, config);
                    }
                }
                writer.WriteEndObject();
            }
            writer.WriteEndArray();
        }