From 70085d5ef499cd11ccae3aadd6967004fbe36900 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 6 Aug 2016 12:33:26 -0400 Subject: [PATCH] de-methodize these things --- bit/reader.go | 8 ++++---- parser.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bit/reader.go b/bit/reader.go index 0e8446e..efe6ef1 100644 --- a/bit/reader.go +++ b/bit/reader.go @@ -89,6 +89,8 @@ func (r *Reader) DiscardBytes(n int) { } } +func (r *Reader) Err() error { return r.err } + // ReadUbitVar reads a prefixed uint value. A prefix is 2 bits wide, followed // by the 4 least-significant bits, then a variable number of most-significant // bits based on the prefix. @@ -97,7 +99,7 @@ func (r *Reader) DiscardBytes(n int) { // 01 - 8 // 10 - 12 (why 12? this really baffles me) // 11 - 32 -func (r *Reader) ReadUBitVar() uint64 { +func ReadUBitVar(r *Reader) uint64 { switch b := r.ReadBits(6); b >> 4 { case 0: return b & 0xf @@ -116,7 +118,7 @@ func (r *Reader) ReadUBitVar() uint64 { // representation used by Protobuf. Each byte contributes 7 bits to the value // in little-endian order. The most-significant bit of each byte represents a // continuation bit. -func (r *Reader) ReadVarInt() uint64 { +func ReadVarInt(r *Reader) uint64 { var ( x uint64 b uint64 @@ -134,5 +136,3 @@ func (r *Reader) ReadVarInt() uint64 { } return x } - -func (r *Reader) Err() error { return r.err } diff --git a/parser.go b/parser.go index a1be3d5..a1443bc 100644 --- a/parser.go +++ b/parser.go @@ -70,8 +70,8 @@ func (p *parser) run(out chan maybe) { func (p *parser) emitChildren(pkt *dota.CDemoPacket, c chan maybe) { br := bit.NewBytesReader(pkt.GetData()) for { - t := entityType(br.ReadUBitVar()) - s := br.ReadVarInt() + t := entityType(bit.ReadUBitVar(br)) + s := bit.ReadVarInt(br) if p.ewl[t] { br.Read(p.scratch[:s])