1
0
Fork 0

fix dumping of VPackSlices without CustomTypeHandler

This commit is contained in:
jsteemann 2016-08-26 10:51:54 +02:00
parent 83cc1a1d5a
commit 9ae2cb36e9
2 changed files with 22 additions and 5 deletions

View File

@ -38,7 +38,7 @@
using namespace arangodb;
// custom type value handler, used for deciphering the _id attribute
struct CustomTypeHandler : public VPackCustomTypeHandler {
struct CustomTypeHandler final : public VPackCustomTypeHandler {
CustomTypeHandler(TRI_vocbase_t* vocbase, CollectionNameResolver const* resolver)
: vocbase(vocbase), resolver(resolver) {}

View File

@ -47,13 +47,28 @@ unsigned long long XXH64(const void* input, size_t length,
unsigned long long seed);
}
using namespace arangodb;
using VelocyPackHelper = arangodb::basics::VelocyPackHelper;
static std::unique_ptr<VPackAttributeTranslator> Translator;
static std::unique_ptr<VPackAttributeExcludeHandler> ExcludeHandler;
static std::unique_ptr<VPackCustomTypeHandler> CustomTypeHandler;
// a default custom type handler that prevents throwing exceptions when
// custom types are encountered during Slice.toJson() and family
struct DefaultCustomTypeHandler final : public VPackCustomTypeHandler {
void dump(VPackSlice const&, VPackDumper* dumper, VPackSlice const&) override {
LOG(WARN) << "DefaultCustomTypeHandler called";
dumper->appendString("hello from CustomTypeHandler");
}
std::string toString(VPackSlice const&, VPackOptions const*, VPackSlice const&) override {
LOG(WARN) << "DefaultCustomTypeHandler called";
return "hello from CustomTypeHandler";
}
};
// attribute exclude handler for skipping over system attributes
struct SystemAttributeExcludeHandler : public VPackAttributeExcludeHandler {
struct SystemAttributeExcludeHandler final : public VPackAttributeExcludeHandler {
bool shouldExclude(VPackSlice const& key, int nesting) override final {
VPackValueLength keyLength;
char const* p = key.getString(keyLength);
@ -81,10 +96,7 @@ struct SystemAttributeExcludeHandler : public VPackAttributeExcludeHandler {
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief static initializer for all VPack values
////////////////////////////////////////////////////////////////////////////////
void VelocyPackHelper::initialize() {
LOG(TRACE) << "initializing vpack";
@ -104,6 +116,11 @@ void VelocyPackHelper::initialize() {
VPackOptions::Defaults.attributeTranslator = Translator.get();
VPackOptions::Defaults.unsupportedTypeBehavior =
VPackOptions::ConvertUnsupportedType;
CustomTypeHandler.reset(new DefaultCustomTypeHandler);
VPackOptions::Defaults.customTypeHandler = CustomTypeHandler.get();
VPackOptions::Defaults.escapeUnicode = false; // false here, but will be set
// when converting to JSON for
// HTTP xfer