Encoders
.qsp.encode.json
Serialize data into JSON format
.qsp.encode.json[]
.qsp.encode.json[.qsp.use enlist[`split]!enlist split]
options:
name | type | description | default |
---|---|---|---|
split | boolean | By default, batches are encoded as single JSON objects. Split encodes each value in a given batch separately. When the input is a table, this encodes each row as its own JSON object. | 0b |
For all common arguments, refer to configuring operators
This operator encodes a table as a JSON array of dictionaries.
.qsp.run
.qsp.read.fromCallback[`publish]
.qsp.encode.json[]
.qsp.write.toVariable[`output]
publish ([] date: .z.d; time: .z.t; price: 3?100f; quantity: 3?100f)
// Format the output to help with viewing
-1 "},\n {" sv "},{" vs output;
[{"date":"2022-02-10","time":"17:46:36.545","price":48.29742,"quantity":73.15636},
{"date":"2022-02-10","time":"17:46:36.545","price":51.24386,"quantity":3.691923},
{"date":"2022-02-10","time":"17:46:36.545","price":51.5731,"quantity":97.58372}]
Encodes a table row by row in JSON
.qsp.run
.qsp.read.fromCallback[`publish]
.qsp.encode.json[.qsp.use``split!11b]
.qsp.write.toVariable[`output]
publish ([] date: .z.d; time: .z.t; price: 3?100f; quantity: 3?100f)
// View the output
-1 output;
{"date":"2022-02-10","time":"17:46:36.545","price":48.29742,"quantity":73.15636}
{"date":"2022-02-10","time":"17:46:36.545","price":51.24386,"quantity":3.691923}
{"date":"2022-02-10","time":"17:46:36.545","price":51.5731,"quantity":97.58372}
.qsp.encode.protobuf
Serialize data into Protocol Buffers
.qsp.encode.protobuf[message; file]
.qsp.decode.protobuf[message; file; .qsp.use (!) . flip (
(`format ; format);
(`payloadType; payloadType))]
Parameters:
name | type | description | default |
---|---|---|---|
message | string or symbol | The name of the Protocol Buffer message type to encode. | Required |
file | symbol | The path to a .proto file containing the message type definition. |
Required |
options:
name | type | description | default |
---|---|---|---|
format | string | A string definition of the Protocol Buffer message format to encode. | "" |
payloadType | symbol | Indicates the message payload that will be encoded (one of auto, table, dict, array, or arrays). | auto |
For all common arguments, refer to configuring operators
This operator encodes Protocol Buffer encoded messages from dictionaries or arrays of values.
Import paths
To import your .proto
file, the folder containing the .proto
file is added as an import
path. This means the folder will be scanned when importing future .proto
files, so it is
important that you avoid having .proto
files with the same filename present in import
paths you use.
Encode Protobuf messages using a Person.proto
file:
// Person.proto
syntax="proto3";
message Person {
string name = 1;
int32 id = 2;
string email = 3;
}
.qsp.run
.qsp.read.fromCallback[`publish]
.qsp.encode.protobuf[`Person;"Person.proto"]
.qsp.write.toConsole[];
publish `name`id`email!("name"; 101i; "email@email.com")
2021.11.10D12:01:49.089788900 | "\n\004name\020e\032\017email@email.com"
Encode Protobuf messages using format
from arrays:
format: "syntax=\"proto3\";
message Person {
string name = 1;
int32 id = 2;
string email = 3;
}";
.qsp.run
.qsp.read.fromCallback[`publish]
.qsp.decode.protobuf[.qsp.use `message`format!(`Person;format)]
.qsp.write.toConsole[];
publish ("name"; 101i; "email@email.com")
2021.11.10D12:01:49.089788900 | "\n\004name\020e\032\017email@email.com"