| 11 | #include <iostream> |
| 12 | |
| 13 | int main(int argc, char** argv) |
| 14 | { |
| 15 | // Create a new account using FBE model |
| 16 | FBE::proto::AccountModel account; |
| 17 | size_t model_begin = account.create_begin(); |
| 18 | size_t account_begin = account.model.set_begin(); |
| 19 | account.model.id.set(1); |
| 20 | account.model.name.set("Test"); |
| 21 | account.model.state.set(proto::State::good); |
| 22 | size_t wallet_begin = account.model.wallet.set_begin(); |
| 23 | account.model.wallet.currency.set("USD"); |
| 24 | account.model.wallet.amount.set(1000.0); |
| 25 | account.model.wallet.set_end(wallet_begin); |
| 26 | account.model.set_end(account_begin); |
| 27 | account.create_end(model_begin); |
| 28 | assert(account.verify()); |
| 29 | |
| 30 | // Show the serialized FBE size |
| 31 | std::cout << "FBE size: " << account.buffer().size() << std::endl; |
| 32 | |
| 33 | // Access the account using the FBE model |
| 34 | FBE::proto::AccountModel access; |
| 35 | access.attach(account.buffer()); |
| 36 | assert(access.verify()); |
| 37 | |
| 38 | int32_t id; |
| 39 | std::string name; |
| 40 | proto::State state; |
| 41 | std::string wallet_currency; |
| 42 | double wallet_amount; |
| 43 | |
| 44 | account_begin = access.model.get_begin(); |
| 45 | access.model.id.get(id); |
| 46 | access.model.name.get(name); |
| 47 | access.model.state.get(state); |
| 48 | wallet_begin = access.model.wallet.get_begin(); |
| 49 | access.model.wallet.currency.get(wallet_currency); |
| 50 | access.model.wallet.amount.get(wallet_amount); |
| 51 | access.model.wallet.get_end(wallet_begin); |
| 52 | access.model.get_end(account_begin); |
| 53 | |
| 54 | // Show account content |
| 55 | std::cout << std::endl; |
| 56 | std::cout << "account.id = " << id << std::endl; |
| 57 | std::cout << "account.name = " << name << std::endl; |
| 58 | std::cout << "account.state = " << state << std::endl; |
| 59 | std::cout << "account.wallet.currency = " << wallet_currency << std::endl; |
| 60 | std::cout << "account.wallet.amount = " << wallet_amount << std::endl; |
| 61 | |
| 62 | return 0; |
| 63 | } |
nothing calls this directly
no test coverage detected