Compare commits
No commits in common. "main" and "detached" have entirely different histories.
1 changed files with 4 additions and 67 deletions
|
@ -29,14 +29,13 @@
|
|||
|
||||
namespace file_reader
|
||||
{
|
||||
template <typename T>
|
||||
struct parsing_buffer
|
||||
{
|
||||
parsing_buffer(buffer<T> &b)
|
||||
parsing_buffer(buffer<char> &b)
|
||||
:buf(b)
|
||||
{}
|
||||
buffer<T> &buf;
|
||||
T *point;
|
||||
buffer<char> &buf;
|
||||
char *point;
|
||||
int consumed_size;
|
||||
};
|
||||
|
||||
|
@ -62,28 +61,6 @@ namespace file_reader
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void read_type(T& val, unsigned char *data)
|
||||
{
|
||||
std::memcpy(&val, data, sizeof(T));
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
val = be16toh(val);
|
||||
break;
|
||||
case 4:
|
||||
val = be32toh(val);
|
||||
break;
|
||||
case 8:
|
||||
val = be64toh(val);
|
||||
break;
|
||||
default:
|
||||
std::println("This integer is not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void read_type<float>(float &val, char *data)
|
||||
{
|
||||
|
@ -94,16 +71,6 @@ namespace file_reader
|
|||
memcpy(&val, &num_as_uint32, sizeof(float));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void read_type<float>(float &val, unsigned char *data)
|
||||
{
|
||||
uint32_t num_as_uint32;
|
||||
|
||||
memcpy(&num_as_uint32, data, sizeof(float));
|
||||
num_as_uint32 = be32toh(num_as_uint32);
|
||||
memcpy(&val, &num_as_uint32, sizeof(float));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void read_type<double>(double &val, char *data)
|
||||
{
|
||||
|
@ -114,16 +81,6 @@ namespace file_reader
|
|||
memcpy(&val, &num_as_uint64, sizeof(double));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void read_type<double>(double &val, unsigned char *data)
|
||||
{
|
||||
uint64_t num_as_uint64;
|
||||
|
||||
memcpy(&num_as_uint64, data, sizeof(double));
|
||||
num_as_uint64 = be64toh(num_as_uint64);
|
||||
memcpy(&val, &num_as_uint64, sizeof(double));
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void read_type<buffer<char>>(buffer<char> &val, char *data)
|
||||
{
|
||||
|
@ -135,7 +92,7 @@ namespace file_reader
|
|||
template<typename T>
|
||||
struct read_var
|
||||
{
|
||||
static void call(T& val, parsing_buffer<char> * v)
|
||||
static void call(T& val, parsing_buffer* v)
|
||||
{
|
||||
int size = 0;
|
||||
if constexpr (typeid(T) == typeid(buffer<char>))
|
||||
|
@ -155,26 +112,6 @@ namespace file_reader
|
|||
v->point += size;
|
||||
v->consumed_size += size;
|
||||
}
|
||||
static void call(T& val, parsing_buffer<unsigned char> * v)
|
||||
{
|
||||
int size = 0;
|
||||
if constexpr (typeid(T) == typeid(buffer<unsigned char>))
|
||||
size = val.size;
|
||||
else
|
||||
size = sizeof(T);
|
||||
if (size + v->consumed_size > v->buf.size)
|
||||
{
|
||||
if constexpr (typeid(T) == typeid(buffer<unsigned char>))
|
||||
{
|
||||
val.size = v->buf.size;
|
||||
}
|
||||
else
|
||||
return ;
|
||||
}
|
||||
read_type<T>(val, v->point);
|
||||
v->point += size;
|
||||
v->consumed_size += size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue