Documentation ¶
Overview ¶
Package b64buff implements a bit buffer that can encode bit vectors as URL string.
The bit buffer allows to read and write any number of bits. The encoding is similar to Base64 but different. It has no padding. Currently it cannot be changed.
Example ¶
buffer := Buffer{} buffer.WriteUInt32(0x57, 7) a, _ := buffer.ReadUInt32(3) b, _ := buffer.ReadUInt32(4) fmt.Println(a, b)
Output: 5 7
Index ¶
- Variables
- func RandomString(length uint32) (ret string, err error)
- func RandomUInt32(nbBits uint8) (uint32, error)
- type Buffer
- func (self *Buffer) AlignRead() (ret byte)
- func (self *Buffer) B64Reader() io.Reader
- func (self *Buffer) Len() uint32
- func (self *Buffer) ReadAllB64() (ret string, err error)
- func (self *Buffer) ReadUInt32(nbBits uint8) (ret uint32, err error)
- func (self *Buffer) WriteB64(str string) (err error)
- func (self *Buffer) WriteUInt32(data uint32, nbBits uint8) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func RandomString ¶
RandomString produces a random readable string of the given length. The returned string is a valid B64 encoded random value.
func RandomUInt32 ¶
RandomUInt32 returns a uniform randow value between 0 and 2^nbBits - 1.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a bit buffer.
func (*Buffer) AlignRead ¶
AlignRead forces read to be aligned, by discarding surnumerous bits.
Read is aligned when the number of bits read from the buffer can be divided by 6. The discarded bits are the less significant bits that would have been returned by a call to ReadUInt32. Those bits are returned by the method.
func (*Buffer) B64Reader ¶
B64Reader returns an encoded reader on the Buffer.
Calling Read on the returned value fails if read is not aligned. Read is aligned when the number of bits read from the buffer can be divided by 6.
func (*Buffer) ReadAllB64 ¶
ReadAllB64 reads the whole buffer to the string.
The call fails if read is not aligned. Read is aligned when the number of bits read from the buffer can be divided by 6.
func (*Buffer) ReadUInt32 ¶
ReadUInt32 reads nbBits of the buffer into the lower bits of ret.