Sha256: 59bc4b73a7366117cfffa5f12ff098a3c90fb907d3aa84cd72564b31231480c2

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

dojo.provide("dojox.encoding.bits");

dojox.encoding.bits.OutputStream = function(){
	this.reset();
};

dojo.extend(dojox.encoding.bits.OutputStream, {
	reset: function(){
		this.buffer = [];
		this.accumulator = 0;
		this.available = 8;
	},
	putBits: function(value, width){
		while(width){
			var w = Math.min(width, this.available);
			var v = (w <= width ? value >>> (width - w) : value) << (this.available - w);
			this.accumulator |= v & (255 >>> (8 - this.available));
			this.available -= w;
			if(!this.available){
				this.buffer.push(this.accumulator);
				this.accumulator = 0;
				this.available = 8;
			}
			width -= w;
		}
	},
	getWidth: function(){
		return this.buffer.length * 8 + (8 - this.available);
	},
	getBuffer: function(){
		var b = this.buffer;
		if(this.available < 8){ b.push(this.accumulator & (255 << this.available)); }
		this.reset();
		return b;
	}
});

dojox.encoding.bits.InputStream = function(buffer, width){
	this.buffer = buffer;
	this.width = width;
	this.bbyte = this.bit = 0;
};

dojo.extend(dojox.encoding.bits.InputStream, {
	getBits: function(width){
		var r = 0;
		while(width){
			var w = Math.min(width, 8 - this.bit);
			var v = this.buffer[this.bbyte] >>> (8 - this.bit - w);
			r <<= w;
			r |= v & ~(~0 << w);
			this.bit += w;
			if(this.bit == 8){
				++this.bbyte;
				this.bit = 0;
			}
			width -= w;
		}
		return r;
	},
	getWidth: function(){
		return this.width - this.bbyte * 8 - this.bit;
	}
});

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dojo_src-1.5.0 dojo/dojox/encoding/bits.js
dojo_src-1.4.3 dojo/dojox/encoding/bits.js
dojo_src-1.4.102 dojo/dojox/encoding/bits.js
dojo-pkg-1.132.0 data/dojo-release-1.3.2-src/dojox/encoding/bits.js
dojo-pkg-1.111.0 data/dojo-release-1.1.1-src/dojox/encoding/bits.js
dojo-pkg-1.120.0 data/dojo-release-1.2.0-src/dojox/encoding/bits.js
dojo-pkg-1.121.0 data/dojo-release-1.2.1-src/dojox/encoding/bits.js
dojo-pkg-1.122.0 data/dojo-release-1.2.2-src/dojox/encoding/bits.js
dojo-pkg-1.123.0 data/dojo-release-1.2.3-src/dojox/encoding/bits.js
dojo-pkg-1.130.0 data/dojo-release-1.3.0-src/dojox/encoding/bits.js
dojo-pkg-1.131.0 data/dojo-release-1.3.1-src/dojox/encoding/bits.js