public static sbyte GetLength(BinaryWriterFast stream, long value) { sbyte length = 1; value >>= 6; while (value > 0) { value >>= 7; length += 1; } return(length); }
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"); } }
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); }
public static void Write(BinaryWriterFast stream, long value) => Write(stream, value, value);
public void ToStream(BinaryWriterFast stream) { LEB128.Write(stream, _idLength); stream.Write(_idBytes, 0, _idLength); }
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; }