-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_candid_type_float32.cpp
More file actions
52 lines (41 loc) · 1.81 KB
/
Copy pathdemo_candid_type_float32.cpp
File metadata and controls
52 lines (41 loc) · 1.81 KB
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
47
48
49
50
51
52
/* file: https://github.com/icppWorld/icpp-demos/tree/main/canisters/api_reference/src/demo_candid_type_float32.cpp
$ icp canister call demo demo_candid_type_float32 '(0.1 : float32)' --environment local
(0.1 : float32)
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_float32 received value '0.100000'
$ icp canister call demo demo_candid_type_float32s '(0.1 : float32, -1.2 : float32)' --environment local
(0.1 : float32, -1.2 : float32)
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_float32s received values '0.100000' & '-1.200000'
*/
#include "demo_candid_type_float32.h"
#include <iostream>
#include <string>
#include "ic_api.h"
void demo_candid_type_float32() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
float in{0.0};
ic_api.from_wire(CandidTypeFloat32{&in});
std::cout << "Method " + std::string(__func__) + " received value '" +
std::to_string(in) + "'"
<< std::endl;
ic_api.to_wire(CandidTypeFloat32{in});
}
void demo_candid_type_float32s() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
float in1{0.0};
float in2{0.0};
CandidArgs args_in;
args_in.append(CandidTypeFloat32(&in1));
args_in.append(CandidTypeFloat32(&in2));
ic_api.from_wire(args_in);
std::cout << "Method " + std::string(__func__) + " received values '" +
std::to_string(in1) + "' & '" + std::to_string(in2) + "'"
<< std::endl;
CandidArgs args_out;
args_out.append(CandidTypeFloat32(in1));
args_out.append(CandidTypeFloat32(in2));
ic_api.to_wire(args_out);
}