MCPcopy Index your code
hub / github.com/CCob/BOF.NET / Unpack

Method Unpack

managed/BOFNET/Unpack.cs:15–50  ·  view source on GitHub ↗
(string format, byte[] data)

Source from the content-addressed store, hash-verified

13 public List<object> Values { get; private set; } = new List<object>();
14
15 public Unpack(string format, byte[] data) {
16
17 BinaryReader br = new BinaryReader(new MemoryStream(data), Encoding.Unicode);
18
19 foreach(char code in format) {
20
21 switch (code) {
22 case 'Z':
23 int lenRaw = br.ReadInt32BE();
24 StringBuilder str = new StringBuilder();
25 char ch;
26
27 while ((ch = br.ReadChar()) != 0) {
28 str.Append(ch);
29 }
30
31 Values.Add(str.ToString());
32 break;
33
34 case 'i':
35 Values.Add(br.ReadInt32BE());
36 break;
37
38 case 's':
39 Values.Add(br.ReadInt16BE());
40 break;
41
42 case 'b':
43 Values.Add(br.ReadBytes(br.ReadInt32BE()));
44 break;
45
46 default:
47 throw new ArgumentException($"Invalid type {code} encountered in format string. Currently only type Z,i,s,b are supported");
48 }
49 }
50 }
51 }
52}

Callers

nothing calls this directly

Calls 3

ReadInt32BEMethod · 0.80
ToStringMethod · 0.80
ReadInt16BEMethod · 0.80

Tested by

no test coverage detected