mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
More refactoring.
Change-Id: Iaf937feb0486d2f008a47584c0a75edccbde2b34
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user