Source File
write_bits.go
Belonging Package
github.com/andybalholm/brotli
package brotliimport/* Copyright 2010 Google Inc. All Rights Reserved.Distributed under MIT license.See file LICENSE for detail or copy at https://opensource.org/licenses/MIT*//* Write bits into a byte array. *//* This function writes bits into bytes in increasing addresses, and withina byte least-significant-bit first.The function can write up to 56 bits in one go with WriteBitsExample: let's assume that 3 bits (Rs below) have been written already:BYTE-0 BYTE+1 BYTE+20000 0RRR 0000 0000 0000 0000Now, we could write 5 or less bits in MSB by just sifting by 3and OR'ing to BYTE-0.For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,and locate the rest in BYTE+1, BYTE+2, etc. */func writeBits( uint, uint64, *uint, []byte) {/* This branch of the code can write up to 56 bits at a time,7 bits are lost by being perhaps already in *p and at least1 bit is needed to initialize the bit-stream ahead (i.e. if 7bits are in *p and we write 57 bits, then the next write willaccess a byte that was never initialized). */:= [*>>3:]:= uint64([0])|= << (* & 7)binary.LittleEndian.PutUint64(, )* +=}func writeSingleBit( bool, *uint, []byte) {if {writeBits(1, 1, , )} else {writeBits(1, 0, , )}}func writeBitsPrepareStorage( uint, []byte) {assert(&7 == 0)[>>3] = 0}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |