mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Refactor WireEncoder.
Change-Id: I50106755ce5571821d6e36767b16d08b91f054de
This commit is contained in:
@@ -8,44 +8,39 @@
|
||||
#ifndef NT_MESSAGEWRITER_H_
|
||||
#define NT_MESSAGEWRITER_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include "ntcore.h"
|
||||
#include "nt_encoding.h"
|
||||
#include "nt_wireencoder.h"
|
||||
|
||||
namespace NtImpl {
|
||||
|
||||
class MessageWriter
|
||||
class MessageWriter : private WireEncoder
|
||||
{
|
||||
public:
|
||||
explicit MessageWriter(unsigned int proto_rev);
|
||||
explicit MessageWriter(unsigned int proto_rev) : WireEncoder(proto_rev) {}
|
||||
~MessageWriter();
|
||||
|
||||
void SetProtocolRev(unsigned int proto_rev)
|
||||
{
|
||||
m_proto_rev = proto_rev;
|
||||
WireEncoder::SetProtocolRev(proto_rev);
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_cur = m_start;
|
||||
m_error = 0;
|
||||
WireEncoder::Reset();
|
||||
}
|
||||
|
||||
const char *GetError() const
|
||||
{
|
||||
return m_error;
|
||||
return WireEncoder::GetError();
|
||||
}
|
||||
|
||||
const char *GetData() const
|
||||
{
|
||||
return m_start;
|
||||
return WireEncoder::GetData();
|
||||
}
|
||||
|
||||
std::size_t GetSize() const
|
||||
{
|
||||
return m_cur - m_start;
|
||||
return WireEncoder::GetSize();
|
||||
}
|
||||
|
||||
void WriteKeepAlive();
|
||||
@@ -74,50 +69,15 @@ public:
|
||||
const NT_Value *results_start,
|
||||
const NT_Value *results_end);
|
||||
|
||||
protected:
|
||||
void Ensure(std::size_t len)
|
||||
{
|
||||
assert(m_end > m_cur);
|
||||
if (static_cast<size_t>(m_end - m_cur) < len)
|
||||
EnsureSlow(len);
|
||||
}
|
||||
|
||||
void Write8(unsigned int val)
|
||||
{
|
||||
NtImpl::Write8(m_cur, val);
|
||||
}
|
||||
|
||||
void Write16(unsigned int val)
|
||||
{
|
||||
NtImpl::Write16(m_cur, val);
|
||||
}
|
||||
|
||||
void Write32(unsigned long val)
|
||||
{
|
||||
NtImpl::Write32(m_cur, val);
|
||||
}
|
||||
|
||||
void WriteULEB128(unsigned long val);
|
||||
void WriteType(NT_Type type);
|
||||
void WriteValue(const NT_Value &value);
|
||||
void WriteString(const NT_String &str);
|
||||
|
||||
private:
|
||||
MessageWriter(const MessageWriter&);
|
||||
MessageWriter& operator= (const MessageWriter&);
|
||||
|
||||
void EnsureSlow(std::size_t len);
|
||||
void WriteRpc(unsigned int msg_type,
|
||||
unsigned int id,
|
||||
unsigned int uid,
|
||||
const NT_Value *values_start,
|
||||
const NT_Value *values_end);
|
||||
|
||||
char *m_start;
|
||||
char *m_cur;
|
||||
char *m_end;
|
||||
unsigned int m_proto_rev;
|
||||
const char *m_error;
|
||||
};
|
||||
|
||||
} // namespace NtImpl
|
||||
|
||||
Reference in New Issue
Block a user