mirror of
https://github.com/corda/corda.git
synced 2025-06-14 05:08:18 +00:00
NOTICK: Add BlobWriter and Schema Dumper
The Blob Writer is a small kotlin app that allows arbitrary things to be serialized and then those bytes written to a file, quite useful for working on non JVM parsing of such things. Along a similar vein, add a schema dumper alongside the blob-inspector to highlight the contents of the header
This commit is contained in:
1
experimental/cpp-serializer/bin/blob-inspector/.gitignore
vendored
Normal file
1
experimental/cpp-serializer/bin/blob-inspector/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
blob-inspector
|
@ -0,0 +1,9 @@
|
||||
include_directories (${BLOB-INSPECTOR_SOURCE_DIR}/src)
|
||||
include_directories (${BLOB-INSPECTOR_SOURCE_DIR}/src/amqp)
|
||||
|
||||
link_directories (${BLOB-INSPECTOR_BINARY_DIR}/src/amqp)
|
||||
link_directories (${BLOB-INSPECTOR_BINARY_DIR}/src/proton)
|
||||
|
||||
add_executable (blob-inspector main)
|
||||
|
||||
target_link_libraries (blob-inspector amqp proton qpid-proton)
|
115
experimental/cpp-serializer/bin/blob-inspector/main.cxx
Normal file
115
experimental/cpp-serializer/bin/blob-inspector/main.cxx
Normal file
@ -0,0 +1,115 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <cstddef>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <proton/types.h>
|
||||
#include <proton/codec.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#import "debug.h"
|
||||
|
||||
#include "proton/proton_wrapper.h"
|
||||
|
||||
#include "amqp/AMQPHeader.h"
|
||||
#include "amqp/AMQPSectionId.h"
|
||||
#include "amqp/descriptors/AMQPDescriptorRegistory.h"
|
||||
|
||||
#include "amqp/schema/Envelope.h"
|
||||
#include "amqp/CompositeFactory.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void
|
||||
data_and_stop(std::ifstream & f_, ssize_t sz) {
|
||||
char * blob = new char[sz];
|
||||
memset (blob, 0, sz);
|
||||
f_.read(blob, sz);
|
||||
|
||||
pn_data_t * d = pn_data(sz);
|
||||
|
||||
// returns how many bytes we processed which right now we don't care
|
||||
// about but I assume there is a case where it doesn't process the
|
||||
// entire file
|
||||
auto rtn = pn_data_decode (d, blob, sz);
|
||||
assert (rtn == sz);
|
||||
|
||||
std::unique_ptr<amqp::internal::schema::Envelope> envelope;
|
||||
|
||||
if (pn_data_is_described(d)) {
|
||||
proton::auto_enter p (d);
|
||||
|
||||
auto a = pn_data_get_ulong(d);
|
||||
|
||||
envelope.reset (
|
||||
dynamic_cast<amqp::internal::schema::Envelope *> (
|
||||
amqp::AMQPDescriptorRegistory[a]->build(d).release()));
|
||||
|
||||
DBG (std::cout << std::endl << "Types in schema: " << std::endl
|
||||
<< *envelope << std::endl); // NOLINT
|
||||
}
|
||||
|
||||
amqp::internal::CompositeFactory cf;
|
||||
|
||||
cf.process (envelope->schema());
|
||||
|
||||
auto reader = cf.byDescriptor (envelope->descriptor());
|
||||
assert (reader);
|
||||
|
||||
{
|
||||
// move to the actual blob entry in the tree - ideally we'd have
|
||||
// saved this on the Envelope but that's not easily doable as we
|
||||
// can't grab an actual copy of our data pointer
|
||||
proton::auto_enter p (d);
|
||||
pn_data_next (d);
|
||||
proton::is_list (d);
|
||||
assert (pn_data_get_list (d) == 3);
|
||||
{
|
||||
proton::auto_enter p (d);
|
||||
|
||||
// We wrap our output like this to make sure it's valid JSON to
|
||||
// facilitate easy pretty printing
|
||||
std::cout
|
||||
<< reader->dump ("{ Parsed", d, envelope->schema())->dump()
|
||||
<< " }" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
int
|
||||
main (int argc, char **argv) {
|
||||
struct stat results { };
|
||||
|
||||
if (stat(argv[1], &results) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::ifstream f (argv[1], std::ios::in | std::ios::binary);
|
||||
std::array<char, 7> header { };
|
||||
f.read(header.data(), 7);
|
||||
|
||||
if (header != amqp::AMQP_HEADER) {
|
||||
std::cerr << "Bad Header in blob" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
amqp::amqp_section_id_t encoding;
|
||||
f.read((char *)&encoding, 1);
|
||||
|
||||
if (encoding == amqp::DATA_AND_STOP) {
|
||||
data_and_stop(f, results.st_size - 8);
|
||||
} else {
|
||||
std::cerr << "BAD ENCODING " << encoding << " != "
|
||||
<< amqp::DATA_AND_STOP << std::endl;
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
BIN
experimental/cpp-serializer/bin/blob-inspector/test/IntList
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/IntList
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
experimental/cpp-serializer/bin/blob-inspector/test/OneComposite
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/OneComposite
Normal file
Binary file not shown.
Binary file not shown.
BIN
experimental/cpp-serializer/bin/blob-inspector/test/OneInt
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/OneInt
Normal file
Binary file not shown.
BIN
experimental/cpp-serializer/bin/blob-inspector/test/TwoIntLists
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/TwoIntLists
Normal file
Binary file not shown.
BIN
experimental/cpp-serializer/bin/blob-inspector/test/TwoInts
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/TwoInts
Normal file
Binary file not shown.
BIN
experimental/cpp-serializer/bin/blob-inspector/test/manyTypes
Normal file
BIN
experimental/cpp-serializer/bin/blob-inspector/test/manyTypes
Normal file
Binary file not shown.
Reference in New Issue
Block a user