2015-06-21 21:02:10 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "nt_messagewriter.h"
|
|
|
|
|
|
|
|
|
|
#include "nt_internal.h"
|
|
|
|
|
|
|
|
|
|
using namespace NtImpl;
|
|
|
|
|
|
|
|
|
|
MessageWriter::~MessageWriter()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteKeepAlive()
|
|
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_KEEP_ALIVE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-22 23:16:58 -07:00
|
|
|
MessageWriter::WriteClientHello(const NT_String& self_id)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_CLIENT_HELLO);
|
|
|
|
|
Write16(m_proto_rev);
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return;
|
|
|
|
|
WriteString(self_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteProtoUnsup()
|
|
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_PROTO_UNSUP);
|
|
|
|
|
Write16(m_proto_rev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteServerHelloDone()
|
|
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_SERVER_HELLO_DONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-22 23:16:58 -07:00
|
|
|
MessageWriter::WriteServerHello(unsigned int flags, const NT_String& self_id)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
Write8(NT_MSG_SERVER_HELLO);
|
|
|
|
|
Write8(flags);
|
|
|
|
|
WriteString(self_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteClientHelloDone()
|
|
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
Write8(NT_MSG_CLIENT_HELLO_DONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-22 23:16:58 -07:00
|
|
|
MessageWriter::WriteEntryAssign(const NT_String& name,
|
2015-06-21 21:02:10 -07:00
|
|
|
unsigned int id,
|
|
|
|
|
unsigned int seq_num,
|
2015-06-22 23:16:58 -07:00
|
|
|
const NT_Value& value,
|
2015-06-21 21:02:10 -07:00
|
|
|
unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_ENTRY_ASSIGN);
|
|
|
|
|
WriteString(name);
|
|
|
|
|
WriteType(value.type);
|
|
|
|
|
Write16(id);
|
|
|
|
|
Write16(seq_num);
|
|
|
|
|
if (m_proto_rev >= 0x0300u)
|
|
|
|
|
Write8(flags);
|
|
|
|
|
WriteValue(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteEntryUpdate(unsigned int id,
|
|
|
|
|
unsigned int seq_num,
|
2015-06-22 23:16:58 -07:00
|
|
|
const NT_Value& value)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
Write8(NT_MSG_ENTRY_UPDATE);
|
|
|
|
|
Write16(id);
|
|
|
|
|
Write16(seq_num);
|
|
|
|
|
if (m_proto_rev >= 0x0300u)
|
|
|
|
|
Write8(value.type);
|
|
|
|
|
WriteValue(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteFlagsUpdate(unsigned int id, unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
Write8(NT_MSG_FLAGS_UPDATE);
|
|
|
|
|
Write16(id);
|
|
|
|
|
Write8(flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteEntryDelete(unsigned int id)
|
|
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
Write8(NT_MSG_ENTRY_DELETE);
|
|
|
|
|
Write16(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteClearEntries()
|
|
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
|
|
|
|
|
Write8(NT_MSG_CLEAR_ENTRIES);
|
|
|
|
|
Write32(NT_CLEAR_ALL_MAGIC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteExecuteRpc(unsigned int id,
|
|
|
|
|
unsigned int uid,
|
2015-06-22 23:16:58 -07:00
|
|
|
const NT_Value* params_start,
|
|
|
|
|
const NT_Value* params_end)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
WriteRpc(NT_MSG_EXECUTE_RPC, id, uid, params_start, params_end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteRpcResponse(unsigned int id,
|
|
|
|
|
unsigned int uid,
|
2015-06-22 23:16:58 -07:00
|
|
|
const NT_Value* results_start,
|
|
|
|
|
const NT_Value* results_end)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
WriteRpc(NT_MSG_RPC_RESPONSE, id, uid, results_start, results_end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessageWriter::WriteRpc(unsigned int msg_type,
|
|
|
|
|
unsigned int id,
|
|
|
|
|
unsigned int uid,
|
2015-06-22 23:16:58 -07:00
|
|
|
const NT_Value* values_start,
|
|
|
|
|
const NT_Value* values_end)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
if (m_proto_rev < 0x0300u)
|
|
|
|
|
return; // new message in version 3.0
|
|
|
|
|
|
|
|
|
|
Write8(msg_type);
|
|
|
|
|
Write16(id);
|
|
|
|
|
Write16(uid);
|
|
|
|
|
|
|
|
|
|
unsigned long len = 0;
|
2015-06-22 23:16:58 -07:00
|
|
|
for (const NT_Value* value = values_start; value != values_end; ++value)
|
2015-06-21 22:42:01 -07:00
|
|
|
len += GetValueSize(*value);
|
2015-06-21 21:02:10 -07:00
|
|
|
WriteULEB128(len);
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
for (const NT_Value* value = values_start; value != values_end; ++value)
|
2015-06-21 21:02:10 -07:00
|
|
|
WriteValue(*value);
|
|
|
|
|
}
|