Skip to content

Support UInt64 values in string payloads #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/internal/sio_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ namespace sio
{
return int_message::create(value.GetInt64());
}
else if (value.IsUint64())
{
return int_message::create(static_cast<int64_t>(value.GetUint64()));
}
else if(value.IsDouble())
{
return double_message::create(value.GetDouble());
Expand Down Expand Up @@ -176,14 +180,14 @@ namespace sio
}
return ptr;
}
else if(value.IsBool())
{
return bool_message::create(value.GetBool());
}
else if(value.IsNull())
{
return null_message::create();
}
else if(value.IsBool())
{
return bool_message::create(value.GetBool());
}
else if(value.IsNull())
{
return null_message::create();
}
return message::ptr();
}

Expand Down
20 changes: 20 additions & 0 deletions test/sio_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,23 @@ TEST_CASE( "test_packet_parse_4" )
CHECK(array->get_vector()[2]->get_string() == "text");

}

/*
* Test parsing of UInt64 values. See #174.
*/
TEST_CASE( "test_packet_parse_5" )
{
packet p;
bool hasbin = p.parse("42/nsp,1001[\"event\",17657333360744292000]");
CHECK(!hasbin);
CHECK(p.get_frame() == packet::frame_message);
CHECK(p.get_type() == packet::type_event);
CHECK(p.get_nsp() == "/nsp");
CHECK(p.get_pack_id() == 1001);
CHECK(p.get_message()->get_flag() == message::flag_array);
REQUIRE(p.get_message()->get_vector().size() == 2);
REQUIRE(p.get_message()->get_vector()[0]->get_flag() == message::flag_string);
CHECK(p.get_message()->get_vector()[0]->get_string() == "event");
REQUIRE(p.get_message()->get_vector()[1]->get_flag() == message::flag_integer);
CHECK(p.get_message()->get_vector()[1]->get_int() == 17657333360744292000U);
}