Skip to content

Commit

Permalink
Enable append/get template for enum types, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkbeyer committed Jan 11, 2016
1 parent a07f7f3 commit 839b40b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Packet {
*
* \author Pompei2
*/
template<class T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
template<class T, typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>::type* = nullptr>
Packet* append( T in )
{
std::int8_t* pBuf;
Expand All @@ -83,7 +83,7 @@ class Packet {
*
* \author Pompei2
*/
template<class T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr >
template<class T, typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>::type* = nullptr >
void get( T& in )
{
std::size_t len = this->getTotalLen();
Expand Down
13 changes: 13 additions & 0 deletions test/packet_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "catch.hpp"
#include "../include/packet.h"
#include <memory>
#include "../include/dsrv_constants.h"

using namespace FTS;
using namespace std;
Expand Down Expand Up @@ -289,3 +290,15 @@ TEST_CASE( "Writing to/ reading from a packet", "[Packet]" )
auto s = p3.get_string();
REQUIRE( s == "Hallo Otto!" );
}

TEST_CASE( "Append non generic data", "[Packet]" )
{
Packet p( DSRV_MSG_CHAT_GETMSG );
DSRV_CHAT_TYPE type = DSRV_CHAT_TYPE::NORMAL;
p.append(type);
p.rewind();
type = DSRV_CHAT_TYPE::NONE;
p.get( type );
REQUIRE( type == DSRV_CHAT_TYPE::NORMAL);

}

0 comments on commit 839b40b

Please sign in to comment.