mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
WireDecoder::Read(): Use const char instead of plain char.
Change-Id: I14932ccd174b70fa3f90676c66ac0907e6086238 MessageReader: Use StringRef for callbacks.
This commit is contained in:
@@ -141,9 +141,9 @@ bool MessageReader::Run() {
|
||||
if (!Read16(&uid)) return false;
|
||||
unsigned long size;
|
||||
if (!ReadUleb128(&size)) return false;
|
||||
char* params;
|
||||
const char* params;
|
||||
if (!Read(¶ms, size)) return false;
|
||||
m_handler.GotExecuteRpc(id, uid, params, size);
|
||||
m_handler.GotExecuteRpc(id, uid, llvm::StringRef(params, size));
|
||||
break;
|
||||
}
|
||||
case NT_MSG_RPC_RESPONSE: {
|
||||
@@ -156,9 +156,9 @@ bool MessageReader::Run() {
|
||||
if (!Read16(&uid)) return false;
|
||||
unsigned long size;
|
||||
if (!ReadUleb128(&size)) return false;
|
||||
char* results;
|
||||
const char* results;
|
||||
if (!Read(&results, size)) return false;
|
||||
m_handler.GotRpcResponse(id, uid, results, size);
|
||||
m_handler.GotRpcResponse(id, uid, llvm::StringRef(results, size));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -37,9 +37,9 @@ class MessageHandler {
|
||||
virtual void GotEntryDelete(unsigned int id) = 0;
|
||||
virtual void GotClearEntries() = 0;
|
||||
virtual void GotExecuteRpc(unsigned int id, unsigned int uid,
|
||||
const char* params, std::size_t params_len) = 0;
|
||||
llvm::StringRef params) = 0;
|
||||
virtual void GotRpcResponse(unsigned int id, unsigned int uid,
|
||||
const char* results, std::size_t results_len) = 0;
|
||||
llvm::StringRef results) = 0;
|
||||
|
||||
MessageHandler() = default;
|
||||
MessageHandler(const MessageHandler&) = delete;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
using namespace ntimpl;
|
||||
|
||||
static double ReadDouble(char*& buf) {
|
||||
static double ReadDouble(const char*& buf) {
|
||||
// Fast but non-portable!
|
||||
std::uint64_t val = (*((unsigned char*)buf)) & 0xff;
|
||||
++buf;
|
||||
@@ -57,7 +57,7 @@ WireDecoder::WireDecoder(raw_istream& is, unsigned int proto_rev) : m_is(is) {
|
||||
WireDecoder::~WireDecoder() { std::free(m_buf); }
|
||||
|
||||
bool WireDecoder::ReadDouble(double* val) {
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, 8)) return false;
|
||||
*val = ::ReadDouble(buf);
|
||||
return true;
|
||||
@@ -139,7 +139,7 @@ bool WireDecoder::ReadValue(NT_Type type, NT_Value* value) {
|
||||
value->data.arr_boolean.size = size;
|
||||
|
||||
// array values
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, size)) return false;
|
||||
value->data.arr_boolean.arr =
|
||||
static_cast<int*>(std::malloc(size * sizeof(int)));
|
||||
@@ -154,7 +154,7 @@ bool WireDecoder::ReadValue(NT_Type type, NT_Value* value) {
|
||||
value->data.arr_double.size = size;
|
||||
|
||||
// array values
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, size * 8)) return false;
|
||||
value->data.arr_double.arr =
|
||||
static_cast<double*>(std::malloc(size * sizeof(double)));
|
||||
|
||||
@@ -45,8 +45,9 @@ class WireDecoder {
|
||||
/* Reads the specified number of bytes.
|
||||
* @param buf pointer to read data (output parameter)
|
||||
* @param len number of bytes to read
|
||||
* Caution: the buffer is only temporarily valid.
|
||||
*/
|
||||
bool Read(char** buf, std::size_t len) {
|
||||
bool Read(const char** buf, std::size_t len) {
|
||||
if (len > m_allocated) Realloc(len);
|
||||
*buf = m_buf;
|
||||
return m_is.read(m_buf, len);
|
||||
@@ -54,7 +55,7 @@ class WireDecoder {
|
||||
|
||||
/* Reads a single byte. */
|
||||
bool Read8(unsigned int* val) {
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, 1)) return false;
|
||||
*val = (*((unsigned char*)buf)) & 0xff;
|
||||
return true;
|
||||
@@ -62,7 +63,7 @@ class WireDecoder {
|
||||
|
||||
/* Reads a 16-bit word. */
|
||||
bool Read16(unsigned int* val) {
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, 2)) return false;
|
||||
unsigned int v = (*((unsigned char*)buf)) & 0xff;
|
||||
++buf;
|
||||
@@ -74,7 +75,7 @@ class WireDecoder {
|
||||
|
||||
/* Reads a 32-bit word. */
|
||||
bool Read32(unsigned long* val) {
|
||||
char* buf;
|
||||
const char* buf;
|
||||
if (!Read(&buf, 4)) return false;
|
||||
unsigned int v = (*((unsigned char*)buf)) & 0xff;
|
||||
++buf;
|
||||
|
||||
Reference in New Issue
Block a user