Class: Hprose::RawReader

Inherits:
Object
  • Object
show all
Includes:
Stream, Tags
Defined in:
lib/hprose/io.rb

Direct Known Subclasses

Reader

Constant Summary

Constants included from Tags

Tags::TagArgument, Tags::TagBytes, Tags::TagCall, Tags::TagClass, Tags::TagClosebrace, Tags::TagDate, Tags::TagDouble, Tags::TagEmpty, Tags::TagEnd, Tags::TagError, Tags::TagFalse, Tags::TagFunctions, Tags::TagGuid, Tags::TagInfinity, Tags::TagInteger, Tags::TagList, Tags::TagLong, Tags::TagMap, Tags::TagNaN, Tags::TagNeg, Tags::TagNine, Tags::TagNull, Tags::TagObject, Tags::TagOpenbrace, Tags::TagPoint, Tags::TagPos, Tags::TagQuote, Tags::TagRef, Tags::TagResult, Tags::TagSemicolon, Tags::TagString, Tags::TagTime, Tags::TagTrue, Tags::TagUTC, Tags::TagUTF8Char, Tags::TagZero

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stream

#readint, #readuntil

Constructor Details

#initialize(stream) ⇒ RawReader

Returns a new instance of RawReader.



244
245
246
# File 'lib/hprose/io.rb', line 244

def initialize(stream)
  @stream = stream
end

Instance Attribute Details

#streamObject

Returns the value of attribute stream.



247
248
249
# File 'lib/hprose/io.rb', line 247

def stream
  @stream
end

Instance Method Details

#read_raw(ostream = nil, tag = nil) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/hprose/io.rb', line 257

def read_raw(ostream = nil, tag = nil)
  ostream = StringIO.new if ostream.nil?
  tag = @stream.getbyte if tag.nil?
  ostream.putc(tag)
  case tag
  when TagZero..TagNine, TagNull, TagEmpty, TagTrue, TagFalse, TagNaN then {}
  when TagInfinity then ostream.putc(@stream.getbyte())
  when TagInteger, TagLong, TagDouble, TagRef then read_number_raw(ostream)
  when TagDate, TagTime then read_datetime_raw(ostream)
  when TagUTF8Char then read_utf8char_raw(ostream)
  when TagBytes then read_bytes_raw(ostream)
  when TagString then read_string_raw(ostream)
  when TagGuid then read_guid_raw(ostream)
  when TagList, TagMap, TagObject then read_complex_raw(ostream)
  when TagClass then read_complex_raw(ostream); read_raw(ostream)
  when TagError then read_raw(ostream)
  else unexpected_tag(tag)
  end
  return ostream
end

#unexpected_tag(tag, expect_tag = nil) ⇒ Object



248
249
250
251
252
253
254
255
256
# File 'lib/hprose/io.rb', line 248

def unexpected_tag(tag, expect_tag = nil)
  if tag.nil? then
    raise Exception.exception("No byte found in stream")
  elsif expect_tag.nil? then
    raise Exception.exception("Unexpected serialize tag '#{tag.chr}' in stream")
  else
    raise Exception.exception("Tag '#{expect_tag}' expected, but '#{tag.chr}' found in stream")
  end
end