Beispiel #1
0
func NewDescTextFrame(ft FrameType, desc, text string) *DescTextFrame {
	f := NewTextFrame(ft, text)
	nullLength := encodedbytes.EncodingNullLengthForIndex(f.encoding)
	f.size += uint32(len(desc) + nullLength)

	return &DescTextFrame{
		TextFrame:   *f,
		description: desc,
	}
}
Beispiel #2
0
func (f *DescTextFrame) SetEncoding(encoding string) error {
	i := byte(encodedbytes.IndexForEncoding(encoding))
	if i < 0 {
		return errors.New("encoding: invalid encoding")
	}

	descDiff, err := encodedbytes.EncodedDiff(i, f.text, f.encoding, f.text)
	if err != nil {
		return err
	}

	newNullLength := encodedbytes.EncodingNullLengthForIndex(i)
	oldNullLength := encodedbytes.EncodingNullLengthForIndex(f.encoding)
	nullDiff := newNullLength - oldNullLength

	textDiff, err := encodedbytes.EncodedDiff(i, f.description, f.encoding, f.description)
	if err != nil {
		return err
	}

	f.changeSize(descDiff + nullDiff + textDiff)
	f.encoding = i
	return nil
}