Infinispan HotRod C++ Client  9.1.0.Final
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 
19 namespace infinispan {
20 namespace 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 
25 struct 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
38 static constexpr const char* APPLICATION_JSON_TYPE = "application/json";
39 static constexpr const char* APPLICATION_OCTET_STREAM_TYPE =
40  "application/octet-stream";
41 static constexpr const char* APPLICATION_OBJECT_TYPE =
42  "application/x-java-object";
43 static constexpr const char* APPLICATION_PDF_TYPE = "application/pdf";
44 static constexpr const char* APPLICATION_RTF_TYPE = "application/rtf";
45 static constexpr const char* APPLICATION_SERIALIZED_OBJECT_TYPE =
46  "application/x-java-serialized-object";
47 static constexpr const char* APPLICATION_XML_TYPE = "application/xml";
48 static constexpr const char* APPLICATION_ZIP_TYPE = "application/zip";
49 static constexpr const char* APPLICATION_JBOSS_MARSHALLING_TYPE =
50  "application/x-jboss-marshalling";
51 static constexpr const char* APPLICATION_PROTOSTREAM_TYPE =
52  "application/x-protostream";
53 static constexpr const char* APPLICATION_UNKNOWN_TYPE = "application/unknown";
54 static constexpr const char* WWW_FORM_URLENCODED_TYPE =
55  "application/x-www-form-urlencoded";
56 static constexpr const char* IMAGE_GIF_TYPE = "image/gif";
57 static constexpr const char* IMAGE_JPEG_TYPE = "image/jpeg";
58 static constexpr const char* IMAGE_PNG_TYPE = "image/png";
59 static constexpr const char* TEXT_CSS_TYPE = "text/css";
60 static constexpr const char* TEXT_CSV_TYPE = "text/csv";
61 static constexpr const char* TEXT_PLAIN_TYPE = "text/plain";
62 static constexpr const char* TEXT_HTML_TYPE = "text/html";
63 static constexpr const char* APPLICATION_INFINISPAN_MARSHALLING_TYPE =
64  "application/x-infinispan-marshalling";
65 static constexpr const char* APPLICATION_INFINISPAN_BINARY_TYPE =
66  "application/x-infinispan-binary";
67 static constexpr const char* APPLICATION_PROTOSTUFF_TYPE =
68  "application/x-protostuff";
69 static 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
73 struct IdsMediaTypes {
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
86 template <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_ */
void valueMarshall(const V &k, std::vector< char > &buff)
Definition: DataFormat.h:93
std::map< std::string, std::string > params
Definition: DataFormat.h:31
void keyMarshall(const K &k, std::vector< char > &buff)
Definition: DataFormat.h:87
std::shared_ptr< Marshaller< V > > valueMarshaller
Definition: DataFormat.h:100
HR_EXTERN MediaType(const char *typeSubtype=nullptr)
#define HR_EXTERN
Definition: ImportExport.h:35
MediaType keyMediaType
Definition: DataFormat.h:81
static int getByMediaType(std::string mediaType)
Definition: DataFormat.h:73
std::string typeSubtype
Definition: DataFormat.h:29
std::string subType
Definition: DataFormat.h:28
MediaType valueMediaType
Definition: DataFormat.h:82
static std::map< std::string, int > typesIds
Definition: DataFormat.h:74
Definition: DataFormat.h:25
std::shared_ptr< Marshaller< K > > keyMarshaller
Definition: DataFormat.h:99
Definition: AuthenticationConfiguration.h:10
Definition: DataFormat.h:80
std::string type
Definition: DataFormat.h:27
K * keyUnmarshall(const std::vector< char > &buff)
Definition: DataFormat.h:90
std::string toString() const
Definition: DataFormat.h:32
V * valueUnmarshall(const std::vector< char > &buff)
Definition: DataFormat.h:96
Definition: DataFormat.h:86
double weight
Definition: DataFormat.h:30
static std::string getById(int id)