Class: Sparkey::LogWriter

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/sparkey/log_writer.rb

Instance Method Summary collapse

Methods included from Errors

#handle_status

Instance Method Details

#closeObject


42
43
44
45
46
# File 'lib/sparkey/log_writer.rb', line 42

def close
  ptr = FFI::MemoryPointer.new(:pointer).write_pointer(@log_writer_ptr)

  Sparkey::Native.logwriter_close(ptr)
end

#create(filename, compression, block_size) ⇒ Object


4
5
6
7
8
9
10
11
# File 'lib/sparkey/log_writer.rb', line 4

def create(filename, compression, block_size)
  ptr = FFI::MemoryPointer.new(:pointer)
  log_filename = "#{filename}.spl"

  handle_status Sparkey::Native.logwriter_create(ptr, log_filename, compression, block_size)

  @log_writer_ptr = ptr.read_pointer
end

#delete(key) ⇒ Object


31
32
33
34
35
36
# File 'lib/sparkey/log_writer.rb', line 31

def delete(key)
  key_length = key.bytesize
  key_ptr = FFI::MemoryPointer.new(:uint8, key_length).write_bytes(key)

  handle_status Sparkey::Native.logwriter_delete(@log_writer_ptr, key_length, key_ptr)
end

#flushObject


38
39
40
# File 'lib/sparkey/log_writer.rb', line 38

def flush
  handle_status Sparkey::Native.logwriter_flush(@log_writer_ptr)
end

#open(filename) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/sparkey/log_writer.rb', line 13

def open(filename)
  ptr = FFI::MemoryPointer.new(:pointer)
  log_filename = "#{filename}.spl"

  handle_status Sparkey::Native.logwriter_append(ptr, log_filename)
  @log_writer_ptr = ptr.read_pointer
end

#put(key, value) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'lib/sparkey/log_writer.rb', line 21

def put(key, value)
  key_length = key.bytesize
  key_ptr = FFI::MemoryPointer.new(:uint8, key_length).write_bytes(key)

  value_length = value.bytesize
  value_ptr = FFI::MemoryPointer.new(:uint8, value_length).write_bytes(value)

  handle_status Sparkey::Native.logwriter_put(@log_writer_ptr, key_length, key_ptr, value_length, value_ptr)
end