summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/amqp/MessageEncoder.h
blob: 05e17140046e7bd96c1fe079d1935133e29b2873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef QPID_AMQP_MESSAGEENCODER_H
#define QPID_AMQP_MESSAGEENCODER_H

/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
#include "qpid/amqp/Encoder.h"
#include "qpid/types/Variant.h"

namespace qpid {
namespace amqp {
class MapHandler;
/**
 *
 */
class MessageEncoder : public Encoder
{
  public:
    class Header
    {
      public:
        virtual ~Header() {}
        virtual bool isDurable() const = 0;
        virtual uint8_t getPriority() const = 0;
        QPID_COMMON_EXTERN virtual bool hasTtl() const = 0;
        virtual uint32_t getTtl() const = 0;
        virtual bool isFirstAcquirer() const = 0;
        virtual uint32_t getDeliveryCount() const = 0;
    };

    class Properties
    {
      public:
        virtual ~Properties() {}
        virtual bool hasMessageId() const = 0;
        virtual std::string getMessageId() const = 0;
        virtual bool hasUserId() const = 0;
        virtual std::string getUserId() const = 0;
        virtual bool hasTo() const = 0;
        virtual std::string getTo() const = 0;
        virtual bool hasSubject() const = 0;
        virtual std::string getSubject() const = 0;
        virtual bool hasReplyTo() const = 0;
        virtual std::string getReplyTo() const = 0;
        virtual bool hasCorrelationId() const = 0;
        virtual std::string getCorrelationId() const = 0;
        virtual bool hasContentType() const = 0;
        virtual std::string getContentType() const = 0;
        virtual bool hasContentEncoding() const = 0;
        virtual std::string getContentEncoding() const = 0;
        virtual bool hasAbsoluteExpiryTime() const = 0;
        virtual int64_t getAbsoluteExpiryTime() const = 0;
        virtual bool hasCreationTime() const = 0;
        virtual int64_t getCreationTime() const = 0;
        virtual bool hasGroupId() const = 0;
        virtual std::string getGroupId() const = 0;
        virtual bool hasGroupSequence() const = 0;
        virtual uint32_t getGroupSequence() const = 0;
        virtual bool hasReplyToGroupId() const = 0;
        virtual std::string getReplyToGroupId() const = 0;
    };

    class ApplicationProperties
    {
      public:
        virtual ~ApplicationProperties() {}
        virtual void handle(MapHandler&) const = 0;
    };

    QPID_COMMON_EXTERN MessageEncoder(char* d, size_t s) : Encoder(d, s), optimise(true) {}
    QPID_COMMON_EXTERN void writeHeader(const Header&);
    QPID_COMMON_EXTERN void writeProperties(const Properties&);
    QPID_COMMON_EXTERN void writeApplicationProperties(const ApplicationProperties&);
    QPID_COMMON_EXTERN void writeApplicationProperties(const qpid::types::Variant::Map& properties);
    QPID_COMMON_EXTERN void writeApplicationProperties(const qpid::types::Variant::Map& properties, bool useLargeMap);

    QPID_COMMON_EXTERN static size_t getEncodedSize(const Header&);
    QPID_COMMON_EXTERN static size_t getEncodedSize(const Properties&);
    QPID_COMMON_EXTERN static size_t getEncodedSize(const ApplicationProperties&);

    QPID_COMMON_EXTERN static size_t getEncodedSize(const qpid::types::Variant::List&, bool useLargeList);
    QPID_COMMON_EXTERN static size_t getEncodedSize(const qpid::types::Variant::Map&, bool useLargeMap);

    QPID_COMMON_EXTERN static size_t getEncodedSizeForValue(const qpid::types::Variant& value);
    QPID_COMMON_EXTERN static size_t getEncodedSizeForContent(const std::string&);

    //used in translating 0-10 content to 1.0, to determine buffer space needed
    QPID_COMMON_EXTERN static size_t getEncodedSize(const Properties&, const qpid::types::Variant::Map&, const std::string&);

  private:
    bool optimise;

    static size_t getEncodedSize(const Header&, const Properties&, const ApplicationProperties&, const std::string&);
    static size_t getEncodedSize(const Header&, const Properties&, const qpid::types::Variant::Map&, const std::string&);

    static size_t getEncodedSizeForElements(const qpid::types::Variant::Map&);
};
}} // namespace qpid::amqp

#endif  /*!QPID_AMQP_MESSAGEENCODER_H*/