1
0
Fork 0
arangodb/arangod/Pregel/MessageFormat.h

72 lines
2.1 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2016 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Simon Grätzer
////////////////////////////////////////////////////////////////////////////////
#include <cstddef>
#include "Basics/Common.h"
#include <velocypack/Builder.h>
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
#ifndef ARANGODB_PREGEL_MFORMAT_H
#define ARANGODB_PREGEL_MFORMAT_H 1
namespace arangodb {
namespace pregel {
template <typename M>
struct MessageFormat {
virtual ~MessageFormat() {}
virtual bool unwrapValue(VPackSlice body, M& value) const = 0;
virtual void addValue(VPackBuilder& arrayBuilder, M const& val) const = 0;
};
struct IntegerMessageFormat : public MessageFormat<int64_t> {
IntegerMessageFormat() {}
bool unwrapValue(VPackSlice s, int64_t& value) const override {
if (s.isInteger()) {
value = s.getInt();
return true;
}
return false;
}
void addValue(VPackBuilder& arrayBuilder, int64_t const& val) const override {
arrayBuilder.add(VPackValue(val));
}
};
struct FloatMessageFormat : public MessageFormat<float> {
FloatMessageFormat() {}
bool unwrapValue(VPackSlice s, float& value) const override {
if (s.isDouble()) {
value = s.getDouble();
return true;
}
return false;
}
void addValue(VPackBuilder& arrayBuilder, float const& val) const override {
arrayBuilder.add(VPackValue(val));
}
};
}
}
#endif