Class: PlainBufferInputStream

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

Instance Method Summary collapse

Constructor Details

#initialize(data_buffer) ⇒ PlainBufferInputStream

Returns a new instance of PlainBufferInputStream.



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

def initialize(data_buffer)
  @buffer = data_buffer
  @cur_pos = 0
  @last_tag = 0
end

Instance Method Details

#bufferObject



91
92
93
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 91

def buffer
  @buffer
end

#check_last_tag_was(tag) ⇒ Object



23
24
25
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 23

def check_last_tag_was(tag)
  @last_tag.ord == tag
end

#cur_posObject



87
88
89
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 87

def cur_pos
  @cur_pos
end

#get_last_tagObject



27
28
29
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 27

def get_last_tag
  @last_tag.ord
end

#is_at_end?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 10

def is_at_end?
  @buffer.length == @cur_pos
end

#last_tagObject



83
84
85
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 83

def last_tag
  @last_tag
end

#read_booleanObject



50
51
52
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 50

def read_boolean
  read_bytes(1).unpack('C')[0] == 1
end

#read_bytes(size) ⇒ Object



66
67
68
69
70
71
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 66

def read_bytes(size)
  raise TableStoreClientError.new("Read bytes encountered EOF.") if @buffer.length - @cur_pos < size
  tmp_pos = @cur_pos
  @cur_pos += size
  @buffer[tmp_pos, size]
end

#read_doubleObject



54
55
56
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 54

def read_double
  read_bytes(8).unpack('q<')[0]
end

#read_int32Object



58
59
60
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 58

def read_int32
  read_bytes(4).unpack('i<')[0]
end

#read_int64Object



62
63
64
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 62

def read_int64
  read_bytes(8).unpack('q<')[0]
end

#read_raw_byteObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 31

def read_raw_byte
  raise TableStoreClientError.new("Read raw byte encountered EOF.") if is_at_end?
  pos = @cur_pos
  @cur_pos += 1
  if @buffer[pos].is_a?(Fixnum)
    [@buffer[pos]].chr
  else
    @buffer[pos]
  end
end

#read_raw_little_endian32Object



46
47
48
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 46

def read_raw_little_endian32
  read_bytes(4).unpack('i<')[0]
end

#read_raw_little_endian64Object



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

def read_raw_little_endian64
  read_bytes(8).unpack('q<')[0]
end

#read_tagObject



14
15
16
17
18
19
20
21
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 14

def read_tag
  if is_at_end?
    @last_tag = 0
    return 0
  end
  @last_tag = read_raw_byte
  @last_tag.ord
end

#read_utf_string(size) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/tablestore/plain_buffer_input_stream.rb', line 73

def read_utf_string(size)
  raise TableStoreClientError.new("Read bytes encountered EOF.") if @buffer.length - @cur_pos < size
  utf_str = @buffer[@cur_pos, size]
  @cur_pos += size
  if utf_str.is_a?(String)
    utf_str = utf_str.force_encoding('UTF-8')
  end
  utf_str
end