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