Class: RabbitMQ::FFI::Bytes Private

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/rabbitmq/ffi.rb,
lib/rabbitmq/ffi/ext/bytes.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_s(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
26
# File 'lib/rabbitmq/ffi/ext/bytes.rb', line 19

def self.from_s(str)
  size = str.bytesize
  bytes = FFI.amqp_bytes_malloc(size)
  
  bytes[:bytes].write_string(str)
  bytes[:len] = size
  bytes
end

Instance Method Details

#free!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
# File 'lib/rabbitmq/ffi/ext/bytes.rb', line 14

def free!
  FFI.free(self[:bytes])
  clear
end

#to_s(free = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
9
10
11
12
# File 'lib/rabbitmq/ffi/ext/bytes.rb', line 6

def to_s(free=false)
  size = self[:len]
  s = size == 0 ? "" : self[:bytes].read_bytes(size)
  s.force_encoding(Encoding::ASCII_8BIT)
  free! if free
  s
end