Class: Ariblib::BitStream

Inherits:
Object
  • Object
show all
Defined in:
lib/ariblib/BitStream.rb

Overview

ビットストリーム

Instance Method Summary collapse

Constructor Details

#initialize(buf) ⇒ BitStream

Returns a new instance of BitStream.



8
9
10
11
# File 'lib/ariblib/BitStream.rb', line 8

def initialize(buf)
	@bitstream_buffer=buf||("".encode("BINARY"))
	@bitstream_postion=0
end

Instance Method Details

#bufObject



55
56
57
# File 'lib/ariblib/BitStream.rb', line 55

def buf
	@bitstream_buffer
end

#buf=(a) ⇒ Object



58
59
60
# File 'lib/ariblib/BitStream.rb', line 58

def buf=(a)
	@bitstream_buffer=a
end

#get3Object



30
31
32
33
34
35
36
37
# File 'lib/ariblib/BitStream.rb', line 30

def get3
	len=@bitstream_postion/8
	@bitstream_postion+=8*3
	ret =@bitstream_buffer.getbyte(len  ) << 16
	ret|=@bitstream_buffer.getbyte(len+1) <<  8
	ret|=@bitstream_buffer.getbyte(len+2)
	ret
end

#getcObject



17
18
19
20
21
22
# File 'lib/ariblib/BitStream.rb', line 17

def getc
	len=@bitstream_postion/8
	@bitstream_postion+=8
	ret =@bitstream_buffer.getbyte(len  )
	ret
end

#getsObject



23
24
25
26
27
28
29
# File 'lib/ariblib/BitStream.rb', line 23

def gets
	len=@bitstream_postion/8
	@bitstream_postion+=8*2
	ret =@bitstream_buffer.getbyte(len  ) <<  8
	ret|=@bitstream_buffer.getbyte(len+1)
	ret
end

#lestObject



52
53
54
# File 'lib/ariblib/BitStream.rb', line 52

def lest
	@bitstream_buffer.size*8-@bitstream_postion
end

#posObject



61
62
63
# File 'lib/ariblib/BitStream.rb', line 61

def pos
	@bitstream_postion
end

#pos=(a) ⇒ Object



64
65
66
# File 'lib/ariblib/BitStream.rb', line 64

def pos=(a)
	@bitstream_postion=a
end

#read(size) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ariblib/BitStream.rb', line 38

def read(size)
	pos =@bitstream_postion>>3
	modd=@bitstream_postion&0x07
	@bitstream_postion+=size
	mod =((~(@bitstream_postion)).succ)&0x07
	poss=((size+modd+7)>>3)
	tmp=0
	poss.times do |i|
		tmp<<=8
		tmp|=@bitstream_buffer.getbyte(pos+i)
	end
	tmpd = (tmp>>mod) & ((1<<size)-1)
	return tmpd
end

#str(byte) ⇒ Object



12
13
14
15
16
# File 'lib/ariblib/BitStream.rb', line 12

def str(byte)
		ret=@bitstream_buffer.byteslice(@bitstream_postion/8,byte)
		@bitstream_postion+=byte*8
		ret
end