示例#1
0
        /// <summary>
        /// Serialize item to byte list.
        /// </summary>
        /// <returns>The byte list.</returns>
        public List <byte> SerializeToByteList()
        {
            List <byte> byteList = new List <byte>();

            int lengthOfItems = this.SerializeItemsToByteList(byteList);

            StreamObjectHeaderStart header;

            if ((int)this.StreamObjectType <= 0x3F && lengthOfItems <= 127)
            {
                header = new StreamObjectHeaderStart16bit(this.StreamObjectType, lengthOfItems);
            }
            else
            {
                header = new StreamObjectHeaderStart32bit(this.StreamObjectType, lengthOfItems);
            }

            byteList.InsertRange(0, header.SerializeToByteList());

            if (CompoundTypes.Contains(this.StreamObjectType))
            {
                if ((int)this.StreamObjectType <= 0x3F)
                {
                    byteList.AddRange(new StreamObjectHeaderEnd8bit((int)this.StreamObjectType).SerializeToByteList());
                }
                else
                {
                    byteList.AddRange(new StreamObjectHeaderEnd16bit((int)this.StreamObjectType).SerializeToByteList());
                }
            }

            return(byteList);
        }
示例#2
0
        /// <summary>
        /// Used to return the length of this element.
        /// </summary>
        /// <param name="header">Then instance of StreamObjectHeaderStart.</param>
        /// <param name="byteArray">The byte list</param>
        /// <param name="startIndex">The position where to start.</param>
        /// <returns>The element length</returns>
        public int DeserializeFromByteArray(StreamObjectHeaderStart header, byte[] byteArray, int startIndex)
        {
            this.StreamObjectType = header.Type;
            this.LengthOfItems    = header.Length;

            if (header is StreamObjectHeaderStart32bit)
            {
                if (header.Length == 32767)
                {
                    this.LengthOfItems = (int)(header as StreamObjectHeaderStart32bit).LargeLength.DecodedValue;
                }
            }

            int index = startIndex;

            this.StreamObjectHeaderStart = header;
            this.DeserializeItemsFromByteArray(byteArray, ref index, this.LengthOfItems);

            if (CompoundTypes.Contains(this.StreamObjectType))
            {
                StreamObjectHeaderEnd end       = null;
                BitReader             bitReader = new BitReader(byteArray, index);
                int aField = bitReader.ReadInt32(2);
                if (aField == 0x1)
                {
                    end = BasicObject.Parse <StreamObjectHeaderEnd8bit>(byteArray, ref index);
                }
                if (aField == 0x3)
                {
                    end = BasicObject.Parse <StreamObjectHeaderEnd16bit>(byteArray, ref index);
                }

                if ((int)end.Type != (int)this.StreamObjectType)
                {
                    throw new StreamObjectParseErrorException(index, null, "Unexpected the stream header end value " + (int)this.StreamObjectType, null);
                }

                this.StreamObjectHeaderEnd = end;
            }

            // Capture all the type related requirements
            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                new MsfsshttpbAdapterCapture().InvokeCaptureMethod(this.GetType(), this, SharedContext.Current.Site);
            }

            return(index - startIndex);
        }