Source File
leb128.go
Belonging Package
github.com/pion/rtp/codecs/av1/obu
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MIT// Package obu implements tools for working with the Open Bitstream Unit.package obuimportconst (sevenLsbBitmask = uint(0b01111111)msbBitmask = uint(0b10000000))// ErrFailedToReadLEB128 indicates that a buffer ended before a LEB128 value could be successfully read.var ErrFailedToReadLEB128 = errors.New("payload ended before LEB128 was finished")// EncodeLEB128 encodes a uint as LEB128.func ( uint) ( uint) {for {// Copy seven bits from in and discard// what we have copied from in|= ( & sevenLsbBitmask)>>= 7// If we have more bits to encode set MSB// otherwise we are doneif != 0 {|= msbBitmask<<= 8} else {return}}}func decodeLEB128( uint) ( uint) {for {// Take 7 LSB from in|= ( & sevenLsbBitmask)// Discard the MSB>>= 8if == 0 {return}<<= 7}}// ReadLeb128 scans an buffer and decodes a Leb128 value.// If the end of the buffer is reached and all MSB are set// an error is returned.func ( []byte) (uint, uint, error) {var uintfor := range {|= uint([])if []&byte(msbBitmask) == 0 {return decodeLEB128(), uint( + 1), nil // nolint: gosec // G115}// Make more room for next read<<= 8}return 0, 0, ErrFailedToReadLEB128}// WriteToLeb128 writes a uint to a LEB128 encoded byte slice.func ( uint) []byte {:= make([]byte, 10)for := 0; < len(); ++ {[] = byte( & 0x7f)>>= 7if == 0 {return [:+1]}[] |= 0x80}return // unreachable}
![]() |
The pages are generated with Golds v0.8.2. (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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |