(argv)
| 12 | |
| 13 | |
| 14 | def main(argv): |
| 15 | parser = argparse.ArgumentParser(description=("Converts from .pdl to .json by invoking the pdl Python module.")) |
| 16 | parser.add_argument( |
| 17 | "--map_binary_to_string", |
| 18 | type=bool, |
| 19 | help=( |
| 20 | "If set, binary in the .pdl is mapped to a " |
| 21 | "string in .json. Client code will have to " |
| 22 | "base64 decode the string to get the payload." |
| 23 | ), |
| 24 | ) |
| 25 | parser.add_argument("pdl_file", help="The .pdl input file to parse.") |
| 26 | parser.add_argument("json_file", help="The .json output file write.") |
| 27 | args = parser.parse_args(argv) |
| 28 | file_name = os.path.normpath(args.pdl_file) |
| 29 | with open(file_name) as input_file: |
| 30 | pdl_string = input_file.read() |
| 31 | |
| 32 | protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string) |
| 33 | |
| 34 | with open(os.path.normpath(args.json_file), "w") as output_file: |
| 35 | json.dump(protocol, output_file, indent=4, separators=(",", ": ")) |
| 36 | |
| 37 | |
| 38 | if __name__ == "__main__": |
no test coverage detected