Struct id3::frame::Frame
[−]
[src]
pub struct Frame { pub uuid: Vec<u8>, pub id: String, pub encoding: Encoding, pub content: Content, pub offset: u32, // some fields omitted }
A structure representing an ID3 frame.
Fields
uuid: Vec<u8>
A sequence of 16 bytes used to uniquely identify this frame.
id: String
The frame identifier.
encoding: Encoding
The preferred encoding to be used when converting this frame to bytes.
content: Content
The parsed content of the frame.
offset: u32
The offset of this frame in the file from which it was loaded.
Methods
impl Frame
[src]
fn new<T: Into<String>>(id: T) -> Frame
Creates a new ID3v2.3 frame with the specified identifier.
fn compression(&self) -> bool
Returns whether the compression flag is set.
fn set_compression(&mut self, compression: bool)
Sets the compression flag.
fn tag_alter_preservation(&self) -> bool
Returns whether the tag_alter_preservation flag is set.
fn set_tag_alter_preservation(&mut self, tag_alter_preservation: bool)
Sets the tag_alter_preservation flag.
fn file_alter_preservation(&self) -> bool
Returns whether the file_alter_preservation flag is set.
fn set_file_alter_preservation(&mut self, file_alter_preservation: bool)
Sets the file_alter_preservation flag.
fn generate_uuid(&mut self)
Generates a new uuid for this frame.
Example
use id3::Frame; let mut frame = Frame::new("TYER"); let prev_uuid = frame.uuid.clone(); frame.generate_uuid(); assert!(prev_uuid != frame.uuid);
fn read_from(reader: &mut Read, version: u8) -> Result<Option<(u32, Frame)>>
Attempts to read a frame from the reader.
Returns a tuple containing the number of bytes read and a frame. If pading is encountered
then None
is returned.
Only reading from versions 2, 3, and 4 is supported. Attempting to read any other version
will return an error with kind UnsupportedVersion
.
fn write_to(&self, writer: &mut Write, version: u8) -> Result<u32>
Attempts to write the frame to the writer.
Returns the number of bytes written.
Only writing to versions 2, 3, and 4 is supported. Attempting to write using any other
version will return an error with kind UnsupportedVersion
.
fn content_to_bytes(&self, version: u8) -> Vec<u8>
Creates a vector representation of the content suitable for writing to an ID3 tag.
fn parse_data(&mut self, data: &[u8]) -> Result<()>
Parses the provided data and sets the content
field. If the compression flag is set to
true then decompression will be performed.
Returns Err
if the data is invalid for the frame type.
fn text(&self) -> Option<Cow<str>>
Returns a string representing the parsed content.
Returns None
if the parsed content can not be represented as text.
Example
use id3::frame::{self, Frame, Content}; let mut title_frame = Frame::new("TIT2"); title_frame.content = Content::Text("title".to_owned()); assert_eq!(&title_frame.text().unwrap()[..], "title"); let mut txxx_frame = Frame::new("TXXX"); txxx_frame.content = Content::ExtendedText(frame::ExtendedText { key: "key".to_owned(), value: "value".to_owned() }); assert_eq!(&txxx_frame.text().unwrap()[..], "key: value");