rabbitmq 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6084d87d4d4379929fbae34f8a6d7e8f979f176
4
- data.tar.gz: 6312eaee4b20b758986c03fa8e448f763e03cb61
3
+ metadata.gz: 7ea9090c210d60db3bf5571f6408f9a91a9fe158
4
+ data.tar.gz: b5c814e43a019e30bd803216b258f90c29510e6e
5
5
  SHA512:
6
- metadata.gz: 0de8d7059d8117341d3605ce4f58463fb912dc581572821cd9b3bcc80f82b3a5cb0ecfc5c3540dae0c6aeea1071027e4d6bc366ae651e04a76d9c60b788e836f
7
- data.tar.gz: e09ce58387e226cd673b51a32934cb8456ba9eaddb00031cafddb7fafa84ea8acbd5657789645eb3388954c24072cf6a25b8e564f38071a7b3a60f2c91e0961d
6
+ metadata.gz: 26478dc891d275f8a8fe7b2ce5112974ce0c7d2fc7c54a7edbd9f2fe15ceb33a13193c8b2dacd12423840beb577aa772bd0091cfd2f1af88e6f9af305dd2fd50
7
+ data.tar.gz: 9d0dd89cbe2170c473f89f5f2e137df725187401a2ff29165828c475b7b56dfc6b5dd204c085442837e7c41bf3fcea945c176218cc1d140546e44dd8eda46327
@@ -227,20 +227,19 @@ module RabbitMQ
227
227
  exchange = FFI::Bytes.from_s(exchange, true)
228
228
  routing_key = FFI::Bytes.from_s(routing_key, true)
229
229
  properties = FFI::BasicProperties.new.apply(
230
- content_type: opts.fetch(:content_type, "application/octet-stream"),
231
- content_encoding: opts.fetch(:content_encoding, ""),
232
- headers: opts.fetch(:headers, {}),
233
- delivery_mode: (opts.fetch(:persistent, false) ? :persistent : :nonpersistent),
234
- priority: opts.fetch(:priority, 0),
235
- correlation_id: opts.fetch(:correlation_id, ""),
236
- reply_to: opts.fetch(:reply_to, ""),
237
- expiration: opts.fetch(:expiration, ""),
238
- message_id: opts.fetch(:message_id, ""),
239
- timestamp: opts.fetch(:timestamp, 0),
240
- type: opts.fetch(:type, ""),
241
- user_id: opts.fetch(:user_id, ""),
242
- app_id: opts.fetch(:app_id, ""),
243
- cluster_id: opts.fetch(:cluster_id, "")
230
+ content_type: opts.fetch(:content_type, nil),
231
+ content_encoding: opts.fetch(:content_encoding, nil),
232
+ headers: opts.fetch(:headers, {}),
233
+ delivery_mode: (opts.fetch(:persistent, false) ? :persistent : :nonpersistent),
234
+ priority: opts.fetch(:priority, 0),
235
+ correlation_id: opts.fetch(:correlation_id, nil),
236
+ reply_to: opts.fetch(:reply_to, nil),
237
+ expiration: opts.fetch(:expiration, nil),
238
+ message_id: opts.fetch(:message_id, nil),
239
+ timestamp: opts.fetch(:timestamp, 0),
240
+ type: opts.fetch(:type, nil),
241
+ app_id: opts.fetch(:app_id, nil),
242
+ cluster_id: opts.fetch(:cluster_id, nil)
244
243
  )
245
244
 
246
245
  Util.error_check :"publishing a message",
data/lib/rabbitmq/ffi.rb CHANGED
@@ -696,6 +696,23 @@ module RabbitMQ
696
696
  :user_id, Bytes,
697
697
  :app_id, Bytes,
698
698
  :cluster_id, Bytes
699
+
700
+ FLAGS = {
701
+ content_type: (1 << 15),
702
+ content_encoding: (1 << 14),
703
+ headers: (1 << 13),
704
+ delivery_mode: (1 << 12),
705
+ priority: (1 << 11),
706
+ correlation_id: (1 << 10),
707
+ reply_to: (1 << 9),
708
+ expiration: (1 << 8),
709
+ message_id: (1 << 7),
710
+ timestamp: (1 << 6),
711
+ type: (1 << 5),
712
+ user_id: (1 << 4),
713
+ app_id: (1 << 3),
714
+ cluster_id: (1 << 2),
715
+ }
699
716
  end
700
717
 
701
718
  attach_function :amqp_channel_open, [ConnectionState, Channel], ChannelOpenOk.ptr, **opts
@@ -181,11 +181,12 @@ module RabbitMQ
181
181
  module MethodClassMixin
182
182
  def apply(borrow=false, **params)
183
183
  params.each do |key, value|
184
- next if key == :dummy
184
+ next if value.nil? || !writable_key?(key)
185
185
  case value
186
186
  when String; value = FFI::Bytes.from_s(value, borrow)
187
187
  when Hash; value = FFI::Table.from(value, borrow)
188
188
  end
189
+ key_applied_hook(key)
189
190
  self[key] = value
190
191
  end
191
192
  self
@@ -194,7 +195,7 @@ module RabbitMQ
194
195
  def to_h(free=false)
195
196
  result = {}
196
197
  self.members.each do |key| [key, self[key]]
197
- next if key == :dummy
198
+ next unless readable_key?(key)
198
199
  value = self[key]
199
200
  case value
200
201
  when FFI::Bytes; value = value.to_s(free)
@@ -219,12 +220,43 @@ module RabbitMQ
219
220
  end
220
221
  clear
221
222
  end
223
+
224
+ def key_applied_hook(key)
225
+ # do nothing here
226
+ end
227
+
228
+ def readable_key?(key)
229
+ key != :dummy
230
+ end
231
+
232
+ def writable_key?(key)
233
+ key != :dummy
234
+ end
222
235
  end
223
236
 
224
237
  Method::MethodClasses.each { |_, kls| kls.send(:include, MethodClassMixin) }
225
238
 
226
239
  BasicProperties.send(:include, MethodClassMixin)
227
240
 
241
+ class BasicProperties
242
+ def key_applied_hook(key)
243
+ flag_bit = FLAGS[key]
244
+ return unless flag_bit
245
+ self[:_flags] = (self[:_flags] | flag_bit)
246
+ end
247
+
248
+ def readable_key?(key)
249
+ return false if key == :_flags
250
+ flag_bit = FLAGS[key]
251
+ return true unless flag_bit
252
+ return (flag_bit & self[:_flags]) != 0
253
+ end
254
+
255
+ def writable_key?(key)
256
+ true
257
+ end
258
+ end
259
+
228
260
  class FramePayloadProperties
229
261
  def decoded
230
262
  BasicProperties.new(self[:decoded])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe McIlvain