More refactoring.

Change-Id: Iaf937feb0486d2f008a47584c0a75edccbde2b34
This commit is contained in:
Peter Johnson
2015-06-21 22:03:51 -07:00
parent c4d4679ed9
commit b88a9295bf
6 changed files with 54 additions and 25 deletions

View File

@@ -17,6 +17,21 @@
using namespace NtImpl;
static double
read_double(char* &buf)
{
std::uint64_t val = (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf; val <<= 8; val |= (*((unsigned char *)buf)) & 0xff;
++buf;
return *reinterpret_cast<double*>(&val);
}
WireDecoder::WireDecoder(raw_istream& is, unsigned int proto_rev)
: m_is(is)
{
@@ -31,6 +46,15 @@ WireDecoder::~WireDecoder()
std::free(m_buf);
}
bool
WireDecoder::ReadDouble(double *val)
{
char *buf;
if (!Read(&buf, 8)) return false;
*val = read_double(buf);
return true;
}
void
WireDecoder::Realloc(std::size_t len)
{
@@ -124,7 +148,7 @@ WireDecoder::ReadValue(NT_Type type, NT_Value *value)
value->data.arr_double.arr =
(double *)std::malloc(size * sizeof(double));
for (unsigned int i=0; i<size; ++i)
value->data.arr_double.arr[i] = NtImpl::ReadDouble(buf);
value->data.arr_double.arr[i] = read_double(buf);
break;
}
case NT_STRING_ARRAY: