MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / Main

Method Main

projects/CSharp/Examples/Create/Program.cs:11–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9 public static class Program
10 {
11 public static void Main()
12 {
13 // Create a new account using FBE model
14 var account = new AccountModel();
15 long modelBegin = account.CreateBegin();
16 long accountBegin = account.model.SetBegin();
17 account.model.id.Set(1);
18 account.model.name.Set("Test");
19 account.model.state.Set(State.good);
20 long walletBegin = account.model.wallet.SetBegin();
21 account.model.wallet.currency.Set("USD");
22 account.model.wallet.amount.Set(1000.0);
23 account.model.wallet.SetEnd(walletBegin);
24 account.model.SetEnd(accountBegin);
25 account.CreateEnd(modelBegin);
26 Debug.Assert(account.Verify());
27
28 // Show the serialized FBE size
29 Console.WriteLine($"FBE size: {account.Buffer.Size}");
30
31 // Access the account using the FBE model
32 var access = new AccountModel();
33 access.Attach(account.Buffer);
34 Debug.Assert(access.Verify());
35
36 accountBegin = access.model.GetBegin();
37 access.model.id.Get(out var id);
38 access.model.name.Get(out var name);
39 access.model.state.Get(out var state);
40 walletBegin = access.model.wallet.GetBegin();
41 access.model.wallet.currency.Get(out var walletCurrency);
42 access.model.wallet.amount.Get(out var walletAmount);
43 access.model.wallet.GetEnd(walletBegin);
44 access.model.GetEnd(accountBegin);
45
46 // Show account content
47 Console.WriteLine();
48 Console.WriteLine($"account.id = {id}");
49 Console.WriteLine($"account.name = {name}");
50 Console.WriteLine($"account.state = {state}");
51 Console.WriteLine($"account.wallet.currency = {walletCurrency}");
52 Console.WriteLine($"account.wallet.amount = {walletAmount}");
53 }
54 }
55}

Callers

nothing calls this directly

Calls 10

CreateBeginMethod · 0.45
SetBeginMethod · 0.45
SetMethod · 0.45
SetEndMethod · 0.45
CreateEndMethod · 0.45
VerifyMethod · 0.45
AttachMethod · 0.45
GetBeginMethod · 0.45
GetMethod · 0.45
GetEndMethod · 0.45

Tested by

no test coverage detected