示例#1
0
        public static sbyte GetLength(BinaryWriterFast stream, long value)
        {
            sbyte length = 1;

            value >>= 6;
            while (value > 0)
            {
                value >>= 7;
                length += 1;
            }
            return(length);
        }
示例#2
0
        public SimplerChunkWriter(byte[] magicNumber, Stream stream, Compression compression = Compression.None, int compressionLevel = ZLib.DefaultCompressionLevel)
        {
            stream.Write(magicNumber, 0, magicNumber.Length);
            _compression      = compression;
            _compressionLevel = compressionLevel;
            _baseStream       = stream;

            switch (compression)
            {
            case Compression.None:
                new BinaryWriter(stream).Write((uint)0);
                _writer = new BinaryWriterFast(stream);
                break;

            case Compression.Zlib:
                new BinaryWriter(stream).Write((uint)0x80000000);
                _writer = new BinaryWriterFast(new MemoryStream());
                break;

            default:
                throw new ArgumentException("compression");
            }
        }
示例#3
0
        public static void Write(BinaryWriterFast stream, long value, long maximumSize)
        {
            do
            {
                // Write byte
                byte currentByte = unchecked ((byte)(value & 0x7F));
                if (maximumSize >> 6 == 0 || maximumSize >> 6 == -1)
                {
                    stream.Write(currentByte);

                    if (value >> 6 != 0 && value >> 6 != -1)
                    {
                        throw new OverflowException("Unable to write integer because the available space overflowed.");
                    }

                    return;
                }
                stream.Write((byte)(currentByte | 0x80));

                // Move data to next byte
                value       >>= 7;
                maximumSize >>= 7;
            } while (true);
        }
示例#4
0
 public static void Write(BinaryWriterFast stream, long value) => Write(stream, value, value);
示例#5
0
 public void ToStream(BinaryWriterFast stream)
 {
     LEB128.Write(stream, _idLength);
     stream.Write(_idBytes, 0, _idLength);
 }
示例#6
0
 public ChunkWriter(byte[] magicNumber, BinaryWriterFast fastWriter)
 {
     fastWriter.Write(magicNumber, 0, magicNumber.Length);
     fastWriter.Write(BitConverter.GetBytes(0), 0, 4);    // @FIXME: where is the compression handling, as above?
     _writer = fastWriter;
 }