Examples
These examples use the Parse operator.
Application with the blob type and block format that calls the Parse operator
The following application reads the blob type from a file by using the block format then calls the Parse operator to convert the data to tuples. Any operator that produces tuples with data in a blob type attribute can be used to feed Parse.
composite Main {
graph
stream<blob b> A = FileSource() {
param file : "in";
format : block;
blockSize : 1024u;
}
stream<rstring s, float64 d, rstring q> B = Parse (A) {
param format : txt;
}
}
() as Nul = FileSink (B) {
param file : "out.normal";
format : txt;
}
Application with the blob type and line format that calls the Parse operator
The following example shows the distinction between binary encoding and the binary format.
In ASCII encoding, the A character is represented as 65, the at symbol, @, is represented as 64, and the control character for the line feed format is represented as 10. The application encodes the line format in a binary form. So while the application is encoded in binary, that encoding is different from the bin format.
composite Main {
graph
stream<blob msg> Raw = Beacon() {
param iterations: 10u;
output Raw: msg=(blob)[65ub, 64ub, 10ub];
}
stream<rstring msg> Parsed = Parse(Raw) {
param format: line;
}
() as Writer = FileSink(Parsed) {
param file: "output.txt";
}
}
That application outputs the following data:
"A@"
"A@"
"A@"
"A@"
"A@"
"A@"
"A@"
"A@"
"A@"
"A@"
Application with the blob type and line format that calls the Format operator
By default the Format operator writes in the bin format, so the Parse operator on the other side must also read in the bin format. The FileSource and FileSink formats must match each other as well.
The following Format application produces output for a Parse application:
composite FormatTest {
graph
stream<rstring s, float64 d, rstring q> A = Beacon() {
param iterations: 100u;
output A: s="hi", q="ho", d=(float64)IterationCount();
}
stream<blob b, rstring inputData> B = Format(A) {
param suppress: s;
output B: b=Output(), inputData=s;
}
stream<blob b> JustBlob = Functor(B) {
output JustBlob: b=b;
}
() as Nul = FileSink(JustBlob){
param file: "out";
format: txt;
}
}
The following application is the Parse application that consumes the output of the Format application:
composite ParseTest {
graph
stream<blob b> Raw = FileSource() {
param file: "out";
format: txt;
}
stream<float64 d, rstring q> Recovered = Parse(Raw) {}
() as Sink = FileSink(Recovered){
param file: "recovered.txt";
format: txt;
}
}
The last 10 lines of the recovered.txt file, which is produced by the ParseTest application, shows:
{d=90,q="ho"}
{d=91,q="ho"}
{d=92,q="ho"}
{d=93,q="ho"}
{d=94,q="ho"}
{d=95,q="ho"}
{d=96,q="ho"}
{d=97,q="ho"}
{d=98,q="ho"}
{d=99,q="ho"}