-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscalar.q
60 lines (42 loc) · 1.66 KB
/
scalar.q
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
53
54
55
56
57
58
59
60
// scalar.q
// Examples of serializing from and deserializing to scalar kdb+ data (atom)
-1"\n+----------|| scalar.q ||----------+\n";
// import the Protobuf library
\l ../q/protobufkdb.q
//-------------------------------------//
// Example-1. Use compiled schema file //
//-------------------------------------//
// Show embeded schema of ScalarExample message
.protobufkdb.displayMessageSchema[`ScalarExample];
// Prepare scalar (atom) data
scalars:(12i;55f;"str");
// Serialize data into char array
serialized:.protobufkdb.serializeArrayFromList[`ScalarExample; scalars];
show serialized;
// Deserialize char array into kdb+ data
deserialized:.protobufkdb.parseArrayToList[`ScalarExample; serialized];
show deserialized;
// Compare the kdb+ objects
show scalars~deserialized
//-------------------------------------------------//
// Example-2. Use dynamically imported schema file //
//-------------------------------------------------//
// Add impot path of schema file for dynamic schema import
.protobufkdb.addProtoImportPath["../proto"];
// Import schema file
.protobufkdb.importProtoFile["examples_dynamic.proto"];
// Display imported schema of ScalarExampleDynamic message
.protobufkdb.displayMessageSchema[`ScalarExampleDynamic];
// Prepare scalar data
scalars:(12i;55f;"str");
// Serialize data into char array
serialized:.protobufkdb.serializeArrayFromList[`ScalarExampleDynamic; scalars];
show serialized;
// Deserialize char array into kdb+ data
deserialized:.protobufkdb.parseArrayToList[`ScalarExampleDynamic; serialized]
show deserialized;
// Compare the kdb+ objects
show scalars~deserialized
-1 "\n+----------------------------------------+\n";
// Process off
exit 0;