예제 #1
0
        private static void PrimitiveDecoding(BinaryReader br, long endPosition, ref object obj, List <TTLVStructNode> childs)
        {
            var nodeInfo = new TTLVNodeInfo();

            while (br.BaseStream.Position < endPosition)
            {
                //int tag = br.ReadInt32();
                //TypeCode valueBufferTypeCode = (TypeCode)br.ReadByte();
                //int length = br.ReadInt32();
                _codec.ReadNodeInfo(br, nodeInfo);
                int      length = nodeInfo.Length;
                TypeCode valueBufferTypeCode = nodeInfo.Type;

                TTLVStructNode node = childs.Find(t => { return(t.Tag == nodeInfo.Tag); });
                if (node == null || !node.CheckCompatible(valueBufferTypeCode))
                {
                    br.BaseStream.Position += length;
                    continue;
                }

                switch (node.TTLVType)
                {
                case TTLVType.BasicType:
                    DecodingBasicType(br, ref obj, node, length, valueBufferTypeCode);
                    break;

                case TTLVType.Convert:
                    DecodingConvert(br, ref obj, node, length);
                    break;

                case TTLVType.Object:
                    DecodingObject(br, ref obj, node, length);
                    break;

                case TTLVType.Array:
                    DecodingArray(br, ref obj, node, length);
                    break;

                case TTLVType.IList:
                    DecodingIList(br, ref obj, node, length);
                    break;

                default:
                    throw new NotImplementedException(string.Format("未知类型", node.TTLVType.ToString()));
                }
            }
        }
예제 #2
0
        private static void DecodingCollection(IList list, BinaryReader br, TTLVStructNode node, int valueLength)
        {
            TTLVCommon.CheckHasNoParaConstructor(node.ElementType);
            var endPosition = br.BaseStream.Position + valueLength;
            var nodeInfo    = new TTLVNodeInfo();

            while (br.BaseStream.Position < endPosition)
            {
                //int tag = br.ReadInt32();
                //TypeCode valueBufferTypeCode = (TypeCode)br.ReadByte();
                //int length = br.ReadInt32();
                _codec.ReadNodeInfo(br, nodeInfo);

                object instance = Activator.CreateInstance(node.ElementType);
                PrimitiveDecoding(br, br.BaseStream.Position + nodeInfo.Length, ref instance, node.Childs);
                list.Add(instance);
            }

            br.BaseStream.Position = endPosition;
        }
예제 #3
0
 /// <summary>
 /// 读取节点信息
 /// </summary>
 /// <param name="br">BinaryReader</param>
 /// <param name="nodeInfo">存储节点信息对象</param>
 public void ReadNodeInfo(BinaryReader br, TTLVNodeInfo nodeInfo)
 {
     nodeInfo.Tag    = br.ReadInt32();
     nodeInfo.Type   = (TypeCode)br.ReadByte();
     nodeInfo.Length = br.ReadInt32();
 }