-
Notifications
You must be signed in to change notification settings - Fork 325
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
Conversation
There was a problem hiding this 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())); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@chwarr, make the changes you requested. |
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
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
The
bf
C++ example is a handy utility to work with files containingarbitrary 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.:
In the above example
bf
will first use Simple Binary to decode headerin schema specified in
header.json
and then will try to guess theprotocol of the next payload (since only one
--from
argument wasspecified) and decode it using schema specified by the
payload.json
file.
Multiple values for the
--schema
and--from
arguments can bespecified either as comma delimited values (like in the example above)
or by passing the argument multiple times, e.g.: