Skip to content

Commit 52a1afa

Browse files
authored
Merge pull request #16 from nmcdonnell-kx/master
Update examples/README.md - Fixes #15
2 parents 6c432b2 + 67838f2 commit 52a1afa

File tree

8 files changed

+48
-8
lines changed

8 files changed

+48
-8
lines changed

examples/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ More basic example workflows are highlighted in the documentation for this inter
1111

1212
`src/examples.proto` provides sample message definitions which help to illustrate the different protobuf field types and the mappings each uses when converting to and from kdb: `ScalarExample`, `RepeatedExample`, `SubMessageExample`, `MapExample`, `SpecifierExample` and `OneofExample`.
1313

14-
The following is a line by line execution of the first section of the example contained in `examples.q`:
14+
The following example is taken from the first section in `examples/scalar.q`:
1515

1616
```
1717
q).protobufkdb.displayMessageSchema[`ScalarExample]
@@ -21,18 +21,18 @@ message ScalarExample {
2121
string scalar_string = 3;
2222
}
2323
24-
q)a:(12i;55f;`str)
24+
q)scalars:(12i;55f;`str)
2525
26-
// Serialise the kdb structure to a protobuf encoded char array:
27-
q)array:.protobufkdb.serializeArray[`ScalarExample;a]
26+
// Serialize the kdb structure to a protobuf encoded char array:
27+
q)serialized:.protobufkdb.serializeArray[`ScalarExample;a]
2828
29-
q)array
29+
q)serialized
3030
"\010\014\021\000\000\000\000\000\200K@\032\003str"
3131
3232
// Parse the char array back to kdb and check the result is the same as the original mixed list
33-
q)b:.protobufkdb.parseArray[`ScalarExample;array]
33+
q)deserialized:.protobufkdb.parseArray[`ScalarExample;serialized]
3434
35-
q)a~b
35+
q)scalars~deserialized
3636
1b
3737
```
3838

@@ -52,7 +52,7 @@ q)array:.protobufkdb.serializeArray[`ScalarExample;(12j;55f;`str)]
5252

5353
Equivalent to the compiled in message examples, `proto/examples_dynamic.proto` provides sample message definitions which help to illustrate the different protobuf field types and the mappings each uses when converting to and from kdb: `ScalarExampleDynamic`, `RepeatedExampleDynamic`, `SubMessageExampleDynamic`, `MapExampleDynamic`, `SpecifierExampleDynamic` and `OneofExampleDynamic`.
5454

55-
The following example is taken from `examples/examples_dynamic.q` and outlines the retrieval of a schema from a `.proto` file based specified on a specified import search path. So if the q session is started in the `examples` subdirectory then the path to the `proto` subdirectory is specified as follows:
55+
The following example is taken from the second section of `examples/scalar.q` and outlines the retrieval of a schema from a `.proto` file based specified on a specified import search path. So if the q session is started in the `examples` subdirectory then the path to the `proto` subdirectory is specified as follows:
5656

5757
```
5858
q).protobufkdb.addProtoImportPath["../proto"]

examples/handling_files.q

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ saveMessage[`ScalarExample; `sample_scalars_file; scalars];
2020
loaded:loadMessage[`ScalarExample; `sample_scalars_file];
2121
show loaded;
2222

23+
// Compare the kdb+ objects
24+
show scalars~loaded
25+
2326
-1 "\n+----------------------------------------+\n";
2427

2528
// Process off

examples/map.q

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ show serialized;
5858
deserialized:.protobufkdb.parseArray[`MapExampleDynamic; serialized];
5959
show deserialized;
6060

61+
// Ordering of protobuf maps is undefined so compare using key lookups
62+
show (count map)~(count deserialized);
63+
show map[0][0]~deserialized[0][0];
64+
show map[1][`s1]~deserialized[1][`s1];
65+
show map[1][`s2]~deserialized[1][`s2];
66+
show map[1][`s3]~deserialized[1][`s3];
67+
6168
-1 "\n+----------------------------------------+\n";
6269

6370
// Process off

examples/one_of.q

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ show serialized;
2828
deserialized:.protobufkdb.parseArray[`OneofExample; serialized];
2929
show deserialized;
3030

31+
// Compare the kdb+ objects
32+
show oneof~deserialized
33+
3134
// Serialize into char array and then deserialize char array into kdb+ data
3235
deserialized:.protobufkdb.parseArray[`OneofExample;.protobufkdb.serializeArray[`OneofExample;(();12:34:56;`str)]];
3336
show deserialized;
@@ -57,6 +60,9 @@ show serialized;
5760
deserialized:.protobufkdb.parseArray[`OneofExampleDynamic; serialized];
5861
show deserialized;
5962

63+
// Compare the kdb+ objects
64+
show oneof~deserialized
65+
6066
// Serialize into char array and then deserialize char array into kdb+ data
6167
deserialized:.protobufkdb.parseArray[`OneofExampleDynamic;.protobufkdb.serializeArray[`OneofExampleDynamic;(();00:01:02;`foo)]];
6268
show deserialized;

examples/repeated.q

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ show serialized;
2727
deserialized:.protobufkdb.parseArray[`RepeatedExample; serialized];
2828
show deserialized;
2929

30+
// Compare the kdb+ objects
31+
show repeated~deserialized
32+
3033
//-------------------------------------------------//
3134
// Example-2. Use dynamically imported schema file //
3235
//-------------------------------------------------//
@@ -51,6 +54,9 @@ show serialized;
5154
deserialized:.protobufkdb.parseArray[`RepeatedExampleDynamic; serialized];
5255
show deserialized;
5356

57+
// Compare the kdb+ objects
58+
show repeated~deserialized
59+
5460
-1 "\n+----------------------------------------+\n";
5561

5662
// Process off

examples/scalar.q

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ show serialized;
2727
deserialized:.protobufkdb.parseArray[`ScalarExample; serialized];
2828
show deserialized;
2929

30+
// Compare the kdb+ objects
31+
show scalars~deserialized
32+
3033
//-------------------------------------------------//
3134
// Example-2. Use dynamically imported schema file //
3235
//-------------------------------------------------//
@@ -51,6 +54,9 @@ show serialized;
5154
deserialized:.protobufkdb.parseArray[`ScalarExampleDynamic; serialized]
5255
show deserialized;
5356

57+
// Compare the kdb+ objects
58+
show scalars~deserialized
59+
5460
-1 "\n+----------------------------------------+\n";
5561

5662
// Process off

examples/sub_message.q

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ show serialized;
2727
deserialized:.protobufkdb.parseArray[`SubMessageExample; serialized];
2828
show deserialized;
2929

30+
// Compare the kdb+ objects
31+
show submessage~deserialized
32+
3033
//-------------------------------------------------//
3134
// Example-2. Use dynamically imported schema file //
3235
//-------------------------------------------------//
@@ -51,6 +54,9 @@ show serialized;
5154
deserialized:.protobufkdb.parseArray[`SubMessageExampleDynamic; serialized];
5255
show deserialized;
5356

57+
// Compare the kdb+ objects
58+
show submessage~deserialized
59+
5460
-1 "\n+----------------------------------------+\n";
5561

5662
// Process off

examples/type_specifier.q

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ show serialized;
2727
deserialized:.protobufkdb.parseArray[`SpecifierExample;serialized];
2828
show deserialized;
2929

30+
// Compare the kdb+ objects
31+
show type_specified~deserialized
32+
3033
//-------------------------------------------------//
3134
// Example-2. Use dynamically imported schema file //
3235
//-------------------------------------------------//
@@ -51,6 +54,9 @@ show serialized;
5154
deserialized:.protobufkdb.parseArray[`SpecifierExampleDynamic;serialized];
5255
show deserialized;
5356

57+
// Compare the kdb+ objects
58+
show type_specified~deserialized
59+
5460
-1 "\n+----------------------------------------+\n";
5561

5662
// Process off

0 commit comments

Comments
 (0)