aboutsummaryrefslogtreecommitdiffstats
path: root/fnet/src/examples/ping/packets.cpp
blob: 9aace9b8dcb285895d0ac7f604b5d54a13a29ddc (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "packets.h"
#include <vespa/fnet/databuffer.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 nullptr;
}