-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmessage.cc
More file actions
134 lines (122 loc) · 6.4 KB
/
message.cc
File metadata and controls
134 lines (122 loc) · 6.4 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* 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 "utils.h"
#include <pybind11/chrono.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <sstream>
namespace py = pybind11;
void export_message(py::module_& m) {
using namespace py;
PyDateTime_IMPORT;
MessageBuilder& (MessageBuilder::*MessageBuilderSetContentString)(const std::string&) =
&MessageBuilder::setContent;
class_<MessageBuilder>(m, "MessageBuilder")
.def(init<>())
.def("content", MessageBuilderSetContentString, return_value_policy::reference)
.def("property", &MessageBuilder::setProperty, return_value_policy::reference)
.def("properties", &MessageBuilder::setProperties, return_value_policy::reference)
.def("sequence_id", &MessageBuilder::setSequenceId, return_value_policy::reference)
.def("deliver_after", &MessageBuilder::setDeliverAfter, return_value_policy::reference)
.def("deliver_at", &MessageBuilder::setDeliverAt, return_value_policy::reference)
.def("partition_key", &MessageBuilder::setPartitionKey, return_value_policy::reference)
.def("ordering_key", &MessageBuilder::setOrderingKey, return_value_policy::reference)
.def("event_timestamp", &MessageBuilder::setEventTimestamp, return_value_policy::reference)
.def("replication_clusters", &MessageBuilder::setReplicationClusters, return_value_policy::reference)
.def("disable_replication", &MessageBuilder::disableReplication, return_value_policy::reference)
.def("build", &MessageBuilder::build);
class_<MessageId>(m, "MessageId")
.def(init<int32_t, int64_t, int64_t, int32_t>())
.def("__str__",
[](const MessageId& msgId) {
std::ostringstream oss;
oss << msgId;
return oss.str();
})
.def("__repr__",
[](const MessageId& msgId) {
std::ostringstream oss;
oss << msgId;
return oss.str();
})
.def("__eq__", &MessageId::operator==)
.def("__ne__", &MessageId::operator!=)
.def("__le__", &MessageId::operator<=)
.def("__lt__", &MessageId::operator<)
.def("__ge__", &MessageId::operator>=)
.def("__gt__", &MessageId::operator>)
.def("ledger_id", &MessageId::ledgerId)
.def("entry_id", &MessageId::entryId)
.def("batch_index", &MessageId::batchIndex)
.def("partition", &MessageId::partition)
.def(
"topic_name",
[](MessageId& msgId, const std::string& topicName) { msgId.setTopicName(topicName); },
return_value_policy::copy)
.def_property_readonly_static("earliest", [](object) { return MessageId::earliest(); })
.def_property_readonly_static("latest", [](object) { return MessageId::latest(); })
.def("serialize",
[](const MessageId& msgId) {
std::string serialized;
msgId.serialize(serialized);
return bytes(serialized);
})
.def_static("deserialize", &MessageId::deserialize);
class_<EncryptionKey>(m, "EncryptionKey")
.def_readonly("key", &EncryptionKey::key)
.def("value", [](const EncryptionKey& key) { return bytes(key.value); })
.def_readonly("metadata", &EncryptionKey::metadata);
5CB7
class_<EncryptionContext>(m, "EncryptionContext")
.def("keys", &EncryptionContext::keys)
.def("param", [](const EncryptionContext& context) { return bytes(context.param()); })
.def("algorithm", &EncryptionContext::algorithm, return_value_policy::copy)
.def("compression_type", &EncryptionContext::compressionType)
.def("uncompressed_message_size", &EncryptionContext::uncompressedMessageSize)
.def("batch_size", &EncryptionContext::batchSize)
.def("is_decryption_failed", &EncryptionContext::isDecryptionFailed);
class_<Message>(m, "Message")
.def(init<>())
.def("properties", &Message::getProperties)
.def("data", [](const Message& msg) { return bytes(msg.getDataAsString()); })
.def("length", &Message::getLength)
.def("partition_key", &Message::getPartitionKey, return_value_policy::copy)
.def("ordering_key", &Message::getOrderingKey, return_value_policy::copy)
.def("publish_timestamp", &Message::getPublishTimestamp)
.def("event_timestamp", &Message::getEventTimestamp)
.def("message_id", &Message::getMessageId, return_value_policy::copy)
.def("__str__",
[](const Message& msg) {
std::ostringstream oss;
oss << msg;
return oss.str();
})
.def("topic_name", &Message::getTopicName, return_value_policy::copy)
.def("redelivery_count", &Message::getRedeliveryCount)
.def("int_schema_version", &Message::getLongSchemaVersion)
.def("schema_version", &Message::getSchemaVersion, return_value_policy::copy)
.def("producer_name", &Message::getProducerName, return_value_policy::copy)
.def("encryption_context", &Message::getEncryptionContext, return_value_policy::reference);
MessageBatch& (MessageBatch::*MessageBatchParseFromString)(const std::string& payload,
uint32_t batchSize) = &MessageBatch::parseFrom;
class_<MessageBatch>(m, "MessageBatch")
.def(init<>())
.def("with_message_id", &MessageBatch::withMessageId, return_value_policy::reference)
.def("parse_from", MessageBatchParseFromString, return_value_policy::reference)
.def("messages", &MessageBatch::messages, return_value_policy::copy);
}