Infinispan HotRod C++ Client 9.2.0.Final
Loading...
Searching...
No Matches
DataFormat.h
Go to the documentation of this file.
1/*
2 * DataFormat.h
3 *
4 * Created on: Sep 6, 2018
5 * Author: rigazilla
6 */
7
8#ifndef INCLUDE_INFINISPAN_HOTROD_DATAFORMAT_H_
9#define INCLUDE_INFINISPAN_HOTROD_DATAFORMAT_H_
10
13
14#include <map>
15#include <vector>
16#include <memory>
17#include <string>
18
19namespace infinispan {
20namespace hotrod {
21
22// A data structure for media type as in MIME type
23// only the typeSubtype field is in use at the moment
24
25struct MediaType {
26 HR_EXTERN MediaType(const char* typeSubtype = nullptr);
27 std::string type;
28 std::string subType;
29 std::string typeSubtype;
30 double weight = 0;
31 std::map<std::string, std::string> params;
32 std::string toString() const {
33 return typeSubtype;
34 }
35};
36
37// Well know media type. This table is used by the hotrod protocol
38static constexpr const char* APPLICATION_JSON_TYPE = "application/json";
39static constexpr const char* APPLICATION_OCTET_STREAM_TYPE =
40 "application/octet-stream";
41static constexpr const char* APPLICATION_OBJECT_TYPE =
42 "application/x-java-object";
43static constexpr const char* APPLICATION_PDF_TYPE = "application/pdf";
44static constexpr const char* APPLICATION_RTF_TYPE = "application/rtf";
45static constexpr const char* APPLICATION_SERIALIZED_OBJECT_TYPE =
46 "application/x-java-serialized-object";
47static constexpr const char* APPLICATION_XML_TYPE = "application/xml";
48static constexpr const char* APPLICATION_ZIP_TYPE = "application/zip";
49static constexpr const char* APPLICATION_JBOSS_MARSHALLING_TYPE =
50 "application/x-jboss-marshalling";
51static constexpr const char* APPLICATION_PROTOSTREAM_TYPE =
52 "application/x-protostream";
53static constexpr const char* APPLICATION_UNKNOWN_TYPE = "application/unknown";
54static constexpr const char* WWW_FORM_URLENCODED_TYPE =
55 "application/x-www-form-urlencoded";
56static constexpr const char* IMAGE_GIF_TYPE = "image/gif";
57static constexpr const char* IMAGE_JPEG_TYPE = "image/jpeg";
58static constexpr const char* IMAGE_PNG_TYPE = "image/png";
59static constexpr const char* TEXT_CSS_TYPE = "text/css";
60static constexpr const char* TEXT_CSV_TYPE = "text/csv";
61static constexpr const char* TEXT_PLAIN_TYPE = "text/plain";
62static constexpr const char* TEXT_HTML_TYPE = "text/html";
63static constexpr const char* APPLICATION_INFINISPAN_MARSHALLING_TYPE =
64 "application/x-infinispan-marshalling";
65static constexpr const char* APPLICATION_INFINISPAN_BINARY_TYPE =
66 "application/x-infinispan-binary";
67static constexpr const char* APPLICATION_PROTOSTUFF_TYPE =
68 "application/x-protostuff";
69static constexpr const char* APPLICATION_KRYO_TYPE = "application/x-kryo";
70
71// This is a map between well know media types and a numerical identifier
72// which will be transmitted to the server
74 static std::map<std::string, int> typesIds;
75 static int getByMediaType(std::string mediaType);
76 static std::string getById(int id);
77};
78
79// A struct representing an entry (key,value) media type
83};
84
85// A template struct containing the media type and the key value marshallers
86template <class K, class V> struct DataFormat : EntryMediaTypes {
87 void keyMarshall(const K& k, std::vector<char>& buff) {
88 keyMarshaller->marshall(k, buff);
89 }
90 K* keyUnmarshall(const std::vector<char>& buff) {
91 return keyMarshaller->unmarshall(buff);
92 }
93 void valueMarshall(const V& k, std::vector<char>& buff) {
94 valueMarshaller->marshall(k, buff);
95 }
96 V* valueUnmarshall(const std::vector<char>& buff) {
97 return valueMarshaller->unmarshall(buff);
98 }
99 std::shared_ptr<Marshaller<K> > keyMarshaller;
100 std::shared_ptr<Marshaller<V> > valueMarshaller;
101};
102
103}
104}
105
106#endif /* INCLUDE_INFINISPAN_HOTROD_DATAFORMAT_H_ */
#define HR_EXTERN
Definition: ImportExport.h:35
Definition: AuthenticationConfiguration.h:10
Definition: DataFormat.h:86
void valueMarshall(const V &k, std::vector< char > &buff)
Definition: DataFormat.h:93
std::shared_ptr< Marshaller< V > > valueMarshaller
Definition: DataFormat.h:100
std::shared_ptr< Marshaller< K > > keyMarshaller
Definition: DataFormat.h:99
V * valueUnmarshall(const std::vector< char > &buff)
Definition: DataFormat.h:96
K * keyUnmarshall(const std::vector< char > &buff)
Definition: DataFormat.h:90
void keyMarshall(const K &k, std::vector< char > &buff)
Definition: DataFormat.h:87
Definition: DataFormat.h:80
MediaType valueMediaType
Definition: DataFormat.h:82
MediaType keyMediaType
Definition: DataFormat.h:81
Definition: DataFormat.h:73
static std::string getById(int id)
static int getByMediaType(std::string mediaType)
static std::map< std::string, int > typesIds
Definition: DataFormat.h:74
Definition: DataFormat.h:25
std::string type
Definition: DataFormat.h:27
std::string subType
Definition: DataFormat.h:28
HR_EXTERN MediaType(const char *typeSubtype=nullptr)
std::map< std::string, std::string > params
Definition: DataFormat.h:31
double weight
Definition: DataFormat.h:30
std::string toString() const
Definition: DataFormat.h:32
std::string typeSubtype
Definition: DataFormat.h:29