-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_specifier.q
60 lines (42 loc) · 1.86 KB
/
type_specifier.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
// repeated.q
// Examples of serializing from and deserializing to type specified kdb+ data
-1"\n+----------|| type_specified.q ||----------+\n";
// import the Protobuf library
\l ../q/protobufkdb.q
//-------------------------------------//
// Example-1. Use compiled schema file //
//-------------------------------------//
// Show embeded schema of SpecifierExample message
.protobufkdb.displayMessageSchema[`SpecifierExample];
// Prepare type specified data
type_specified:(2020.01.01;enlist 12:34:56.123;(1?0Ng)!(enlist 12:34:56.123456789));
// Serialize data into char array
serialized:.protobufkdb.serializeArrayFromList[`SpecifierExample; type_specified];
show serialized;
// Deserialize char array into kdb+ data
deserialized:.protobufkdb.parseArrayToList[`SpecifierExample;serialized];
show deserialized;
// Compare the kdb+ objects
show type_specified~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"];
// Show embeded schema of SpecifierExampleDynamic message
.protobufkdb.displayMessageSchema[`SpecifierExampleDynamic];
// Prepare type specified data
type_specified:(2008.02.29;00:30:58 12:34:56.123;(2?0Ng)!2D00:00:00:000000001 12:34:56.123456789);
// Serialize data into char array
serialized:.protobufkdb.serializeArrayFromList[`SpecifierExampleDynamic; type_specified];
show serialized;
// Deserialize char array into kdb+ data
deserialized:.protobufkdb.parseArrayToList[`SpecifierExampleDynamic;serialized];
show deserialized;
// Compare the kdb+ objects
show type_specified~deserialized
-1 "\n+----------------------------------------+\n";
// Process off
exit 0;