summaryrefslogtreecommitdiffstats
path: root/fnet/src/examples/ping/packets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fnet/src/examples/ping/packets.cpp')
-rw-r--r--fnet/src/examples/ping/packets.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/fnet/src/examples/ping/packets.cpp b/fnet/src/examples/ping/packets.cpp
new file mode 100644
index 00000000000..8958666b374
--- /dev/null
+++ b/fnet/src/examples/ping/packets.cpp
@@ -0,0 +1,65 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/fastos/fastos.h>
+#include <vespa/fnet/fnet.h>
+#include "packets.h"
+
+uint32_t
+PingRequest::GetPCODE()
+{
+ return PCODE_PING_REQUEST;
+}
+
+uint32_t
+PingRequest::GetLength()
+{
+ return 0;
+}
+
+void
+PingRequest::Encode(FNET_DataBuffer *)
+{
+}
+
+bool
+PingRequest::Decode(FNET_DataBuffer *src, uint32_t len)
+{
+ src->DataToDead(len);
+ return (len == 0);
+}
+
+
+uint32_t
+PingReply::GetPCODE()
+{
+ return PCODE_PING_REPLY;
+}
+
+uint32_t
+PingReply::GetLength()
+{
+ return 0;
+}
+
+void
+PingReply::Encode(FNET_DataBuffer *)
+{
+}
+
+bool
+PingReply::Decode(FNET_DataBuffer *src, uint32_t len)
+{
+ src->DataToDead(len);
+ return (len == 0);
+}
+
+
+FNET_Packet *
+PingPacketFactory::CreatePacket(uint32_t pcode, FNET_Context)
+{
+ switch(pcode) {
+ case PCODE_PING_REQUEST: return new PingRequest();
+ case PCODE_PING_REPLY: return new PingReply();
+ }
+ return NULL;
+}