Class: PlainBufferOutputStream

Inherits:
Object
  • Object
show all
Defined in:
lib/tablestore/plain_buffer_output_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(capacity) ⇒ PlainBufferOutputStream

Returns a new instance of PlainBufferOutputStream.



4
5
6
7
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 4

def initialize(capacity)
  @buffer = []
  @capacity = capacity
end

Instance Method Details

#clearObject



21
22
23
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 21

def clear
  @buffer.clear
end

#countObject



13
14
15
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 13

def count
  @buffer.length
end

#get_bufferObject



59
60
61
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 59

def get_buffer
  @buffer
end

#is_full?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 9

def is_full?
  @capacity <= @buffer.length
end

#remainObject



17
18
19
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 17

def remain
  @capacity - count
end

#write_boolean(value) ⇒ Object



42
43
44
45
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 42

def write_boolean(value)
  bool_value = value ? 1 : 0
  write_bytes([bool_value].pack("C"))
end

#write_bytes(value) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 47

def write_bytes(value)
  if @buffer.length + value.length > @capacity
    debugger
    raise TableStoreClientError.new("The buffer is full.")
  end
  bytes = ''
  value.to_s.each_byte do |b|
    bytes += [b].pack("C*")
  end
  @buffer << bytes
end

#write_double(value) ⇒ Object



38
39
40
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 38

def write_double(value)
  write_bytes([value].pack("d"))
end

#write_raw_byte(value) ⇒ Object



25
26
27
28
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 25

def write_raw_byte(value)
  raise TableStoreClientError.new("The buffer is full") if is_full?
  @buffer << [value].pack("C*")
end

#write_raw_little_endian32(value) ⇒ Object



30
31
32
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 30

def write_raw_little_endian32(value)
  write_bytes([value].pack("i"))
end

#write_raw_little_endian64(value) ⇒ Object



34
35
36
# File 'lib/tablestore/plain_buffer_output_stream.rb', line 34

def write_raw_little_endian64(value)
  write_bytes([value].pack("q"))
end