-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_serialization.h
More file actions
44 lines (39 loc) · 1.51 KB
/
Copy pathmessage_serialization.h
File metadata and controls
44 lines (39 loc) · 1.51 KB
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
/*
* Header for the MessageSerialization namespace.
* Provides functions for encoding and decoding Message objects.
*
* CSF Assignment 5
*
* Ifrah Attar - iattar1@jh.edu
* Morgan Huberty - mhubert3@jh.edu
*
*/
#ifndef MESSAGE_SERIALIZATION_H
#define MESSAGE_SERIALIZATION_H
#include <string>
#include "message.h"
/**
* @namespace MessageSerialization
* @brief A collection of functions for serializing and deserializing Message objects.
*/
namespace MessageSerialization {
/**
* @brief Encodes a Message object into its string representation.
* Converts a Message object into a single line of text terminated by a
* newline, according to the network protocol.
* @param msg The Message object to encode.
* @param encoded_msg A reference to a string where the encoded message will be stored.
* @throw InvalidMessage if the resulting encoded message exceeds the maximum length.
*/
void encode(const Message &msg, std::string &encoded_msg);
/**
* @brief Decodes a string representation into a Message object.
* Parses a string and constructs a Message object.
* @param encoded_msg The string to decode.
* @param msg A reference to a Message object where the decoded message will be stored.
* @throw InvalidMessage if the string is not a valid encoded message (e.g.,
* too long, no newline, invalid format, or results in an invalid Message).
*/
void decode(const std::string &encoded_msg, Message &msg);
};
#endif // MESSAGE_SERIALIZATION_H