Пример #1
0
        /// <summary>
        /// This method is used to deserialize the SerialNumber basic object from the specified byte array and start index.
        /// </summary>
        /// <param name="byteArray">Specify the byte array.</param>
        /// <param name="startIndex">Specify the start index from the byte array.</param>
        /// <returns>Return the length in byte of the SerialNumber basic object.</returns>
        protected override int DoDeserializeFromByteArray(byte[] byteArray, int startIndex) // return the length consumed
        {
            using (BitReader bitField = new BitReader(byteArray, startIndex))
            {
                int type = bitField.ReadInt32(8);

                if (type == 0)
                {
                    this.GUID = Guid.Empty;
                    this.Type = 0;

                    return(1);
                }
                else if (type == 128)
                {
                    this.GUID  = bitField.ReadGuid();
                    this.Value = bitField.ReadUInt64(64);
                    this.Type  = 128;
                    return(25);
                }
                else
                {
                    throw new System.IO.IOException("Failed to parse SerialNumber object, Expect the type value is either 0 or 128, but the actual value is " + this.Type);
                }
            }
        }
 /// <summary>
 /// This method is used to get the compressed size value from the data file signature.
 /// </summary>
 /// <param name="dataFileSignature">Specify the signature of the zip file content.</param>
 /// <returns>Return the compressed size value.</returns>
 private ulong GetCompressedSize(byte[] dataFileSignature)
 {
     using (BitReader reader = new BitReader(dataFileSignature, 0))
     {
         reader.ReadUInt32(32);
         return(reader.ReadUInt64(64));
     }
 }
Пример #3
0
        /// <summary>
        /// This method is used to deserialize the Compact64bitInt basic object from the specified byte array and start index.
        /// </summary>
        /// <param name="byteArray">Specify the byte array.</param>
        /// <param name="startIndex">Specify the start index from the byte array.</param>
        /// <returns>Return the length in byte of the Compact64bitInt basic object.</returns>
        protected override int DoDeserializeFromByteArray(byte[] byteArray, int startIndex) // return the length consumed
        {
            using (BitReader bitReader = new BitReader(byteArray, startIndex))
            {
                int numberOfContinousZeroBit = 0;
                while (numberOfContinousZeroBit < 8 && bitReader.MoveNext())
                {
                    if (bitReader.Current == false)
                    {
                        numberOfContinousZeroBit++;
                    }
                    else
                    {
                        break;
                    }
                }

                switch (numberOfContinousZeroBit)
                {
                case 0:
                    this.DecodedValue = bitReader.ReadUInt64(7);
                    this.Type         = CompactUint7bitType;
                    return(1);

                case 1:
                    this.DecodedValue = bitReader.ReadUInt64(14);
                    this.Type         = CompactUint14bitType;
                    return(2);

                case 2:
                    this.DecodedValue = bitReader.ReadUInt64(21);
                    this.Type         = CompactUint21bitType;
                    return(3);

                case 3:
                    this.DecodedValue = bitReader.ReadUInt64(28);
                    this.Type         = CompactUint28bitType;
                    return(4);

                case 4:
                    this.DecodedValue = bitReader.ReadUInt64(35);
                    this.Type         = CompactUint35bitType;
                    return(5);

                case 5:
                    this.DecodedValue = bitReader.ReadUInt64(42);
                    this.Type         = CompactUint42bitType;
                    return(6);

                case 6:
                    this.DecodedValue = bitReader.ReadUInt64(49);
                    this.Type         = CompactUint49bitType;
                    return(7);

                case 7:
                    this.DecodedValue = bitReader.ReadUInt64(64);
                    this.Type         = CompactUint64bitType;
                    return(9);

                case 8:
                    this.DecodedValue = 0;
                    this.Type         = CompactUintNullType;
                    return(1);

                default:
                    throw new InvalidOperationException("Failed to parse the Compact64bitInt, the type value is unexpected");
                }
            }
        }