Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend bf utility to support multiple payloads #288

Closed
wants to merge 1 commit into from

Conversation

sapek
Copy link
Contributor

@sapek sapek commented Jan 3, 2017

The bf C++ example is a handy utility to work with files containing
arbitrary Bond payloads. This change extends it to support files with
more than one Bond payload.

The most obvious use case is files with a sequence of records (e.g.
logs). The less obvious but very powerful scenario is extracting some
kind of header that precedes the actual Bond payload of interest. This
is possible because a Bond schema in Simple Binary protocol can be used
to model many kinds of arbitrary headers (e.g. any fixed size header
aligned to octet boundary).

The change is backward compatible and existing command line arguments
retain their old semantics. In order to process multiple payloads user
can specified multiple --schema and/or multiple --from arguments,
e.g.:

bf --from=simple --schema=header.json,payload.json file

In the above example bf will first use Simple Binary to decode header
in schema specified in header.json and then will try to guess the
protocol of the next payload (since only one --from argument was
specified) and decode it using schema specified by the payload.json
file.

Multiple values for the --schema and --from arguments can be
specified either as comma delimited values (like in the example above)
or by passing the argument multiple times, e.g.:

bf --from=fast --from=fast file

Copy link
Member

@chwarr chwarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things that I think should be addressed before merging.

@@ -113,7 +113,7 @@ void TranscodeFromTo(Reader& reader, Writer& writer, const Options& options)
{
if (!options.schema.empty())
{
bond::SchemaDef schema(LoadSchema(options.schema));
bond::SchemaDef schema(LoadSchema(options.schema.front()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it handles an empty string like the old code used to.
Based on my reading and testing of boost::escaped_list_separator, which is used for the cmd arg parsing, it will return an empty string for the first item in an input like --schema=,second.schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

bf::Protocol from = options.from.empty() ? guess : options.from.front();

if (from == guess)
std::cerr << std::endl << "Guessed " << ToString(from = Guess(input)) << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put the from = Guess(input) on its own line so we don't mix interesting logic with diagnostic output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't changed from the previous version. But you are right, it is cleaner when separate.

if (!options.from.empty())
options.from.pop_front();
}
while (!options.schema.empty() || !options.from.empty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extension, if you're interested, would be to have a way to specify that the last from/schema pair should be used to continually transcode until EOF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea but let me think about interface for this separately...

The `bf` C++ example is a handy utility to work with files containing
arbitrary Bond payloads. This change extends it to support files with
more than one Bond payload.

The most obvious use case is files with a sequence of records (e.g.
logs). The less obvious but very powerful scenario is extracting some
kind of header that precedes the actual Bond payload of interest. This
is possible because a Bond schema in Simple Binary protocol can be used
to model many kinds of arbitrary headers (e.g. any fixed size header
aligned to octet boundary).

The change is backward compatible and existing command line arguments
retain their old semantics. In order to process multiple payloads user
can specified multiple `--schema` and/or multiple `--from` arguments,
e.g.:

    bf --from=simple --schema=header.json,payload.json file

In the above example `bf` will first use Simple Binary to decode header
in schema specified in `header.json` and then will try to guess the
protocol of the next payload (since only one `--from` argument was
specified) and decode it using schema specified by the `payload.json`
file.

Multiple values for the `--schema` and `--from` arguments can be
specified either as comma delimited values (like in the example above)
or by passing the argument multiple times, e.g.:

    bf --from=fast --from=fast file
@sapek
Copy link
Contributor Author

sapek commented Jan 7, 2017

@chwarr, make the changes you requested.

@chwarr chwarr closed this in 0d7b261 Jan 9, 2017
jdubrule pushed a commit to jdubrule/bond that referenced this pull request Jan 12, 2017
The `bf` C++ example is a handy utility to work with files containing
arbitrary Bond payloads. This change extends it to support files with
more than one Bond payload.

The most obvious use case is files with a sequence of records (e.g.
logs). The less obvious but very powerful scenario is extracting some
kind of header that precedes the actual Bond payload of interest. This
is possible because a Bond schema in Simple Binary protocol can be used
to model many kinds of arbitrary headers (e.g. any fixed size header
aligned to octet boundary).

The change is backward compatible and existing command line arguments
retain their old semantics. In order to process multiple payloads user
can specified multiple `--schema` and/or multiple `--from` arguments,
e.g.:

    bf --from=simple --schema=header.json,payload.json file

In the above example `bf` will first use Simple Binary to decode header
in schema specified in `header.json` and then will try to guess the
protocol of the next payload (since only one `--from` argument was
specified) and decode it using schema specified by the `payload.json`
file.

Multiple values for the `--schema` and `--from` arguments can be
specified either as comma delimited values (like in the example above)
or by passing the argument multiple times, e.g.:

    bf --from=fast --from=fast file

Closes microsoft#288
fuzhouch pushed a commit to fuzhouch/bond that referenced this pull request Apr 9, 2017
The `bf` C++ example is a handy utility to work with files containing
arbitrary Bond payloads. This change extends it to support files with
more than one Bond payload.

The most obvious use case is files with a sequence of records (e.g.
logs). The less obvious but very powerful scenario is extracting some
kind of header that precedes the actual Bond payload of interest. This
is possible because a Bond schema in Simple Binary protocol can be used
to model many kinds of arbitrary headers (e.g. any fixed size header
aligned to octet boundary).

The change is backward compatible and existing command line arguments
retain their old semantics. In order to process multiple payloads user
can specified multiple `--schema` and/or multiple `--from` arguments,
e.g.:

    bf --from=simple --schema=header.json,payload.json file

In the above example `bf` will first use Simple Binary to decode header
in schema specified in `header.json` and then will try to guess the
protocol of the next payload (since only one `--from` argument was
specified) and decode it using schema specified by the `payload.json`
file.

Multiple values for the `--schema` and `--from` arguments can be
specified either as comma delimited values (like in the example above)
or by passing the argument multiple times, e.g.:

    bf --from=fast --from=fast file

Closes microsoft#288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants