Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-relayserver
Commits
1c087a1b
Commit
1c087a1b
authored
Apr 12, 2018
by
Hubert Denkmair
Browse files
use msgpack::unpack() to avoid unneccessary memcpy()
parent
96855a9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
relayserver/TcpProtocol.cpp
View file @
1c087a1b
...
...
@@ -45,20 +45,16 @@ void TcpProtocol::OnMessageReceived(std::vector<char> &data)
{
_messageReceivedCallback
(
data
);
msgpack
::
unpacker
pac
;
msgpack
::
object_handle
obj
;
uint64_t
version
,
message_type
;
pac
.
reserve_buffer
(
data
.
size
());
memcpy
(
pac
.
buffer
(),
data
.
data
(),
data
.
size
());
pac
.
buffer_consumed
(
data
.
size
());
if
(
!
pac
.
next
(
obj
))
{
return
;
}
msgpack
::
unpack
(
obj
,
data
.
data
(),
data
.
size
());
if
(
obj
.
get
().
type
!=
msgpack
::
type
::
ARRAY
)
{
return
;
}
auto
arr
=
obj
.
get
().
via
.
array
;
if
(
arr
.
size
<
2
)
{
return
;
}
uint64_t
version
=
arr
.
ptr
[
0
].
via
.
u64
;
uint64_t
message_type
=
arr
.
ptr
[
1
].
via
.
u64
;
arr
.
ptr
[
0
]
>>
version
;
arr
.
ptr
[
1
]
>>
message_type
;
switch
(
message_type
)
{
...
...
@@ -71,7 +67,7 @@ void TcpProtocol::OnMessageReceived(std::vector<char> &data)
break
;
case
MsgPackProtocol
::
MESSAGE_TYPE_TICK
:
std
::
cerr
<<
"tick"
<<
std
::
endl
;
OnTickReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
TickMessage
>
())
;
break
;
case
MsgPackProtocol
::
MESSAGE_TYPE_BOT_SPAWN
:
...
...
@@ -121,6 +117,11 @@ void TcpProtocol::OnWorldUpdateReceived(const MsgPackProtocol::WorldUpdateMessag
}
}
void
TcpProtocol
::
OnTickReceived
(
const
MsgPackProtocol
::
TickMessage
&
msg
)
{
(
void
)
msg
;
}
void
TcpProtocol
::
OnFoodSpawnReceived
(
const
MsgPackProtocol
::
FoodSpawnMessage
&
msg
)
{
if
(
_food
==
nullptr
)
{
return
;
}
...
...
relayserver/TcpProtocol.h
View file @
1c087a1b
...
...
@@ -43,6 +43,7 @@ class TcpProtocol
void
OnGameInfoReceived
(
const
MsgPackProtocol
::
GameInfoMessage
&
msg
);
void
OnWorldUpdateReceived
(
const
MsgPackProtocol
::
WorldUpdateMessage
&
msg
);
void
OnTickReceived
(
const
MsgPackProtocol
::
TickMessage
&
msg
);
void
OnFoodSpawnReceived
(
const
MsgPackProtocol
::
FoodSpawnMessage
&
msg
);
void
OnFoodConsumedReceived
(
const
MsgPackProtocol
::
FoodConsumeMessage
&
msg
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment