Source File
bytereader.go
Belonging Package
github.com/klauspost/compress/zstd
// Copyright 2019+ Klaus Post. All rights reserved.// License information can be found in the LICENSE file.// Based on work by Yann Collet, released under BSD License.package zstd// byteReader provides a byte reader that reads// little endian values from a byte stream.// The input stream is manually advanced.// The reader performs no bounds checks.type byteReader struct {b []byteoff int}// advance the stream b n bytes.func ( *byteReader) ( uint) {.off += int()}// overread returns whether we have advanced too far.func ( *byteReader) () bool {return .off > len(.b)}// Int32 returns a little endian int32 starting at current offset.func ( byteReader) () int32 {:= .b[.off:]= [:4]:= int32([3]):= int32([2]):= int32([1]):= int32([0])return | ( << 8) | ( << 16) | ( << 24)}// Uint8 returns the next bytefunc ( *byteReader) () uint8 {:= .b[.off]return}// Uint32 returns a little endian uint32 starting at current offset.func ( byteReader) () uint32 {if := .remain(); < 4 {// Very rare:= uint32(0)for := 1; <= ; ++ {= ( << 8) | uint32(.b[len(.b)-])}return}:= .b[.off:]= [:4]:= uint32([3]):= uint32([2]):= uint32([1]):= uint32([0])return | ( << 8) | ( << 16) | ( << 24)}// Uint32NC returns a little endian uint32 starting at current offset.// The caller must be sure if there are at least 4 bytes left.func ( byteReader) () uint32 {:= .b[.off:]= [:4]:= uint32([3]):= uint32([2]):= uint32([1]):= uint32([0])return | ( << 8) | ( << 16) | ( << 24)}// unread returns the unread portion of the input.func ( byteReader) () []byte {return .b[.off:]}// remain will return the number of bytes remaining.func ( byteReader) () int {return len(.b) - .off}
![]() |
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. |