From 60d6959198e0ca64e41882b8b59a89a05d549637 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Fri, 24 Jan 2014 23:34:21 -0500 Subject: [PATCH] Add utility for flag bytes --- v2/id3v2.go | 10 +++++----- v2/util.go | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 v2/util.go diff --git a/v2/id3v2.go b/v2/id3v2.go index fc8919b..f61e3b8 100644 --- a/v2/id3v2.go +++ b/v2/id3v2.go @@ -297,12 +297,12 @@ func ParseHeader(reader io.Reader) *Header { switch header.version { case 2: - header.unsynchronization = (header.flags & 1 << 7) == 1 - header.compression = (header.flags & 1 << 6) == 1 + header.unsynchronization = isBitSet(header.flags, 7) + header.compression = isBitSet(header.flags, 6) case 3: - header.unsynchronization = (header.flags & 1 << 7) == 1 - header.extendedHeader = (header.flags & 1 << 6) == 1 - header.experimental = (header.flags & 1 << 5) == 1 + header.unsynchronization = isBitSet(header.flags, 7) + header.extendedHeader = isBitSet(header.flags, 6) + header.experimental = isBitSet(header.flags, 5) } return header diff --git a/v2/util.go b/v2/util.go new file mode 100644 index 0000000..160144a --- /dev/null +++ b/v2/util.go @@ -0,0 +1,8 @@ +// Copyright 2013 Michael Yang. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +package v2 + +func isBitSet(flag, index byte) bool { + return flag&(1<