|
static void | ReadBytes (this Stream stream, byte[] buf) |
|
static byte[] | ReadBytes (this Stream stream, int len) |
|
static byte[] | ReadBytes (this Stream stream, long len) |
|
static Item | ReadItem (this BinaryReader reader, bool readStack=false, bool readFavorite=false) |
|
static int | ReadVarInt (this BinaryReader reader) |
|
static void | SafeRead (this BinaryReader reader, Action< BinaryReader > read) |
|
static void | SafeWrite (this BinaryWriter writer, Action< BinaryWriter > write) |
|
static void | WriteItem (this BinaryWriter writer, Item item, bool readStack=false, bool readFavorite=false) |
|
static void | WriteVarInt (this BinaryWriter writer, int value) |
|
Definition at line 6 of file BinaryIO.cs.
◆ ReadBytes() [1/3]
static void Terraria.ModLoader.IO.BinaryIO.ReadBytes |
( |
this Stream |
stream, |
|
|
byte[] |
buf |
|
) |
| |
|
static |
Definition at line 62 of file BinaryIO.cs.
62 {
63 int r, pos = 0;
64 while ((r = stream.Read(buf, pos, buf.Length - pos)) > 0)
65 pos += r;
66
67 if (pos != buf.Length)
68 throw new IOException($
"Stream did not contain enough bytes ({pos}) < ({buf.Length})");
69 }
◆ ReadBytes() [2/3]
static byte[] Terraria.ModLoader.IO.BinaryIO.ReadBytes |
( |
this Stream |
stream, |
|
|
int |
len |
|
) |
| |
|
static |
◆ ReadBytes() [3/3]
static byte[] Terraria.ModLoader.IO.BinaryIO.ReadBytes |
( |
this Stream |
stream, |
|
|
long |
len |
|
) |
| |
|
static |
Definition at line 73 of file BinaryIO.cs.
73 {
74 var buf = new byte[len];
75 stream.ReadBytes(buf);
76 return buf;
77 }
◆ ReadItem()
static Item Terraria.ModLoader.IO.BinaryIO.ReadItem |
( |
this BinaryReader |
reader, |
|
|
bool |
readStack = false , |
|
|
bool |
readFavorite = false |
|
) |
| |
|
static |
◆ ReadVarInt()
static int Terraria.ModLoader.IO.BinaryIO.ReadVarInt |
( |
this BinaryReader |
reader | ) |
|
|
static |
Definition at line 27 of file BinaryIO.cs.
27 {
28
29
30 int count = 0;
31 int shift = 0;
32 byte b;
33 do {
34
35 if (shift == 5 * 7)
36 throw new FormatException("variable length int with more than 32 bits");
37
38
39 b = reader.ReadByte();
40 count |= (b & 0x7F) << shift;
41 shift += 7;
42 } while ((b & 0x80) != 0);
43 return count;
44 }
◆ SafeRead()
Definition at line 54 of file BinaryIO.cs.
54 {
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");
60 }
◆ SafeWrite()
Definition at line 46 of file BinaryIO.cs.
46 {
47 var ms = new MemoryStream();
49 writer.WriteVarInt((int)ms.Length);
50 ms.Position = 0;
51 ms.CopyTo(writer.BaseStream);
52 }
◆ WriteItem()
static void Terraria.ModLoader.IO.BinaryIO.WriteItem |
( |
this BinaryWriter |
writer, |
|
|
Item |
item, |
|
|
bool |
readStack = false , |
|
|
bool |
readFavorite = false |
|
) |
| |
|
static |
◆ WriteVarInt()
static void Terraria.ModLoader.IO.BinaryIO.WriteVarInt |
( |
this BinaryWriter |
writer, |
|
|
int |
value |
|
) |
| |
|
static |
Definition at line 15 of file BinaryIO.cs.
15 {
16
17
18 uint v = (uint)value;
19 while (v >= 0x80) {
20 writer.Write((byte)(v | 0x80));
21 v >>= 7;
22 }
23 writer.Write((byte)v);
24 }