Exemple #1
0
        public override bool Push(bool bit)
        {
            this.byteBuffer |= (ushort)(Convert.ToUInt16(bit) << this.waitingBits);
            if (++this.waitingBits >= 16)
            {
                LittleEndian.Write2(this.stream, this.byteBuffer);
                this.waitingBits = 0;
                this.byteBuffer  = 0;
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public override bool Flush(bool unchanged)
        {
            if (this.waitingBits != 0)
            {
                if (!unchanged)
                {
                    this.byteBuffer <<= 16 - this.waitingBits;
                }

                LittleEndian.Write2(this.stream, this.byteBuffer);
                this.waitingBits = 0;
                return(true);
            }

            return(false);
        }
Exemple #3
0
        public override bool Write(ushort data, int size)
        {
            if (this.waitingBits + size >= 16)
            {
                int delta = 16 - this.waitingBits;
                this.waitingBits = (this.waitingBits + size) % 16;
                ushort bits = (ushort)((this.byteBuffer << delta) | (data >> this.waitingBits));
                LittleEndian.Write2(this.stream, bits);
                this.byteBuffer = data;
                return(true);
            }

            this.byteBuffer <<= size;
            this.byteBuffer  |= data;
            this.waitingBits += size;
            return(false);
        }