decoding hat some strange error
This commit is contained in:
parent
a3715c45ef
commit
d018473288
|
@ -395,7 +395,9 @@ public:
|
|||
|
||||
Reader asReader() { return Reader{message}; }
|
||||
|
||||
void set(const std::string &str) { message.container.set(str); }
|
||||
void set(std::string &&str) { message.container.set(std::move(str)); }
|
||||
void set(const std::string_view str) { message.container.set(str); }
|
||||
void set(const char *str) { set(std::string_view{str}); }
|
||||
};
|
||||
|
||||
class Reader {
|
||||
|
|
|
@ -214,12 +214,15 @@ template <> class MessageContainer<schema::String> {
|
|||
public:
|
||||
using SchemaType = schema::String;
|
||||
using ValueType = std::string;
|
||||
using ValueViewType = std::string_view;
|
||||
|
||||
private:
|
||||
ValueType value;
|
||||
|
||||
public:
|
||||
void set(ValueType &&v) { value = std::move(v); }
|
||||
void set(const ValueType &v) { value = v; }
|
||||
void set(const ValueViewType v) { value = std::string{v}; }
|
||||
|
||||
const ValueType &get() const { return value; }
|
||||
};
|
||||
|
|
|
@ -487,7 +487,12 @@ Error ProtoKelCodec::decode(
|
|||
}
|
||||
|
||||
if (packet_length > limits.packet_size) {
|
||||
return criticalError("Packet size too big");
|
||||
return criticalError(
|
||||
[packet_length]() {
|
||||
return std::string{"Packet size too big: "} +
|
||||
std::to_string(packet_length);
|
||||
},
|
||||
"Packet size too big");
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace gin {
|
||||
/**
|
||||
* Helper class to encode/decode any primtive type into/from litte endian.
|
||||
|
@ -40,7 +42,7 @@ public:
|
|||
uint16_t raw = 0;
|
||||
|
||||
for (size_t i = 0; i < sizeof(T); ++i) {
|
||||
raw |= buffer.read(i) << (i * 8);
|
||||
raw |= (static_cast<uint16_t>(buffer.read(i)) << (i * 8));
|
||||
}
|
||||
memcpy(&val, &raw, sizeof(T));
|
||||
buffer.readAdvance(sizeof(T));
|
||||
|
@ -78,7 +80,7 @@ public:
|
|||
uint32_t raw = 0;
|
||||
|
||||
for (size_t i = 0; i < sizeof(T); ++i) {
|
||||
raw |= buffer.read(i) << (i * 8);
|
||||
raw |= (static_cast<uint32_t>(buffer.read(i)) << (i * 8));
|
||||
}
|
||||
memcpy(&val, &raw, sizeof(T));
|
||||
buffer.readAdvance(sizeof(T));
|
||||
|
@ -116,8 +118,9 @@ public:
|
|||
uint64_t raw = 0;
|
||||
|
||||
for (size_t i = 0; i < sizeof(T); ++i) {
|
||||
raw |= buffer.read(i) << (i * 8);
|
||||
raw |= (static_cast<uint64_t>(buffer.read(i)) << (i * 8));
|
||||
}
|
||||
|
||||
memcpy(&val, &raw, sizeof(T));
|
||||
buffer.readAdvance(sizeof(T));
|
||||
|
||||
|
@ -146,4 +149,4 @@ public:
|
|||
|
||||
template <typename T> using StreamValue = ShiftStreamValue<T>;
|
||||
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
Loading…
Reference in New Issue