/// <summary>
        /// This method is used to convert the element of StreamObjectHeaderStart16bit basic object into a byte List.
        /// </summary>
        /// <returns>Return the byte list which store the byte information of StreamObjectHeaderStart16bit.</returns>
        public override List <byte> SerializeToByteList()
        {
            BitWriter bitField = new BitWriter(2);

            bitField.AppendInit32(this.HeaderType, 2);
            bitField.AppendInit32(this.Compound, 1);
            bitField.AppendUInit32(Convert.ToUInt32(this.Type), 6);
            bitField.AppendInit32(this.Length, 7);
            return(new List <byte>(bitField.Bytes));
        }
        /// <summary>
        /// This method is used to convert the element of StreamObjectHeaderEnd16bit basic object into a byte List.
        /// </summary>
        /// <returns>Return the byte list which store the byte information of StreamObjectHeaderEnd16bit.</returns>
        public override List <byte> SerializeToByteList()
        {
            BitWriter bitFieldWriter = new BitWriter(2);

            bitFieldWriter.AppendInit32(0x3, 2);
            bitFieldWriter.AppendUInit32(Convert.ToUInt32(this.Type), 14);
            return(new List <byte>(bitFieldWriter.Bytes));
        }
        /// <summary>
        /// This method is used to convert the element of StreamObjectHeaderStart32bit basic object into a byte List.
        /// </summary>
        /// <returns>Return the byte list which store the byte information of StreamObjectHeaderStart32bit.</returns>
        public override List <byte> SerializeToByteList()
        {
            BitWriter bitFieldWriter = new BitWriter(4);

            bitFieldWriter.AppendInit32(this.HeaderType, 2);
            bitFieldWriter.AppendInit32(this.Compound, 1);
            bitFieldWriter.AppendUInit32(Convert.ToUInt32(this.Type), 14);
            bitFieldWriter.AppendInit32(this.Length, 15);

            List <byte> listByte = new List <byte>(bitFieldWriter.Bytes);

            if (this.LargeLength != null)
            {
                listByte.AddRange(this.LargeLength.SerializeToByteList().ToArray());
            }

            return(listByte);
        }
Пример #4
0
        /// <summary>
        /// This method is used to convert the element into a byte List
        /// </summary>
        /// <returns>Return the Byte List</returns>
        public override List <byte> SerializeToByteList()
        {
            List <byte> byteList = new List <byte>();

            byteList.AddRange(base.SerializeToByteList());
            byteList.AddRange(this.AllocateExtendedGuidRangeRequest.SerializeToByteList());
            byteList.AddRange(this.RequestIDCount.SerializeToByteList());
            BitWriter bitWriter = new BitWriter(1);

            bitWriter.AppendInit32(this.Reserved, 8);
            List <byte> reservedBytes = new List <byte>(bitWriter.Bytes);

            byteList.AddRange(reservedBytes);
            byteList.AddRange(this.ToBytesEnd());

            return(byteList);
        }
        /// <summary>
        /// This method is used to analyze the zip file header.
        /// </summary>
        /// <param name="content">Specify the zip content.</param>
        /// <param name="index">Specify the start position.</param>
        /// <param name="dataFileSignature">Specify the output value for the data file signature.</param>
        /// <returns>Return the data file content.</returns>
        private byte[] AnalyzeFileHeader(byte[] content, int index, out byte[] dataFileSignature)
        {
            int crc32             = BitConverter.ToInt32(content, index + 14);
            int compressedSize    = BitConverter.ToInt32(content, index + 18);
            int uncompressedSize  = BitConverter.ToInt32(content, index + 22);
            int fileNameLength    = BitConverter.ToInt16(content, index + 26);
            int extraFileldLength = BitConverter.ToInt16(content, index + 28);
            int headerLength      = 30 + fileNameLength + extraFileldLength;

            BitWriter writer = new BitWriter(20);

            writer.AppendInit32(crc32, 32);
            writer.AppendUInt64((ulong)compressedSize, 64);
            writer.AppendUInt64((ulong)uncompressedSize, 64);
            dataFileSignature = writer.Bytes;

            return(AdapterHelper.GetBytes(content, index, headerLength));
        }
        /// <summary>
        /// This method is used to convert the element into a byte List
        /// </summary>
        /// <returns>Return the Byte List</returns>
        public List <byte> SerializeToByteList()
        {
            this.RequestStart     = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.Request, 0);
            this.UserAgentStart   = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.UserAgent, 0);
            this.UserAgentGUID    = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.UserAgentGUID, 16);
            this.UserAgentVersion = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.UserAgentversion, 4);
            this.UserAgentEnd     = new StreamObjectHeaderEnd16bit((int)StreamObjectTypeHeaderEnd.UserAgent);
            this.CellRequestEnd   = new StreamObjectHeaderEnd16bit((int)StreamObjectTypeHeaderEnd.Request);

            List <byte> byteList = new List <byte>();

            // Protocol Version
            byteList.AddRange(LittleEndianBitConverter.GetBytes(this.ProtocolVersion));

            // Minimum Version
            byteList.AddRange(LittleEndianBitConverter.GetBytes(this.MinimumVersion));

            // Signature
            byteList.AddRange(LittleEndianBitConverter.GetBytes(this.Signature));

            // Request Start
            byteList.AddRange(this.RequestStart.SerializeToByteList());

            // User Agent Start
            byteList.AddRange(this.UserAgentStart.SerializeToByteList());

            // User Agent GUID
            byteList.AddRange(this.UserAgentGUID.SerializeToByteList());

            // GUID
            byteList.AddRange(this.GUID.ToByteArray());

            // User Agent Version
            byteList.AddRange(this.UserAgentVersion.SerializeToByteList());

            // Version
            byteList.AddRange(LittleEndianBitConverter.GetBytes(this.Version));

            // User Agent End
            byteList.AddRange(this.UserAgentEnd.SerializeToByteList());

            if (this.IsRequestHashingOptionsUsed)
            {
                List <byte> hashSchemaList = this.RequestHashingSchema.SerializeToByteList();
                this.RequestHashingOptionsDeclaration = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.RequestHashOptions, hashSchemaList.Count + 1);

                // Request Hashing Options Declaration
                byteList.AddRange(this.RequestHashingOptionsDeclaration.SerializeToByteList());

                // Request Hashing Schema
                byteList.AddRange(hashSchemaList);

                // Reserve
                BitWriter bw = new BitWriter(1);
                bw.AppendInit32(this.Reserve1, 1);
                bw.AppendInit32(this.Reserve2, 1);
                bw.AppendInit32(this.RequestDataElementHashesInsteadofData, 1);
                bw.AppendInit32(this.RequestDataElementHashes, 1);
                bw.AppendInit32(this.Reserve3, 4);
                byteList.AddRange(bw.Bytes);
            }

            // Sub-requests
            if (this.SubRequests != null && this.SubRequests.Count != 0)
            {
                foreach (FsshttpbCellSubRequest subRequest in this.SubRequests)
                {
                    byteList.AddRange(subRequest.SerializeToByteList());
                }
            }
            else
            {
                throw new InvalidOperationException("MUST contain sub request in request structure which is defined in the MS-FSSHTTPB.");
            }

            // Data Element Package
            if (this.DataElementPackage != null)
            {
                byteList.AddRange(this.DataElementPackage.SerializeToByteList());
            }

            // Cell Request End
            byteList.AddRange(this.CellRequestEnd.SerializeToByteList());

            return(byteList);
        }
        /// <summary>
        /// This method is used to convert the element into a byte List
        /// </summary>
        /// <returns>Return the Byte List</returns>
        public override List <byte> SerializeToByteList()
        {
            // Storage Index Extended GUID
            this.StorageIndexExtendedGUID = this.StorageIndexExtendedGUID ?? new ExGuid();
            List <byte> storageIndexExtendedGUIDBytes = this.StorageIndexExtendedGUID.SerializeToByteList();

            // Expect Storage Index Extended GUID
            List <byte> expectedStorageIndexExtendedGUIDBytes = this.ExpectedStorageIndexExtendedGUID.SerializeToByteList();

            // Put Changes Request
            this.PutChangesRequestStart = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.PutChangesRequest, 1 + storageIndexExtendedGUIDBytes.Count + expectedStorageIndexExtendedGUIDBytes.Count);
            List <byte> putChangesRequestBytes = this.PutChangesRequestStart.SerializeToByteList();

            // reserved
            BitWriter bitWriter = new BitWriter(1);

            bitWriter.AppendInit32(this.ImplyNullExpectedIfNoMapping, 1);
            bitWriter.AppendInit32(this.Partial, 1);
            bitWriter.AppendInit32(this.PartialLast, 1);
            bitWriter.AppendInit32(this.FavorCoherencyFailureOverNotFound, 1);
            bitWriter.AppendInit32(this.AbortRemainingPutChangesOnFailure, 1);
            bitWriter.AppendInit32(this.MultiRequestPutHint, 1);
            bitWriter.AppendInit32(this.ReturnCompleteKnowledgeIfPossible, 1);
            bitWriter.AppendInit32(this.LastWriterWinsOnNextChange, 1);

            List <byte> reservedBytes = new List <byte>(bitWriter.Bytes);

            List <byte> byteList = new List <byte>();

            // sub-request start
            byteList.AddRange(base.SerializeToByteList());

            // put change request
            byteList.AddRange(putChangesRequestBytes);

            // Storage Index Extended GUID
            byteList.AddRange(storageIndexExtendedGUIDBytes);

            // Expected Storage Index Extended GUID
            byteList.AddRange(expectedStorageIndexExtendedGUIDBytes);

            // reserved
            byteList.AddRange(reservedBytes);

            if (this.IsAdditionalFlagsUsed)
            {
                this.AdditionalFlagsStart = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.AdditionalFlags, 2);
                byteList.AddRange(this.AdditionalFlagsStart.SerializeToByteList());

                BitWriter additionalFlagsWriter = new BitWriter(2);
                additionalFlagsWriter.AppendInit32(this.ReturnAppliedStorageIndexIdEntries, 1);
                additionalFlagsWriter.AppendInit32(this.ReturnDataElementsAdded, 1);
                additionalFlagsWriter.AppendInit32(this.CheckForIdReuse, 1);
                additionalFlagsWriter.AppendInit32(this.CoherencyCheckOnlyAppliedIndexEntries, 1);
                additionalFlagsWriter.AppendInit32(this.FullFileReplacePut, 1);
                additionalFlagsWriter.AppendInit32(this.RequireStorageMappingsRooted, 1);
                additionalFlagsWriter.AppendInit32(this.Reserve, 10);
                byteList.AddRange(additionalFlagsWriter.Bytes);
            }

            if (this.IsLockIdUsed)
            {
                this.LockIdStart = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.PutChangesLockId, 16);
                byteList.AddRange(this.LockIdStart.SerializeToByteList());
                byteList.AddRange(this.LockID.ToByteArray());
            }

            if (this.OptionalClientKnowledge != null)
            {
                byteList.AddRange(this.OptionalClientKnowledge.SerializeToByteList());
            }

            if (this.IsDiagnosticRequestOptionInputUsed)
            {
                this.DiagnosticRequestOptionInputStart = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.DiagnosticRequestOptionInput, 2);
                byteList.AddRange(this.DiagnosticRequestOptionInputStart.SerializeToByteList());

                BitWriter diagnosticRequestOptionWriter = new BitWriter(2);
                diagnosticRequestOptionWriter.AppendInit32(this.ForceRevisionChainOptimization, 1);
                diagnosticRequestOptionWriter.AppendInit32(this.Reserve, 7);
                byteList.AddRange(diagnosticRequestOptionWriter.Bytes);
            }

            // sub-request end
            byteList.AddRange(this.ToBytesEnd());

            return(byteList);
        }
        /// <summary>
        /// This method is used to convert the element into a byte List
        /// </summary>
        /// <returns>Return the Byte List</returns>
        public override List <byte> SerializeToByteList()
        {
            List <byte> byteList = new List <byte>();

            byteList.AddRange(base.SerializeToByteList());

            // Query Changes Request
            byteList.AddRange(this.QueryChangesRequest.SerializeToByteList());

            // Reserved1
            BitWriter bitWriter = new BitWriter(1);

            bitWriter.AppendInit32(this.Reserved, 1);
            bitWriter.AppendInit32(this.AllowFragments, 1);
            bitWriter.AppendInit32(this.ExcludeObjectData, 1);
            bitWriter.AppendInit32(this.IncludeFilteredOutDataElementsInKnowledge, 1);
            bitWriter.AppendInit32(this.Reserved1, 4);
            byteList.AddRange(bitWriter.Bytes);

            // Cell ID bytes
            List <byte> cellIDBytes = this.CellId.SerializeToByteList();

            // Query Changes Request Arguments
            this.QueryChangesRequestArguments = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.QueryChangesRequestArguments, 1 + cellIDBytes.Count);
            byteList.AddRange(this.QueryChangesRequestArguments.SerializeToByteList());

            // Reserved2
            bitWriter = new BitWriter(1);
            bitWriter.AppendInit32(this.IncludeStorageManifest, 1);
            bitWriter.AppendInit32(this.IncludeCellChanges, 1);
            bitWriter.AppendInit32(this.Reserved2, 6);
            byteList.AddRange(bitWriter.Bytes);

            // Cell ID
            byteList.AddRange(cellIDBytes);

            // optional
            if (this.MaxDataElements != null)
            {
                if (this.MaxDataElements.DecodedValue > 0)
                {
                    // Max Data Elements bytes
                    List <byte> maxDataElementsBytes = (new Compact64bitInt(this.MaxDataElements.DecodedValue)).SerializeToByteList();

                    // Query Changes Data Constraints
                    this.QueryChangesDataConstraints = new StreamObjectHeaderStart32bit(StreamObjectTypeHeaderStart.QueryChangesDataConstraint, maxDataElementsBytes.Count);
                    byteList.AddRange(this.QueryChangesDataConstraints.SerializeToByteList());

                    // Max Data Elements
                    byteList.AddRange(maxDataElementsBytes);
                }
            }

            if (this.QueryChangeFilters != null)
            {
                foreach (Filter filter in this.QueryChangeFilters)
                {
                    byteList.AddRange(filter.SerializeToByteList());
                }
            }

            if (this.Knowledge != null)
            {
                byteList.AddRange(this.Knowledge.SerializeToByteList());
            }

            byteList.AddRange(this.ToBytesEnd());
            return(byteList);
        }