8 public static void WriteItem(
this BinaryWriter writer, Item item,
bool readStack =
false,
bool readFavorite =
false) =>
9 ItemIO.
Send(item, writer, readStack, readFavorite);
20 writer.Write((
byte)(v | 0x80));
23 writer.Write((
byte)v);
36 throw new FormatException(
"variable length int with more than 32 bits");
39 b = reader.ReadByte();
40 count |= (b & 0x7F) << shift;
42 }
while ((b & 0x80) != 0);
47 var ms =
new MemoryStream();
49 writer.WriteVarInt((
int)ms.Length);
51 ms.CopyTo(writer.BaseStream);
55 int length = reader.ReadVarInt();
56 var ms =
new MemoryStream(reader.ReadBytes(length));
58 if (ms.Position != length)
59 throw new IOException(
"Read underflow " + ms.Position +
" of " + length +
" bytes");
62 public static void ReadBytes(
this Stream stream,
byte[] buf) {
64 while ((r = stream.Read(buf, pos, buf.Length - pos)) > 0)
67 if (pos != buf.Length)
68 throw new IOException($
"Stream did not contain enough bytes ({pos}) < ({buf.Length})");
73 public static byte[]
ReadBytes(
this Stream stream,
long len) {
74 var buf =
new byte[len];
75 stream.ReadBytes(buf);
static void WriteItem(this BinaryWriter writer, Item item, bool readStack=false, bool readFavorite=false)
static void WriteVarInt(this BinaryWriter writer, int value)
static int ReadVarInt(this BinaryReader reader)
static void ReadBytes(this Stream stream, byte[] buf)
static byte[] ReadBytes(this Stream stream, int len)
static void SafeWrite(this BinaryWriter writer, Action< BinaryWriter > write)
static byte[] ReadBytes(this Stream stream, long len)
static void SafeRead(this BinaryReader reader, Action< BinaryReader > read)
static Item ReadItem(this BinaryReader reader, bool readStack=false, bool readFavorite=false)
static void Receive(Item item, BinaryReader reader, bool readStack=false, bool readFavorite=false)
static void Send(Item item, BinaryWriter writer, bool writeStack=false, bool writeFavourite=false)