Class: Xbd::Asi
- Inherits:
-
Object
show all
- Defined in:
- lib/xbd/asi.rb
Overview
********************************* Xbd::Asi module *********************************
Read and Generate ASI strings
Defined Under Namespace
Modules: Bignum, Fixnum, IO, String
Constant Summary
collapse
- ASI_INSTANCE =
Asi.new
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.asi_length(num) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/xbd/asi.rb', line 96
def Asi.asi_length(num)
count=1
while num>=0x80
num>>=7
count+=1
end
count
end
|
.asi_to_i(source) ⇒ Object
49
50
51
|
# File 'lib/xbd/asi.rb', line 49
def Asi.asi_to_i(source)
Asi.read_asi(source,0)[0]
end
|
.i_to_asi2(num) ⇒ Object
78
79
80
|
# File 'lib/xbd/asi.rb', line 78
def Asi.i_to_asi2(num)
ASI_INSTANCE.i_to_asi_c(num)
end
|
.i_to_asi_ruby(num) ⇒ Object
Also known as:
i_to_asi
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/xbd/asi.rb', line 82
def Asi.i_to_asi_ruby(num)
ret=""
while ret.length==0 || num>0
val=num & 0x7F;
num=num>>7
val|=0x80 if num>0
ret<<val
end
ret
end
|
.read_asi(source, index = 0) ⇒ Object
read an ASI from a string, returning an integer optionally starts and the specified offset index.
returns the number read and the first index after the ASI data in the string.
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/xbd/asi.rb', line 18
def Asi.read_asi(source,index=0)
ret=0
shift=0
val=0
while index<source.length
val=source.byte(index)
ret+= (val & 0x7F) << shift;
shift+=7
index+=1
break if val<128
end
return ret,index
end
|
.read_asi_from_file(file) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/xbd/asi.rb', line 37
def Asi.read_asi_from_file(file)
ret=0
shift=0
val=0
while val=file.readbyte
ret+= (val & 0x7F) << shift;
shift+=7
break if val<128
end
return ret
end
|
.read_asi_string(source, index = 0) ⇒ Object
32
33
34
35
|
# File 'lib/xbd/asi.rb', line 32
def Asi.read_asi_string(source,index=0)
n,index=read_asi(source,index)
return source[index,n],index+n
end
|
Instance Method Details
#i_to_asi_c(num) ⇒ Object
72
73
74
|
# File 'lib/xbd/asi.rb', line 72
def i_to_asi_c(num)
Asi.i_to_asi_ruby(num)
end
|