FETPAPI 0.6.0.0
This project provides C++ classes which facilitate the developement of ETP1.2 clients and servers.
Loading...
Searching...
No Matches
EtpMessage.h
1/*-----------------------------------------------------------------------
2Licensed to the Apache Software Foundation (ASF) under one
3or more contributor license agreements. See the NOTICE file
4distributed with this work for additional information
5regarding copyright ownership. The ASF licenses this file
6to you under the Apache License, Version 2.0 (the
7"License"; you may not use this file except in compliance
8with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing,
13software distributed under the License is distributed on an
14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, either express or implied. See the License for the
16specific language governing permissions and limitations
17under the License.
18-----------------------------------------------------------------------*/
19#pragma once
20
21#include <avro/Decoder.hh>
22#include <avro/Encoder.hh>
23#include <avro/Specific.hh>
24
25namespace Energistics {
26 namespace Etp {
27 namespace v12 {
28 namespace Datatypes {
30 int32_t protocol = 0;
31 int32_t messageType = 0;
32 int64_t correlationId = 0;
33 int64_t messageId = 0;
34 int32_t messageFlags = 0;
35 };
36 }
37 }
38 }
39}
40namespace avro {
41 template<> struct codec_traits<Energistics::Etp::v12::Datatypes::MessageHeader> {
42 static void encode(Encoder& e, const Energistics::Etp::v12::Datatypes::MessageHeader& v) {
43 avro::encode(e, v.protocol);
44 avro::encode(e, v.messageType);
45 avro::encode(e, v.correlationId);
46 avro::encode(e, v.messageId);
47 avro::encode(e, v.messageFlags);
48 }
49 static void decode(Decoder& e, Energistics::Etp::v12::Datatypes::MessageHeader& v) {
50 avro::decode(e, v.protocol);
51 avro::decode(e, v.messageType);
52 avro::decode(e, v.correlationId);
53 avro::decode(e, v.messageId);
54 avro::decode(e, v.messageFlags);
55 }
56 };
57}
58
59namespace ETP_NS
60{
62 {
63 public:
64
65 virtual ~EtpMessage() = default;
66
67 std::shared_ptr<const std::vector<uint8_t>> encodeHeaderAndBody() {
68 auto out = avro::memoryOutputStream();
69 auto encoder = avro::binaryEncoder();
70 encoder->init(*out);
71
72 avro::encode(*encoder, messageHeader);
73 encode(*encoder);
74 encoder->flush();
75
76 return avro::snapshot(*out);
77 }
78
79 virtual void encode(avro::Encoder&) const = 0;
80 virtual void decode(avro::Decoder&) = 0;
81
82 std::string to_string() const {
83 std::ostringstream oss;
84 oss << "*************************************************\n"
85 << "Message Header put in the queue :\n"
86 << "protocol : " << messageHeader.protocol << '\n'
87 << "type : " << messageHeader.messageType << '\n'
88 << "id : " << messageHeader.messageId << '\n'
89 << "correlation id : " << messageHeader.correlationId << '\n'
90 << "flags : " << messageHeader.messageFlags << '\n'
91 << "*************************************************" << '\n'
92 << body_to_string();
93 return oss.str();
94 }
95
97
98 protected :
99 virtual std::string body_to_string() const { return ""; }
100 };
101}
Definition EtpMessage.h:62