aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/html/htmlprotobuf.h
blob: 35d1d1d9a84639df1f2932be9f70883ce1a5e84f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//=============================================================================//

#ifndef HTML_PROTOBUF
#define HTML_PROTOBUF

#ifdef _WIN32
#pragma once
#endif

#include "tier1/utlbuffer.h"
#include "html/htmlmessages.h"

namespace google
{
	namespace protobuf
	{
		class MessageLite;
	}
}

class CHTMLBaseProtoBufMsg
{
public:
	void SerializeCrossProc( CUtlBuffer *pBuffer ) const;
	bool BDeserializeCrossProc( CUtlBuffer *pBuffer );

protected:
	void *m_pMsg;
	bool m_bIsValid;
};


//-----------------------------------------------------------------------------
// Purpose: Base class for protobuf objects
//-----------------------------------------------------------------------------
template< typename PB_OBJECT_TYPE > 
class CHTMLProtoBufMsg : public CHTMLBaseProtoBufMsg
{
public:
	CHTMLProtoBufMsg( EHTMLCommands eMsg )
	{
		m_pMsg = new PB_OBJECT_TYPE;
		m_bIsValid = true;
	}

	// Construct and deserialize in one
	CHTMLProtoBufMsg( CUtlBuffer *pBuffer )
	{
		m_pMsg = NULL;
		m_bIsValid = BDeserializeCrossProc( pBuffer );
	}

	// Destructor
	virtual ~CHTMLProtoBufMsg()
	{
		delete (PB_OBJECT_TYPE *)m_pMsg;
	}

	bool BIsValid() { return m_bIsValid; }

	// Accessors
	PB_OBJECT_TYPE &Body() { return *((PB_OBJECT_TYPE*)( (google::protobuf::MessageLite *)m_pMsg )); }
	const PB_OBJECT_TYPE &BodyConst() const { return *((const PB_OBJECT_TYPE*)( (google::protobuf::MessageLite *)m_pMsg )); }

};


#endif // HTML_PROTOBUF