1
// Copyright 2018 Klaus Post. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
// Based on work Copyright (c) 2013, Yann Collet, released under BSD License.
8
// byteReader provides a byte reader that reads
9
// little endian values from a byte stream.
10
// The input stream is manually advanced.
11
// The reader performs no bounds checks.
12
type byteReader struct {
17
// init will initialize the reader and set the input.
18
func (b *byteReader) init(in []byte) {
23
// advance the stream b n bytes.
24
func (b *byteReader) advance(n uint) {
28
// Int32 returns a little endian int32 starting at current offset.
29
func (b byteReader) Int32() int32 {
30
v3 := int32(b.b[b.off+3])
31
v2 := int32(b.b[b.off+2])
32
v1 := int32(b.b[b.off+1])
33
v0 := int32(b.b[b.off])
34
return (v3 << 24) | (v2 << 16) | (v1 << 8) | v0
37
// Uint32 returns a little endian uint32 starting at current offset.
38
func (b byteReader) Uint32() uint32 {
39
v3 := uint32(b.b[b.off+3])
40
v2 := uint32(b.b[b.off+2])
41
v1 := uint32(b.b[b.off+1])
42
v0 := uint32(b.b[b.off])
43
return (v3 << 24) | (v2 << 16) | (v1 << 8) | v0
46
// unread returns the unread portion of the input.
47
func (b byteReader) unread() []byte {
51
// remain will return the number of bytes remaining.
52
func (b byteReader) remain() int {
53
return len(b.b) - b.off