示例#1
0
文件: frame.go 项目: viking/id3-go
func (f *ImageFrame) SetEncoding(encoding string) error {
	i := byte(encodedbytes.IndexForEncoding(encoding))
	if i < 0 {
		return errors.New("encoding: invalid encoding")
	}

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

	f.changeSize(diff)
	f.encoding = i
	return nil
}
示例#2
0
文件: frame.go 项目: viking/id3-go
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
}