1 QuestHelper_File
["collect_bitstream.lua"] = "Development Version"
2 QuestHelper_Loadtime
["collect_bitstream.lua"] = GetTime()
6 local function Output(outbits
)
12 append
= function (self
, value
, bits
)
13 self
.cbits
= self
.cbits
+ bits
14 self
.cval
= bit
.lshift(self
.cval
, bits
)
15 self
.cval
= self
.cval
+ value
16 while self
.cbits
>= outbits
do
17 Merger
.Add(self
.r
, strchar(bit
.rshift(self
.cval
, self
.cbits
- outbits
)))
18 self
.cbits
= self
.cbits
- outbits
19 self
.cval
= bit
.band(self
.cval
, bit
.lshift(1, self
.cbits
) - 1)
22 finish
= function (self
)
23 if self
.cbits
> 0 then self
:append(0, outbits
- self
.cbits
) end
24 return Merger
.Finish(self
.r
)
29 local function Input(indata
, outbits
)
35 depend
= function (self
, bits
)
36 while self
.cbits
< bits
do
37 self
.cbits
= self
.cbits
+ outbits
38 self
.cval
= bit
.lshift(self
.cval
, outbits
) + strbyte(indata
, self
.coffset
)
39 self
.coffset
= self
.coffset
+ 1
41 local rv
= bit
.rshift(self
.cval
, self
.cbits
- bits
)
42 self
.cbits
= self
.cbits
- bits
;
43 self
.cval
= bit
.band(self
.cval
, bit
.lshift(1, self
.cbits
) - 1)
49 function QH_Collect_Bitstream_Init(_
, API
)
50 Merger
= API
.Utility_Merger
51 QuestHelper
: Assert(Merger
)
53 API
.Utility_Bitstream
= {Input
= Input
, Output
= Output
}