This repository has been archived by the owner on Feb 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProgram.cs
46 lines (37 loc) · 1.44 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using BeeSchema;
namespace Example {
class Program {
static void Main() {
// Create an instance of a Schema object from a file.
var schema = Schema.FromFile("example.bee");
// Parse our example binary data with the resulting Schema instance.
var result = schema.Parse("example.bin");
/* The Result class supports both implicit and explicit conversion.
This makes it easy to get the Result's value if you know the expected data type.
Declared variables can be retrieved by both index and name. */
byte first = result[0];
var anInt = (int)result["an_int"];
byte[] bytes = result["a_struct"]["bytes"];
// Print the values grabbed from the return Result.
Console.WriteLine($"first result: {first}");
Console.WriteLine($"an_int: {anInt}");
Console.Write("a_struct.bytes: ");
foreach (var b in bytes)
Console.Write($"{b}, ");
// Print all values from the returned Result, recursing into any values that have children.
Console.WriteLine("\n\nresults:");
WriteResults(result);
Console.ReadKey();
}
static void WriteResults(ResultCollection r, int tab = 0) {
foreach (var v in r) {
// Print the current value's type, name and value.
Console.WriteLine($"{new string('\t', tab)}{v.TypeName} {v.Name} : {v.Value}");
// If the current value is a struct, bitfield or array, print all its children.
if (v.HasChildren)
WriteResults(v.Children, tab + 1);
}
}
}
}