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

Function main

projects/Python/examples/create.py:6–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5
6def main():
7 # Create a new account using FBE model
8 account = proto.AccountModel(fbe.WriteBuffer())
9 model_begin = account.create_begin()
10 account_begin = account.model.set_begin()
11 account.model.id.set(1)
12 account.model.name.set("Test")
13 account.model.state.set(proto.State.good)
14 wallet_begin = account.model.wallet.set_begin()
15 account.model.wallet.currency.set("USD")
16 account.model.wallet.amount.set(1000.0)
17 account.model.wallet.set_end(wallet_begin)
18 account.model.set_end(account_begin)
19 account.create_end(model_begin)
20 assert account.verify()
21
22 # Show the serialized FBE size
23 print("FBE size: {}".format(account.buffer.size))
24
25 # Access the account using the FBE model
26 access = proto.AccountModel(fbe.ReadBuffer())
27 access.attach_buffer(account.buffer)
28 assert access.verify()
29
30 account_begin = access.model.get_begin()
31 id = access.model.id.get()
32 name = access.model.name.get()
33 state = access.model.state.get()
34 wallet_begin = access.model.wallet.get_begin()
35 wallet_currency = access.model.wallet.currency.get()
36 wallet_amount = access.model.wallet.amount.get()
37 access.model.wallet.get_end(wallet_begin)
38 access.model.get_end(account_begin)
39
40 # Show account content
41 print()
42 print("account.id = {}".format(id))
43 print("account.name = {}".format(name))
44 print("account.state = {}".format(state))
45 print("account.wallet.currency = {}".format(wallet_currency))
46 print("account.wallet.amount = {}".format(wallet_amount))
47
48
49if __name__ == "__main__":

Callers 1

create.pyFile · 0.70

Calls 12

create_beginMethod · 0.95
create_endMethod · 0.95
verifyMethod · 0.95
AccountModelMethod · 0.45
set_beginMethod · 0.45
setMethod · 0.45
set_endMethod · 0.45
formatMethod · 0.45
attach_bufferMethod · 0.45
get_beginMethod · 0.45
getMethod · 0.45
get_endMethod · 0.45

Tested by

no test coverage detected