Clean tag and frame header bytes methods

develop
Michael Yang 2014-01-19 11:06:29 -05:00
rodzic 1052d2f5ca
commit e6fdcb2297
3 zmienionych plików z 11 dodań i 14 usunięć

Wyświetl plik

@ -328,13 +328,11 @@ func (h Header) Size() int {
}
func (h Header) Bytes() []byte {
data := make([]byte, HeaderSize)
data := make([]byte, 0, HeaderSize)
copy(data[:3], []byte("ID3"))
copy(data[6:], encodedbytes.SynchBytes(h.size))
data[3] = h.version
data[4] = h.revision
data[5] = h.flags
data = append(data, "ID3"...)
data = append(data, h.version, h.revision, h.flags)
data = append(data, encodedbytes.SynchBytes(h.size)...)
return data
}

Wyświetl plik

@ -122,10 +122,10 @@ func ParseV22Frame(reader io.Reader) Framer {
}
func V22Bytes(f Framer) []byte {
headBytes := make([]byte, V22FrameHeaderSize)
headBytes := make([]byte, 0, V22FrameHeaderSize)
copy(headBytes[:3], []byte(f.Id()))
copy(headBytes[3:6], encodedbytes.NormBytes(uint32(f.Size()))[1:])
headBytes = append(headBytes, f.Id()...)
headBytes = append(headBytes, encodedbytes.NormBytes(uint32(f.Size()))[1:]...)
return append(headBytes, f.Bytes()...)
}

Wyświetl plik

@ -150,12 +150,11 @@ func ParseV23Frame(reader io.Reader) Framer {
}
func V23Bytes(f Framer) []byte {
headBytes := make([]byte, FrameHeaderSize)
headBytes := make([]byte, 0, FrameHeaderSize)
copy(headBytes[:4], []byte(f.Id()))
copy(headBytes[4:8], encodedbytes.NormBytes(uint32(f.Size())))
headBytes[8] = f.StatusFlags()
headBytes[9] = f.FormatFlags()
headBytes = append(headBytes, f.Id()...)
headBytes = append(headBytes, encodedbytes.NormBytes(uint32(f.Size()))...)
headBytes = append(headBytes, f.StatusFlags(), f.FormatFlags())
return append(headBytes, f.Bytes()...)
}