Logo Search packages:      
Sourcecode: taglib-sharp version File versions

TagLib::Id3v2::PrivateFrame Class Reference

Inheritance diagram for TagLib::Id3v2::PrivateFrame:

List of all members.


Detailed Description

This class extends Frame, implementing support for ID3v2 Private (PRIV) Frames.

A PrivateFrame should be used for storing values specific to the application that cannot or should not be stored in another frame type.

Serializing a database entry and storing it in a private field.

          using System;
          using System.IO;
          using System.Runtime.Serialization;
          using System.Text;
          using System.Xml.Serialization;
          using TagLib.Id3v2;

          public static class DbUtil
          {
            public static void StoreDatabaseEntry (Tag tag, ISerializable dbEntry)
            {
                  StringWriter data = new StringWriter (new StringBuilder ());
                  XmlSerializer serializer = new XmlSerializer (dbEntry.GetType ());
                  serializer.Serialize (data, dbEntry);
                  PrivateFrame frame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", true);
                  frame.PrivateData = Encoding.UTF8.GetBytes (data.ToString ());
            }

            public static object GetDatabaseEntry (Tag tag, Type type)
            {
                  PrivateFrame frame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", false);
                  if (frame == null)
                        return null;

                  XmlSerializer serializer = new XmlSerializer (type);
                  return serializer.Deserialize (new MemoryStream (frame.PrivateData));
            }
          }
          #using <System.dll>
          #using <System.Xml.dll>
          #using <taglib-sharp.dll>

          using System;
          using System::IO;
          using System::Runtime::Serialization;
          using System::Text;
          using System::Xml::Serialization;
          using TagLib::Id3v2;

          public ref class DbUtil abstract sealed
          {
          public:
            static void StoreDatabaseEntry (Tag^ tag, ISerializable^ dbEntry)
            {
                  StringWriter^ data = gcnew StringWriter (gcnew StringBuilder);
                  XmlSerializer serializer = gcnew XmlSerializer (dbEntry->GetType ());
                  serializer->Serialize (data, dbEntry);
                  PrivateFrame frame = PrivateFrame::Get (tag, L"org.MyProgram.DatabaseEntry", true);
                  frame.PrivateData = Encoding::UTF8->GetBytes (data->ToString ());
            }

            static Object^ GetDatabaseEntry (Tag^ tag, Type^ type)
            {
                  PrivateFrame^ frame = PrivateFrame::Get (tag, L"org.MyProgram.DatabaseEntry", false);
                  if (frame == null)
                        return null;

                  XmlSerializer serializer = gcnew XmlSerializer (type);
                  return serializer->Deserialize (gcnew MemoryStream (frame->PrivateData));
            }
          }
          Imports System
          Imports System.IO
          Imports System.Runtime.Serialization
          Imports System.Text
          Imports System.Xml.Serialization
          Imports TagLib.Id3v2

          Public Shared Class DbUtil
            Public Shared Sub StoreDatabaseEntry (tag As Tag, dbEntry As ISerializable)
                  Dim data As New StringWriter (New StringBuilder ())
                  Dim serializer As New XmlSerializer (dbEntry.GetType ())
                  serializer.Serialize (data, dbEntry)
                  Dim frame As PrivateFrame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", True)
                  frame.PrivateData = Encoding.UTF8.GetBytes (data.ToString ())
            End Sub

            Public Shared Sub GetDatabaseEntry (tag As Tag, type As Type)
                  Dim frame As PrivateFrame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", False)
                  If frame Is Nothing Then Return Nothing

                  Dim serializer As XmlSerializer = New XmlSerializer (type)
                  Return serializer.Deserialize (New MemoryStream (frame.PrivateData))
            End Sub
          End Class
          import System
          import System.IO
          import System.Runtime.Serialization
          import System.Text
          import System.Xml.Serialization
          import TagLib.Id3v2

          public static class DbUtil:
            static def StoreDatabaseEntry (tag as Tag, dbEntry as ISerializable):
                  data as StringWriter = StringWriter (StringBuilder ())
                  serializer as XmlSerializer = XmlSerializer (dbEntry.GetType ())
                  serializer.Serialize (data, dbEntry)
                  frame as PrivateFrame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", true)
                  frame.PrivateData = Encoding.UTF8.GetBytes (data.ToString ())

            static def GetDatabaseEntry (tag As Tag, type As Type):
                  frame as PrivateFrame = PrivateFrame.Get (tag, "org.MyProgram.DatabaseEntry", false)
                  if frame == null:
                        return null

                  serializer as XmlSerializer = XmlSerializer (type)
                  return serializer.Deserialize (MemoryStream (frame.PrivateData))

Definition at line 156 of file PrivateFrame.cs.


Public Member Functions

 PrivateFrame (ByteVector data, byte version)
 Constructs and initializes a new instance of PrivateFrame by reading its raw data in a specified ID3v2 version.
 PrivateFrame (string owner)
 Constructs and initializes a new instance of PrivateFrame without data for a specified owner.
 PrivateFrame (string owner, ByteVector data)
 Constructs and initializes a new instance of PrivateFrame for a specified owner and data.
virtual ByteVector Render (byte version)

Static Public Member Functions

static PrivateFrame Get (Tag tag, string owner, bool create)
 Gets a specified private frame from the specified tag, optionally creating it if it does not exist.
static ByteVector TextDelimiter (StringType type)

Protected Member Functions

ByteVector FieldData (ByteVector frameData, int offset, byte version)
override void ParseFields (ByteVector data, byte version)
 Populates the values in the current instance by parsing its field data in a specified version.
internal PrivateFrame (ByteVector data, int offset, FrameHeader header, byte version)
 Constructs and initializes a new instance of PrivateFrame by reading its raw data in a specified ID3v2 version.
override ByteVector RenderFields (byte version)
 Renders the values in the current instance into field data for a specified version.
void SetData (ByteVector data, int offset, byte version, bool readHeader)

Static Protected Member Functions

static StringType CorrectEncoding (StringType type, byte version)

Properties

short EncryptionId [get, set]
FrameFlags Flags [get, set]
ReadOnlyByteVector FrameId [get]
short GroupId [get, set]
string Owner [get]
 Gets the owner of the current instance.
ByteVector PrivateData [get, set]
 Gets and sets the private data stored in the current instance.
uint Size [get]

Private Attributes

ByteVector data = null
 Contains private data stored in the current instance.
string owner = null
 Contains the owner of the current instance.

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index