From 283f75aa984395bba0bade2c208cc9ba01dc57ab Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 20 May 2016 14:02:54 +0700 Subject: [PATCH] remove unused byte masks from WriteUint functions --- utils/utils.go | 68 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index e47169866..9b8b145fe 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -102,65 +102,65 @@ func ReadUint16(b io.ByteReader) (uint16, error) { // WriteUint64 writes a uint64 func WriteUint64(b *bytes.Buffer, i uint64) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) - b.WriteByte(uint8((i >> 24) & 0xff)) - b.WriteByte(uint8((i >> 32) & 0xff)) - b.WriteByte(uint8((i >> 40) & 0xff)) - b.WriteByte(uint8((i >> 48) & 0xff)) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) + b.WriteByte(uint8(i >> 24)) + b.WriteByte(uint8(i >> 32)) + b.WriteByte(uint8(i >> 40)) + b.WriteByte(uint8(i >> 48)) b.WriteByte(uint8(i >> 56)) } // WriteUint56 writes 56 bit of a uint64 func WriteUint56(b *bytes.Buffer, i uint64) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) - b.WriteByte(uint8((i >> 24) & 0xff)) - b.WriteByte(uint8((i >> 32) & 0xff)) - b.WriteByte(uint8((i >> 40) & 0xff)) - b.WriteByte(uint8((i >> 48))) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) + b.WriteByte(uint8(i >> 24)) + b.WriteByte(uint8(i >> 32)) + b.WriteByte(uint8(i >> 40)) + b.WriteByte(uint8(i >> 48)) } // WriteUint48 writes 48 bit of a uint64 func WriteUint48(b *bytes.Buffer, i uint64) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) - b.WriteByte(uint8((i >> 24) & 0xff)) - b.WriteByte(uint8((i >> 32) & 0xff)) - b.WriteByte(uint8((i >> 40))) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) + b.WriteByte(uint8(i >> 24)) + b.WriteByte(uint8(i >> 32)) + b.WriteByte(uint8(i >> 40)) } // WriteUint40 writes 40 bit of a uint64 func WriteUint40(b *bytes.Buffer, i uint64) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) - b.WriteByte(uint8((i >> 24) & 0xff)) - b.WriteByte(uint8((i >> 32))) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) + b.WriteByte(uint8(i >> 24)) + b.WriteByte(uint8(i >> 32)) } // WriteUint32 writes a uint32 func WriteUint32(b *bytes.Buffer, i uint32) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) - b.WriteByte(uint8((i >> 24) & 0xff)) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) + b.WriteByte(uint8(i >> 24)) } // WriteUint24 writes 24 bit of a uint32 func WriteUint24(b *bytes.Buffer, i uint32) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) - b.WriteByte(uint8((i >> 16) & 0xff)) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) + b.WriteByte(uint8(i >> 16)) } // WriteUint16 writes a uint16 func WriteUint16(b *bytes.Buffer, i uint16) { - b.WriteByte(uint8(i & 0xff)) - b.WriteByte(uint8((i >> 8) & 0xff)) + b.WriteByte(uint8(i)) + b.WriteByte(uint8(i >> 8)) } // RandomBit returns a cryptographically secure random bit (encoded as true / false)