ostinato/rpc/pbhelper.h
Srivats P. 84c7fe1e06 Features
- Added support for retrieving the packet capture buffer from server to client (does not work consistently however - needs investigation)
		- getCaptureBuffer() Rpc signature changed
	- RPC: Added support in Rpc Channel (client) to queue calls
	- RPC: Added support for transferring arbitrary binary data from server to client (used to get packet capture files)
		- Rpc header changed - length is now 4 bytes instead of 2; there is no rsvd field any longer

Fixes
	- RPC: Fix for the case when a msg is not received all at once over the socket
	- StreamConfigDialog: fixed display issue in packet view for combo protocols containing meta fields
	- Fixed issue with Stacked Vlan not retaining data for both CVlan and SVlan
	- Fixed incorrect payload size issue with increment/decrement frame length modes

Refactoring, Cleanup etc.
	- RPC: Minor code and TODOs cleanup
	- Server: Minor code and TODOs cleanup
	- Server: Removed unused file(s): rxtx.cpp, rxtx.h
	- Server: Replaced direct use of ProtocolList with the ProtocolListIterator
	- Common: Minor code and TODOs cleanup
	- StreamBase::frameLen() now returns the length based on the mode/min/max and the passed in streamIndex
	- AbstractProtocol interface changed for methods - protocolFrameSize(), protocolFrameOffset(), protocolFramePayloadSize() : all of them now take streamIndex as an optional param with 0 as the default value
		- Protocols implementing the above methods changed accordingly
2009-11-03 14:02:09 +00:00

152 lines
4.1 KiB
C++

#ifndef _PB_HELPER_H
#define _PB_HELPER_H
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <qdebug.h>
#if 0 // not reqd. any longer?
class PbHelper
{
public:
// FIXME: Change msg from * to &
void ForceSetSingularDefault(::google::protobuf::Message *msg)
{
const ::google::protobuf::Descriptor *desc;
::google::protobuf::Message::Reflection *refl;
qDebug("In %s", __FUNCTION__);
desc = msg->GetDescriptor();
refl = msg->GetReflection();
for (int i=0; i < desc->field_count(); i++)
{
const ::google::protobuf::FieldDescriptor *f;
f = desc->field(i);
// Ensure field is singular and not already set
if (f->label() ==
::google::protobuf::FieldDescriptor::LABEL_REPEATED)
continue;
if (refl->HasField(f))
continue;
switch(f->type())
{
case ::google::protobuf::FieldDescriptor::TYPE_DOUBLE:
refl->SetDouble(f, refl->GetDouble(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_FLOAT:
refl->SetFloat(f, refl->GetFloat(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_INT32:
case ::google::protobuf::FieldDescriptor::TYPE_SINT32:
case ::google::protobuf::FieldDescriptor::TYPE_SFIXED32:
refl->SetInt32(f, refl->GetInt32(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_INT64:
case ::google::protobuf::FieldDescriptor::TYPE_SINT64:
case ::google::protobuf::FieldDescriptor::TYPE_SFIXED64:
refl->SetInt64(f, refl->GetInt64(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_UINT32:
case ::google::protobuf::FieldDescriptor::TYPE_FIXED32:
refl->SetUInt32(f, refl->GetUInt32(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_UINT64:
case ::google::protobuf::FieldDescriptor::TYPE_FIXED64:
refl->SetUInt64(f, refl->GetUInt64(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_BOOL:
refl->SetBool(f, refl->GetBool(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_ENUM:
refl->SetEnum(f, refl->GetEnum(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_STRING:
case ::google::protobuf::FieldDescriptor::TYPE_BYTES:
refl->SetString(f, refl->GetString(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_MESSAGE:
case ::google::protobuf::FieldDescriptor::TYPE_GROUP:
ForceSetSingularDefault(refl->MutableMessage(f)); // recursion!
break;
default:
qDebug("unhandled Field Type");
break;
}
}
}
bool update(
::google::protobuf::Message *target,
::google::protobuf::Message *source)
{
// FIXME(HI): Depracate: use MergeFrom() directly
qDebug("In %s", __FUNCTION__);
target->MergeFrom(*source);
return true;
#if 0
::google::protobuf::Message::Reflection *sourceRef;
::google::protobuf::Message::Reflection *targetRef;
std::vector<const ::google::protobuf::FieldDescriptor*> srcFieldList;
if (source->GetDescriptor()->full_name() !=
target->GetDescriptor()->full_name())
goto _error_exit;
sourceRef = source->GetReflection();
targetRef = target->GetReflection();
sourceRef->ListFields(&srcFieldList);
for (uint i=0; i < srcFieldList.size(); i++)
{
const ::google::protobuf::FieldDescriptor *srcField, *targetField;
srcField = srcFieldList[i];
targetField = target->GetDescriptor()->FindFieldByName(
srcField->name());
switch(targetField->type())
{
case ::google::protobuf::FieldDescriptor::TYPE_UINT32:
targetRef->SetUInt32(targetField,
sourceRef->GetUInt32(srcField));
break;
case ::google::protobuf::FieldDescriptor::TYPE_BOOL:
targetRef->SetBool(targetField,
sourceRef->GetBool(srcField));
break;
case ::google::protobuf::FieldDescriptor::TYPE_STRING:
targetRef->SetString(targetField,
sourceRef->GetString(srcField));
break;
default:
qDebug("unhandled Field Type");
break;
}
}
_error_exit:
qDebug("%s: error!", __FUNCTION__);
return false;
#endif
}
};
#endif
#endif