Panda3D
Loading...
Searching...
No Matches
pStatServerControlMessage.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pStatServerControlMessage.cxx
10 * @author drose
11 * @date 2000-07-09
12 */
13
14#include "config_pstatclient.h"
16
17#include "datagram.h"
18#include "datagramIterator.h"
19
20/**
21 *
22 */
23PStatServerControlMessage::
24PStatServerControlMessage() {
25 _type = T_invalid;
26}
27
28/**
29 * Writes the message into the indicated datagram.
30 */
32encode(Datagram &datagram) const {
33 datagram.clear();
34 datagram.add_uint8(_type);
35 switch (_type) {
36 case T_hello:
37 datagram.add_string(_server_hostname);
38 datagram.add_string(_server_progname);
39 datagram.add_uint16(_udp_port);
40 break;
41
42 default:
43 pstats_cat.error()
44 << "Invalid PStatServerControlMessage::Type " << (int)_type << "\n";
45 }
46}
47
48/**
49 * Extracts the message from the indicated datagram. Returns true on success,
50 * false on error.
51 */
53decode(const Datagram &datagram) {
54 DatagramIterator source(datagram);
55 _type = (Type)source.get_uint8();
56
57 switch (_type) {
58 case T_hello:
59 _server_hostname = source.get_string();
60 _server_progname = source.get_string();
61 _udp_port = source.get_uint16();
62 break;
63
64 default:
65 pstats_cat.error()
66 << "Read invalid PStatServerControlMessage type: " << (int)_type << "\n";
67 _type = T_invalid;
68 return false;
69 }
70
71 return true;
72}
A class to retrieve the individual data elements previously stored in a Datagram.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
std::string get_string()
Extracts a variable-length string.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition datagram.I:50
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
Definition datagram.cxx:35
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition datagram.I:85
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
Definition datagram.I:219
bool decode(const Datagram &datagram)
Extracts the message from the indicated datagram.
void encode(Datagram &datagram) const
Writes the message into the indicated datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.