Skip to content
Repos

DevPlaceApp

C++ 990 B23 lines Opens in site

Directory Raw Download

#pragma once
// Spec: models.md "Chat websocket". decode: frame bytes -> event, nullopt (frame dropped) on any problem.
// encode*: byte compatible with Swift JSONEncoder(): compact, declaration order (type first), "/" escaped as "\/",
// non-ASCII raw UTF-8, control characters escaped (\b \f \n \r \t, others \u00XX).
#include <optional>
#include <string>
#include <vector>

#include "model/ChatSocketEvent.hpp"

namespace dp {

class ChatSocketCodec {
 public:
  static std::optional<ChatSocketEvent> decode(const std::string& frame);
  static std::string encodeSend(const std::string& receiverUid, const std::string& content,
                                const std::vector<std::string>& attachmentUids, const std::string& clientId);
  static std::string encodeTyping(const std::string& receiverUid);
  static std::string encodeRead(const std::string& withUid);
  static std::string quote(const std::string& text);  // one JSON string literal, Foundation style
};

}  // namespace dp
29.3ms