Esempio n. 1
0
        /// <summary>
        /// This method is used to deserialize the ExGuid 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 ExGuid basic object.</returns>
        protected override int DoDeserializeFromByteArray(byte[] byteArray, int startIndex)
        {
            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 2:
                    this.Value = bitReader.ReadUInt32(5);
                    this.GUID  = bitReader.ReadGuid();
                    this.Type  = ExtendedGUID5BitUintType;
                    return(17);

                case 5:
                    this.Value = bitReader.ReadUInt32(10);
                    this.GUID  = bitReader.ReadGuid();
                    this.Type  = ExtendedGUID10BitUintType;
                    return(18);

                case 6:
                    this.Value = bitReader.ReadUInt32(17);
                    this.GUID  = bitReader.ReadGuid();
                    this.Type  = ExtendedGUID17BitUintType;
                    return(19);

                case 7:
                    this.Value = bitReader.ReadUInt32(32);
                    this.GUID  = bitReader.ReadGuid();
                    this.Type  = ExtendedGUID32BitUintType;
                    return(21);

                case 8:
                    this.GUID = Guid.Empty;
                    this.Type = ExtendedGUIDNullType;
                    return(1);

                default:
                    throw new InvalidOperationException("Failed to parse the ExGuid, the type value is unexpected");
                }
            }
        }
        /// <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);
                }
            }
        }