Clean utils folder
Summary: The goal is to standardize utils folder. Reviewers: teon.banek, mferencevic Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1354
This commit is contained in:
parent
4cbfc800b8
commit
20d667f8bf
@ -102,11 +102,11 @@ class Decoder {
|
|||||||
return ReadEdge(marker, data);
|
return ReadEdge(marker, data);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((value & 0xF0) == underlying_cast(Marker::TinyString)) {
|
if ((value & 0xF0) == utils::UnderlyingCast(Marker::TinyString)) {
|
||||||
return ReadString(marker, data);
|
return ReadString(marker, data);
|
||||||
} else if ((value & 0xF0) == underlying_cast(Marker::TinyList)) {
|
} else if ((value & 0xF0) == utils::UnderlyingCast(Marker::TinyList)) {
|
||||||
return ReadList(marker, data);
|
return ReadList(marker, data);
|
||||||
} else if ((value & 0xF0) == underlying_cast(Marker::TinyMap)) {
|
} else if ((value & 0xF0) == utils::UnderlyingCast(Marker::TinyMap)) {
|
||||||
return ReadMap(marker, data);
|
return ReadMap(marker, data);
|
||||||
} else {
|
} else {
|
||||||
return ReadInt(marker, data);
|
return ReadInt(marker, data);
|
||||||
@ -187,7 +187,7 @@ class Decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ReadInt(const Marker &marker, DecodedValue *data) {
|
bool ReadInt(const Marker &marker, DecodedValue *data) {
|
||||||
uint8_t value = underlying_cast(marker);
|
uint8_t value = utils::UnderlyingCast(marker);
|
||||||
int64_t ret;
|
int64_t ret;
|
||||||
VLOG(20) << "[ReadInt] Start";
|
VLOG(20) << "[ReadInt] Start";
|
||||||
if (value >= 240 || value <= 127) {
|
if (value >= 240 || value <= 127) {
|
||||||
@ -227,7 +227,7 @@ class Decoder {
|
|||||||
ret = bswap(ret);
|
ret = bswap(ret);
|
||||||
} else {
|
} else {
|
||||||
DLOG(WARNING) << "[ReadInt] Received invalid marker "
|
DLOG(WARNING) << "[ReadInt] Received invalid marker "
|
||||||
<< underlying_cast(marker);
|
<< utils::UnderlyingCast(marker);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*data = DecodedValue(ret);
|
*data = DecodedValue(ret);
|
||||||
@ -253,8 +253,8 @@ class Decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int64_t ReadTypeSize(const Marker &marker, const uint8_t type) {
|
int64_t ReadTypeSize(const Marker &marker, const uint8_t type) {
|
||||||
uint8_t value = underlying_cast(marker);
|
uint8_t value = utils::UnderlyingCast(marker);
|
||||||
if ((value & 0xF0) == underlying_cast(MarkerTiny[type])) {
|
if ((value & 0xF0) == utils::UnderlyingCast(MarkerTiny[type])) {
|
||||||
VLOG(20) << "[ReadTypeSize] Found a TinyType";
|
VLOG(20) << "[ReadTypeSize] Found a TinyType";
|
||||||
return value & 0x0F;
|
return value & 0x0F;
|
||||||
} else if (marker == Marker8[type]) {
|
} else if (marker == Marker8[type]) {
|
||||||
@ -285,7 +285,7 @@ class Decoder {
|
|||||||
return tmp;
|
return tmp;
|
||||||
} else {
|
} else {
|
||||||
DLOG(WARNING) << "[ReadTypeSize] Received invalid marker "
|
DLOG(WARNING) << "[ReadTypeSize] Received invalid marker "
|
||||||
<< underlying_cast(marker);
|
<< utils::UnderlyingCast(marker);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,10 +423,10 @@ class Decoder {
|
|||||||
// check header
|
// check header
|
||||||
if (marker != Marker::TinyStruct5) {
|
if (marker != Marker::TinyStruct5) {
|
||||||
DLOG(WARNING) << "[ReadEdge] Received invalid marker "
|
DLOG(WARNING) << "[ReadEdge] Received invalid marker "
|
||||||
<< (uint64_t)underlying_cast(marker);
|
<< (uint64_t)utils::UnderlyingCast(marker);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (value != underlying_cast(Signature::Relationship)) {
|
if (value != utils::UnderlyingCast(Signature::Relationship)) {
|
||||||
DLOG(WARNING) << "[ReadEdge] Received invalid signature " << value;
|
DLOG(WARNING) << "[ReadEdge] Received invalid signature " << value;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteVertex(const VertexAccessor &vertex) {
|
void WriteVertex(const VertexAccessor &vertex) {
|
||||||
this->WriteRAW(underlying_cast(Marker::TinyStruct) + 3);
|
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) + 3);
|
||||||
this->WriteRAW(underlying_cast(Signature::Node));
|
this->WriteRAW(utils::UnderlyingCast(Signature::Node));
|
||||||
WriteUInt(vertex.gid());
|
WriteUInt(vertex.gid());
|
||||||
|
|
||||||
// write labels
|
// write labels
|
||||||
@ -58,9 +58,10 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteEdge(const EdgeAccessor &edge, bool unbound = false) {
|
void WriteEdge(const EdgeAccessor &edge, bool unbound = false) {
|
||||||
this->WriteRAW(underlying_cast(Marker::TinyStruct) + (unbound ? 3 : 5));
|
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) +
|
||||||
this->WriteRAW(underlying_cast(unbound ? Signature::UnboundRelationship
|
(unbound ? 3 : 5));
|
||||||
: Signature::Relationship));
|
this->WriteRAW(utils::UnderlyingCast(
|
||||||
|
unbound ? Signature::UnboundRelationship : Signature::Relationship));
|
||||||
|
|
||||||
WriteUInt(edge.gid());
|
WriteUInt(edge.gid());
|
||||||
if (!unbound) {
|
if (!unbound) {
|
||||||
@ -113,8 +114,8 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write data.
|
// Write data.
|
||||||
this->WriteRAW(underlying_cast(Marker::TinyStruct) + 3);
|
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) + 3);
|
||||||
this->WriteRAW(underlying_cast(Signature::Path));
|
this->WriteRAW(utils::UnderlyingCast(Signature::Path));
|
||||||
this->WriteTypeSize(vertices.size(), MarkerList);
|
this->WriteTypeSize(vertices.size(), MarkerList);
|
||||||
for (auto &v : vertices) WriteVertex(v);
|
for (auto &v : vertices) WriteVertex(v);
|
||||||
this->WriteTypeSize(edges.size(), MarkerList);
|
this->WriteTypeSize(edges.size(), MarkerList);
|
||||||
|
@ -40,8 +40,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
*/
|
*/
|
||||||
bool MessageInit(const std::string client_name,
|
bool MessageInit(const std::string client_name,
|
||||||
const std::map<std::string, query::TypedValue> &auth_token) {
|
const std::map<std::string, query::TypedValue> &auth_token) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct2));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct2));
|
||||||
WriteRAW(underlying_cast(Signature::Init));
|
WriteRAW(utils::UnderlyingCast(Signature::Init));
|
||||||
WriteString(client_name);
|
WriteString(client_name);
|
||||||
WriteMap(auth_token);
|
WriteMap(auth_token);
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
@ -64,8 +64,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
bool MessageRun(const std::string statement,
|
bool MessageRun(const std::string statement,
|
||||||
const std::map<std::string, query::TypedValue> ¶meters,
|
const std::map<std::string, query::TypedValue> ¶meters,
|
||||||
bool flush = true) {
|
bool flush = true) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct2));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct2));
|
||||||
WriteRAW(underlying_cast(Signature::Run));
|
WriteRAW(utils::UnderlyingCast(Signature::Run));
|
||||||
WriteString(statement);
|
WriteString(statement);
|
||||||
WriteMap(parameters);
|
WriteMap(parameters);
|
||||||
if (flush) {
|
if (flush) {
|
||||||
@ -88,8 +88,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
* when flushing, false otherwise
|
* when flushing, false otherwise
|
||||||
*/
|
*/
|
||||||
bool MessageDiscardAll() {
|
bool MessageDiscardAll() {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct));
|
||||||
WriteRAW(underlying_cast(Signature::DiscardAll));
|
WriteRAW(utils::UnderlyingCast(Signature::DiscardAll));
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +104,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
* when flushing, false otherwise
|
* when flushing, false otherwise
|
||||||
*/
|
*/
|
||||||
bool MessagePullAll() {
|
bool MessagePullAll() {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct));
|
||||||
WriteRAW(underlying_cast(Signature::PullAll));
|
WriteRAW(utils::UnderlyingCast(Signature::PullAll));
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +120,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
* when flushing, false otherwise
|
* when flushing, false otherwise
|
||||||
*/
|
*/
|
||||||
bool MessageAckFailure() {
|
bool MessageAckFailure() {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct));
|
||||||
WriteRAW(underlying_cast(Signature::AckFailure));
|
WriteRAW(utils::UnderlyingCast(Signature::AckFailure));
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +136,8 @@ class ClientEncoder : private BaseEncoder<Buffer> {
|
|||||||
* when flushing, false otherwise
|
* when flushing, false otherwise
|
||||||
*/
|
*/
|
||||||
bool MessageReset() {
|
bool MessageReset() {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct));
|
||||||
WriteRAW(underlying_cast(Signature::Reset));
|
WriteRAW(utils::UnderlyingCast(Signature::Reset));
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -37,8 +37,8 @@ class Encoder : private BaseEncoder<Buffer> {
|
|||||||
* @param values the fields list object that should be sent
|
* @param values the fields list object that should be sent
|
||||||
*/
|
*/
|
||||||
void MessageRecord(const std::vector<query::TypedValue> &values) {
|
void MessageRecord(const std::vector<query::TypedValue> &values) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct1));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
|
||||||
WriteRAW(underlying_cast(Signature::Record));
|
WriteRAW(utils::UnderlyingCast(Signature::Record));
|
||||||
WriteList(values);
|
WriteList(values);
|
||||||
buffer_.Chunk();
|
buffer_.Chunk();
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ class Encoder : private BaseEncoder<Buffer> {
|
|||||||
*/
|
*/
|
||||||
bool MessageSuccess(const std::map<std::string, query::TypedValue> &metadata,
|
bool MessageSuccess(const std::map<std::string, query::TypedValue> &metadata,
|
||||||
bool flush = true) {
|
bool flush = true) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct1));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
|
||||||
WriteRAW(underlying_cast(Signature::Success));
|
WriteRAW(utils::UnderlyingCast(Signature::Success));
|
||||||
WriteMap(metadata);
|
WriteMap(metadata);
|
||||||
if (flush) {
|
if (flush) {
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
@ -97,8 +97,8 @@ class Encoder : private BaseEncoder<Buffer> {
|
|||||||
*/
|
*/
|
||||||
bool MessageFailure(
|
bool MessageFailure(
|
||||||
const std::map<std::string, query::TypedValue> &metadata) {
|
const std::map<std::string, query::TypedValue> &metadata) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct1));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
|
||||||
WriteRAW(underlying_cast(Signature::Failure));
|
WriteRAW(utils::UnderlyingCast(Signature::Failure));
|
||||||
WriteMap(metadata);
|
WriteMap(metadata);
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
@ -117,8 +117,8 @@ class Encoder : private BaseEncoder<Buffer> {
|
|||||||
*/
|
*/
|
||||||
bool MessageIgnored(
|
bool MessageIgnored(
|
||||||
const std::map<std::string, query::TypedValue> &metadata) {
|
const std::map<std::string, query::TypedValue> &metadata) {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct1));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
|
||||||
WriteRAW(underlying_cast(Signature::Ignored));
|
WriteRAW(utils::UnderlyingCast(Signature::Ignored));
|
||||||
WriteMap(metadata);
|
WriteMap(metadata);
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
@ -132,8 +132,8 @@ class Encoder : private BaseEncoder<Buffer> {
|
|||||||
* false otherwise
|
* false otherwise
|
||||||
*/
|
*/
|
||||||
bool MessageIgnored() {
|
bool MessageIgnored() {
|
||||||
WriteRAW(underlying_cast(Marker::TinyStruct));
|
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct));
|
||||||
WriteRAW(underlying_cast(Signature::Ignored));
|
WriteRAW(utils::UnderlyingCast(Signature::Ignored));
|
||||||
return buffer_.Flush();
|
return buffer_.Flush();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -36,35 +36,35 @@ class PrimitiveEncoder {
|
|||||||
WriteRAW(reinterpret_cast<const uint8_t *>(&value), sizeof(value));
|
WriteRAW(reinterpret_cast<const uint8_t *>(&value), sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteNull() { WriteRAW(underlying_cast(Marker::Null)); }
|
void WriteNull() { WriteRAW(utils::UnderlyingCast(Marker::Null)); }
|
||||||
|
|
||||||
void WriteBool(const bool &value) {
|
void WriteBool(const bool &value) {
|
||||||
if (value)
|
if (value)
|
||||||
WriteRAW(underlying_cast(Marker::True));
|
WriteRAW(utils::UnderlyingCast(Marker::True));
|
||||||
else
|
else
|
||||||
WriteRAW(underlying_cast(Marker::False));
|
WriteRAW(utils::UnderlyingCast(Marker::False));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteInt(const int64_t &value) {
|
void WriteInt(const int64_t &value) {
|
||||||
if (value >= -16L && value < 128L) {
|
if (value >= -16L && value < 128L) {
|
||||||
WriteRAW(static_cast<uint8_t>(value));
|
WriteRAW(static_cast<uint8_t>(value));
|
||||||
} else if (value >= -128L && value < -16L) {
|
} else if (value >= -128L && value < -16L) {
|
||||||
WriteRAW(underlying_cast(Marker::Int8));
|
WriteRAW(utils::UnderlyingCast(Marker::Int8));
|
||||||
WriteRAW(static_cast<uint8_t>(value));
|
WriteRAW(static_cast<uint8_t>(value));
|
||||||
} else if (value >= -32768L && value < 32768L) {
|
} else if (value >= -32768L && value < 32768L) {
|
||||||
WriteRAW(underlying_cast(Marker::Int16));
|
WriteRAW(utils::UnderlyingCast(Marker::Int16));
|
||||||
WriteValue(static_cast<int16_t>(value));
|
WriteValue(static_cast<int16_t>(value));
|
||||||
} else if (value >= -2147483648L && value < 2147483648L) {
|
} else if (value >= -2147483648L && value < 2147483648L) {
|
||||||
WriteRAW(underlying_cast(Marker::Int32));
|
WriteRAW(utils::UnderlyingCast(Marker::Int32));
|
||||||
WriteValue(static_cast<int32_t>(value));
|
WriteValue(static_cast<int32_t>(value));
|
||||||
} else {
|
} else {
|
||||||
WriteRAW(underlying_cast(Marker::Int64));
|
WriteRAW(utils::UnderlyingCast(Marker::Int64));
|
||||||
WriteValue(value);
|
WriteValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteDouble(const double &value) {
|
void WriteDouble(const double &value) {
|
||||||
WriteRAW(underlying_cast(Marker::Float64));
|
WriteRAW(utils::UnderlyingCast(Marker::Float64));
|
||||||
WriteValue(*reinterpret_cast<const int64_t *>(&value));
|
WriteValue(*reinterpret_cast<const int64_t *>(&value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,18 +72,18 @@ class PrimitiveEncoder {
|
|||||||
if (size <= 15) {
|
if (size <= 15) {
|
||||||
uint8_t len = size;
|
uint8_t len = size;
|
||||||
len &= 0x0F;
|
len &= 0x0F;
|
||||||
WriteRAW(underlying_cast(MarkerTiny[typ]) + len);
|
WriteRAW(utils::UnderlyingCast(MarkerTiny[typ]) + len);
|
||||||
} else if (size <= 255) {
|
} else if (size <= 255) {
|
||||||
uint8_t len = size;
|
uint8_t len = size;
|
||||||
WriteRAW(underlying_cast(Marker8[typ]));
|
WriteRAW(utils::UnderlyingCast(Marker8[typ]));
|
||||||
WriteRAW(len);
|
WriteRAW(len);
|
||||||
} else if (size <= 65535) {
|
} else if (size <= 65535) {
|
||||||
uint16_t len = size;
|
uint16_t len = size;
|
||||||
WriteRAW(underlying_cast(Marker16[typ]));
|
WriteRAW(utils::UnderlyingCast(Marker16[typ]));
|
||||||
WriteValue(len);
|
WriteValue(len);
|
||||||
} else {
|
} else {
|
||||||
uint32_t len = size;
|
uint32_t len = size;
|
||||||
WriteRAW(underlying_cast(Marker32[typ]));
|
WriteRAW(utils::UnderlyingCast(Marker32[typ]));
|
||||||
WriteValue(len);
|
WriteValue(len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ State StateErrorRun(TSession &session, State state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DLOG(INFO) << fmt::format("Message signature is: 0x{:02X}",
|
DLOG(INFO) << fmt::format("Message signature is: 0x{:02X}",
|
||||||
underlying_cast(signature));
|
utils::UnderlyingCast(signature));
|
||||||
|
|
||||||
// Clear the data buffer if it has any leftover data.
|
// Clear the data buffer if it has any leftover data.
|
||||||
session.encoder_buffer_.Clear();
|
session.encoder_buffer_.Clear();
|
||||||
@ -58,11 +58,11 @@ State StateErrorRun(TSession &session, State state) {
|
|||||||
LOG(FATAL) << "Shouldn't happen";
|
LOG(FATAL) << "Shouldn't happen";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t value = underlying_cast(marker);
|
uint8_t value = utils::UnderlyingCast(marker);
|
||||||
|
|
||||||
// All bolt client messages have less than 15 parameters so if we receive
|
// All bolt client messages have less than 15 parameters so if we receive
|
||||||
// anything than a TinyStruct it's an error.
|
// anything than a TinyStruct it's an error.
|
||||||
if ((value & 0xF0) != underlying_cast(Marker::TinyStruct)) {
|
if ((value & 0xF0) != utils::UnderlyingCast(Marker::TinyStruct)) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct marker, but received 0x{:02X}!", value);
|
"Expected TinyStruct marker, but received 0x{:02X}!", value);
|
||||||
return State::Close;
|
return State::Close;
|
||||||
|
@ -23,7 +23,7 @@ State HandleRun(TSession &session, State state, Marker marker) {
|
|||||||
if (marker != Marker::TinyStruct2) {
|
if (marker != Marker::TinyStruct2) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct2 marker, but received 0x{:02X}!",
|
"Expected TinyStruct2 marker, but received 0x{:02X}!",
|
||||||
underlying_cast(marker));
|
utils::UnderlyingCast(marker));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ State HandlePullAll(Session &session, State state, Marker marker) {
|
|||||||
if (marker != Marker::TinyStruct) {
|
if (marker != Marker::TinyStruct) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct marker, but received 0x{:02X}!",
|
"Expected TinyStruct marker, but received 0x{:02X}!",
|
||||||
underlying_cast(marker));
|
utils::UnderlyingCast(marker));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ State HandleDiscardAll(Session &session, State state, Marker marker) {
|
|||||||
if (marker != Marker::TinyStruct) {
|
if (marker != Marker::TinyStruct) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct marker, but received 0x{:02X}!",
|
"Expected TinyStruct marker, but received 0x{:02X}!",
|
||||||
underlying_cast(marker));
|
utils::UnderlyingCast(marker));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ State HandleReset(Session &session, State, Marker marker) {
|
|||||||
if (marker != Marker::TinyStruct) {
|
if (marker != Marker::TinyStruct) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct marker, but received 0x{:02X}!",
|
"Expected TinyStruct marker, but received 0x{:02X}!",
|
||||||
underlying_cast(marker));
|
utils::UnderlyingCast(marker));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
// clear all pending data and send a success message
|
// clear all pending data and send a success message
|
||||||
@ -313,7 +313,7 @@ State StateExecutingRun(Session &session, State state) {
|
|||||||
return HandleReset(session, state, marker);
|
return HandleReset(session, state, marker);
|
||||||
} else {
|
} else {
|
||||||
DLOG(WARNING) << fmt::format("Unrecognized signature recieved (0x{:02X})!",
|
DLOG(WARNING) << fmt::format("Unrecognized signature recieved (0x{:02X})!",
|
||||||
underlying_cast(signature));
|
utils::UnderlyingCast(signature));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,13 @@ State StateInitRun(Session &session) {
|
|||||||
if (UNLIKELY(signature != Signature::Init)) {
|
if (UNLIKELY(signature != Signature::Init)) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected Init signature, but received 0x{:02X}!",
|
"Expected Init signature, but received 0x{:02X}!",
|
||||||
underlying_cast(signature));
|
utils::UnderlyingCast(signature));
|
||||||
return State::Close;
|
return State::Close;
|
||||||
}
|
}
|
||||||
if (UNLIKELY(marker != Marker::TinyStruct2)) {
|
if (UNLIKELY(marker != Marker::TinyStruct2)) {
|
||||||
DLOG(WARNING) << fmt::format(
|
DLOG(WARNING) << fmt::format(
|
||||||
"Expected TinyStruct2 marker, but received 0x{:02X}!",
|
"Expected TinyStruct2 marker, but received 0x{:02X}!",
|
||||||
underlying_cast(marker));
|
utils::UnderlyingCast(marker));
|
||||||
DLOG(WARNING) << "The client sent malformed data, but we are continuing "
|
DLOG(WARNING) << "The client sent malformed data, but we are continuing "
|
||||||
"because the official Neo4j Java driver sends malformed "
|
"because the official Neo4j Java driver sends malformed "
|
||||||
"data. D'oh!";
|
"data. D'oh!";
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr typename std::underlying_type<T>::type underlying_cast(T e) {
|
constexpr typename std::underlying_type<T>::type UnderlyingCast(T e) {
|
||||||
return static_cast<typename std::underlying_type<T>::type>(e);
|
return static_cast<typename std::underlying_type<T>::type>(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
@ -59,9 +59,10 @@ class SnapshotWriter {
|
|||||||
|
|
||||||
void WriteNode(const Node &node,
|
void WriteNode(const Node &node,
|
||||||
const std::unordered_map<gid::Gid, Edge> &edges) {
|
const std::unordered_map<gid::Gid, Edge> &edges) {
|
||||||
encoder_.WriteRAW(underlying_cast(communication::bolt::Marker::TinyStruct) +
|
encoder_.WriteRAW(
|
||||||
3);
|
utils::UnderlyingCast(communication::bolt::Marker::TinyStruct) + 3);
|
||||||
encoder_.WriteRAW(underlying_cast(communication::bolt::Signature::Node));
|
encoder_.WriteRAW(
|
||||||
|
utils::UnderlyingCast(communication::bolt::Signature::Node));
|
||||||
encoder_.WriteInt(node.gid);
|
encoder_.WriteInt(node.gid);
|
||||||
|
|
||||||
WriteList(node.labels);
|
WriteList(node.labels);
|
||||||
@ -81,10 +82,10 @@ class SnapshotWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteEdge(const Edge &edge) {
|
void WriteEdge(const Edge &edge) {
|
||||||
encoder_.WriteRAW(underlying_cast(communication::bolt::Marker::TinyStruct) +
|
|
||||||
5);
|
|
||||||
encoder_.WriteRAW(
|
encoder_.WriteRAW(
|
||||||
underlying_cast(communication::bolt::Signature::Relationship));
|
utils::UnderlyingCast(communication::bolt::Marker::TinyStruct) + 5);
|
||||||
|
encoder_.WriteRAW(
|
||||||
|
utils::UnderlyingCast(communication::bolt::Signature::Relationship));
|
||||||
encoder_.WriteInt(edge.gid);
|
encoder_.WriteInt(edge.gid);
|
||||||
encoder_.WriteInt(edge.from);
|
encoder_.WriteInt(edge.from);
|
||||||
encoder_.WriteInt(edge.to);
|
encoder_.WriteInt(edge.to);
|
||||||
|
@ -390,8 +390,9 @@ void Convert(const std::vector<std::string> &nodes,
|
|||||||
auto &vertex = vertex_pair.second;
|
auto &vertex = vertex_pair.second;
|
||||||
// write node
|
// write node
|
||||||
encoder.WriteRAW(
|
encoder.WriteRAW(
|
||||||
underlying_cast(communication::bolt::Marker::TinyStruct) + 3);
|
utils::UnderlyingCast(communication::bolt::Marker::TinyStruct) + 3);
|
||||||
encoder.WriteRAW(underlying_cast(communication::bolt::Signature::Node));
|
encoder.WriteRAW(
|
||||||
|
utils::UnderlyingCast(communication::bolt::Signature::Node));
|
||||||
|
|
||||||
encoder.WriteInt(vertex.gid);
|
encoder.WriteInt(vertex.gid);
|
||||||
auto &labels = vertex.labels;
|
auto &labels = vertex.labels;
|
||||||
@ -420,9 +421,9 @@ void Convert(const std::vector<std::string> &nodes,
|
|||||||
auto &edge = edge_pair.second;
|
auto &edge = edge_pair.second;
|
||||||
// write relationship
|
// write relationship
|
||||||
encoder.WriteRAW(
|
encoder.WriteRAW(
|
||||||
underlying_cast(communication::bolt::Marker::TinyStruct) + 5);
|
utils::UnderlyingCast(communication::bolt::Marker::TinyStruct) + 5);
|
||||||
encoder.WriteRAW(
|
encoder.WriteRAW(
|
||||||
underlying_cast(communication::bolt::Signature::Relationship));
|
utils::UnderlyingCast(communication::bolt::Signature::Relationship));
|
||||||
encoder.WriteInt(edge.id);
|
encoder.WriteInt(edge.id);
|
||||||
encoder.WriteInt(edge.from);
|
encoder.WriteInt(edge.from);
|
||||||
encoder.WriteInt(edge.to);
|
encoder.WriteInt(edge.to);
|
||||||
|
Loading…
Reference in New Issue
Block a user