예제 #1
0
        public virtual void ReadExtras(byte[] buffer)
        {
            if (buffer.Length > Header.ExtrasOffset)
            {
                var format = new byte();
                var flags  = Converter.ToByte(buffer, Header.ExtrasOffset);
                Converter.SetBit(ref format, 0, Converter.GetBit(flags, 0));
                Converter.SetBit(ref format, 1, Converter.GetBit(flags, 1));
                Converter.SetBit(ref format, 2, Converter.GetBit(flags, 2));
                Converter.SetBit(ref format, 3, Converter.GetBit(flags, 3));

                var compression = new byte();
                Converter.SetBit(ref compression, 4, Converter.GetBit(flags, 4));
                Converter.SetBit(ref compression, 5, Converter.GetBit(flags, 5));
                Converter.SetBit(ref compression, 6, Converter.GetBit(flags, 6));

                var typeCode = (TypeCode)(Converter.ToUInt16(buffer, 26) & 0xff);
                Format            = (DataFormat)format;
                Compression       = (Compression)compression;
                Flags.DataFormat  = Format;
                Flags.Compression = Compression;
                Flags.TypeCode    = typeCode;
                Expires           = Converter.ToUInt32(buffer, 25);
            }
        }
예제 #2
0
        public virtual byte[] CreateExtras()
        {
            var        extras      = new byte[8];
            var        format      = (byte)GetFormat();
            const byte compression = (byte)Compression.None;

            Converter.SetBit(ref extras[0], 0, Converter.GetBit(format, 0));
            Converter.SetBit(ref extras[0], 1, Converter.GetBit(format, 1));
            Converter.SetBit(ref extras[0], 2, Converter.GetBit(format, 2));
            Converter.SetBit(ref extras[0], 3, Converter.GetBit(format, 3));
            Converter.SetBit(ref extras[0], 4, false);
            Converter.SetBit(ref extras[0], 5, Converter.GetBit(compression, 0));
            Converter.SetBit(ref extras[0], 6, Converter.GetBit(compression, 1));
            Converter.SetBit(ref extras[0], 7, Converter.GetBit(compression, 2));

            var typeCode = (ushort)Type.GetTypeCode(typeof(T));

            Converter.FromUInt16(typeCode, extras, 2);
            Converter.FromUInt32(Expires, extras, 4);

            Format      = (DataFormat)format;
            Compression = compression;

            Flags.DataFormat  = Format;
            Flags.Compression = Compression;
            Flags.TypeCode    = (TypeCode)typeCode;

            return(extras);
        }