本文整理汇总了C#中ByteVector.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ByteVector.ToString方法的具体用法?C# ByteVector.ToString怎么用?C# ByteVector.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteVector
的用法示例。
在下文中一共展示了ByteVector.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Picture
public Picture(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (data.Count < 0x20)
{
throw new CorruptFileException("Data must be at least 32 bytes long");
}
int startIndex = 0;
this.type = (PictureType) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
int count = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.mime_type = data.ToString(StringType.Latin1, startIndex, count);
startIndex += count;
int num3 = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.description = data.ToString(StringType.UTF8, startIndex, num3);
startIndex += num3;
this.width = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.height = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.color_depth = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.indexed_colors = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
int length = (int) data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.picture_data = data.Mid(startIndex, length);
}
示例2: Parse
private void Parse(ByteVector data)
{
this.title = data.ToString(StringType.Latin1, 0, 0x20).Trim();
this.artist = data.ToString(StringType.Latin1, 0x20, 0x1c).Trim();
this.year = data.ToString(StringType.Latin1, 60, 4).Trim();
this.comment = data.ToString(StringType.Latin1, 0x40, 0x30).Trim();
this.genre = data.ToString(StringType.Latin1, 0x70, 3).Trim();
this.extra_data = data.Mid(0x73, 6);
}
示例3: Parse
//////////////////////////////////////////////////////////////////////////
// public methods
//////////////////////////////////////////////////////////////////////////
public virtual string Parse (ByteVector data)
{
if (data == null)
throw new ArgumentNullException ("data");
string output = data.ToString (StringType.Latin1).Trim ();
int i = output.IndexOf ('\0');
return (i >= 0) ? output.Substring (0, i) : output;
}
示例4: Parse
public virtual string Parse(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
string str = data.ToString(StringType.Latin1).Trim();
int index = str.IndexOf('\0');
return ((index < 0) ? str : str.Substring(0, index));
}
示例5: CopyResize
public void CopyResize()
{
ByteVector a = new ByteVector(TestVector);
ByteVector b = ByteVector.FromString("ABCDEFGHIJKL", StringType.UTF8);
a.Resize(12);
Assert.AreEqual(b, a);
Assert.AreEqual( b.ToString(), a.ToString());
Assert.IsFalse(a.Count == TestVector.Count);
}
示例6: Picture
public Picture (ByteVector data)
{
if (data == null)
throw new ArgumentNullException ("data");
if (data.Count < 32)
throw new CorruptFileException ("Data must be at least 32 bytes long");
int pos = 0;
_type = (PictureType) data.Mid (pos, 4).ToUInt ();
pos += 4;
int mimetype_length = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_mimetype = data.ToString (StringType.Latin1, pos, mimetype_length);
pos += mimetype_length;
int description_length = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_description = data.ToString (StringType.UTF8, pos, description_length);
pos += description_length;
_width = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_height = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_color_depth = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_indexed_colors = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
int data_length = (int) data.Mid (pos, 4).ToUInt ();
pos += 4;
_data = data.Mid (pos, data_length);
}
示例7: ParseFields
protected override void ParseFields(ByteVector data, byte version)
{
ByteVector pattern = ByteVector.TextDelimiter(StringType.Latin1);
int count = data.Find(pattern);
if (count < 0)
{
throw new CorruptFileException("Popularimeter frame does not contain a text delimiter");
}
this.user = data.ToString(StringType.Latin1, 0, count);
this.rating = data[count + 1];
this.play_count = data.Mid(count + 2).ToULong();
}
示例8: CommentsFrameError
public void CommentsFrameError()
{
// http://bugzilla.gnome.org/show_bug.cgi?id=582735
// Comments data found in the wild
ByteVector vector = new ByteVector (
1, 255, 254, 73, 0, 68, 0, 51, 0, 71, 0, 58, 0, 32, 0, 50, 0, 55, 0, 0, 0);
var encoding = (StringType) vector [0];
var language = vector.ToString (StringType.Latin1, 1, 3);
var split = vector.ToStrings (encoding, 4, 3);
Assert.AreEqual (2, split.Length);
}
示例9: CreateDataString
private string CreateDataString (int min_size)
{
string src = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ByteVector data = new ByteVector ();
for (int i = 0; data.Count < min_size; i++)
{
int index = i % src.Length;
data.Add (src.Substring (index, src.Length - index));
}
return data.ToString ();
}
示例10: PictureFromData
/// <summary>
/// Converts a raw ASF picture into an <see cref="IPicture"
/// /> object.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing raw ASF
/// picture data.
/// </param>
/// <returns>
/// A <see cref="IPicture" /> object to read from the raw
/// data.
/// </returns>
private static IPicture PictureFromData (ByteVector data)
{
if (data.Count < 9)
return null;
int offset = 0;
Picture p = new Picture ();
// Get the picture type:
p.Type = (PictureType) data [offset];
offset += 1;
// Get the picture size:
int size = (int) data.Mid (offset, 4).ToUInt (false);
offset += 4;
// Get the mime-type:
int found = data.Find (ByteVector.TextDelimiter (
StringType.UTF16LE), offset, 2);
if (found < 0)
return null;
p.MimeType = data.ToString (StringType.UTF16LE, offset,
found - offset);
offset = found + 2;
// Get the description:
found = data.Find (ByteVector.TextDelimiter (
StringType.UTF16LE), offset, 2);
if (found < 0)
return null;
p.Description = data.ToString (StringType.UTF16LE,
offset, found - offset);
offset = found + 2;
p.Data = data.Mid (offset, size);
return p;
}
示例11: Parse
/// <summary>
/// Populates the current instance by parsing the contents of
/// a raw AudibleMetadata tag.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the whole tag
/// object
/// </param>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> is less than 128 bytes or does
/// not start with <see cref="FileIdentifier" />.
/// </exception>
private void Parse (ByteVector data)
{
String currentKey, currentValue;
int keyLen, valueLen;
try
{
do
{
keyLen = (int) data.ToUInt(true);
data.RemoveRange (0, 4);
valueLen = (int) data.ToUInt(true);
data.RemoveRange (0, 4);
currentKey = data.ToString ( TagLib.StringType.UTF8, 0, keyLen );
data.RemoveRange (0, keyLen);
currentValue = data.ToString ( TagLib.StringType.UTF8, 0, valueLen );
data.RemoveRange (0, valueLen);
tags.Add( new KeyValuePair<string, string>(currentKey, currentValue) );
//StringHandle (currentKey, currentValue);
// if it is not the last item remove the end byte (null terminated)
if (data.Count != 0)
data.RemoveRange(0,1);
}
while (data.Count >= 4);
}
catch (Exception)
{
//
}
if (data.Count != 0)
throw new CorruptFileException();
}
示例12: ParseFields
/// <summary>
/// Populates the values in the current instance by parsing
/// its field data in a specified version.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the
/// extracted field data.
/// </param>
/// <param name="version">
/// A <see cref="byte" /> indicating the ID3v2 version the
/// field data is encoded in.
/// </param>
protected override void ParseFields (ByteVector data,
byte version)
{
if (data.Count < 4)
throw new CorruptFileException (
"Not enough bytes in field.");
encoding = (StringType) data [0];
language = data.ToString (StringType.Latin1, 1, 3);
string [] split = data.ToStrings (encoding, 4, 2);
if (split.Length == 1) {
// Bad lyrics frame. Assume that it lacks a
// description.
description = String.Empty;
text = split [0];
} else {
description = split [0];
text = split [1];
}
}
示例13: ParseFields
/// <summary>
/// Populates the values in the current instance by parsing
/// its field data in a specified version.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the
/// extracted field data.
/// </param>
/// <param name="version">
/// A <see cref="byte" /> indicating the ID3v2 version the
/// field data is encoded in.
/// </param>
protected override void ParseFields (ByteVector data,
byte version)
{
if (data.Count < 4)
throw new CorruptFileException (
"Not enough bytes in field.");
encoding = (StringType) data [0];
language = data.ToString (StringType.Latin1, 1, 3);
text = data.ToString (encoding, 4, data.Count - 4);
}
示例14: ParseFields
/// <summary>
/// Populates the values in the current instance by parsing
/// its field data in a specified version.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the
/// extracted field data.
/// </param>
/// <param name="version">
/// A <see cref="byte" /> indicating the ID3v2 version the
/// field data is encoded in.
/// </param>
protected override void ParseFields (ByteVector data,
byte version)
{
if (data.Count < 4)
throw new CorruptFileException (
"Not enough bytes in field.");
encoding = (StringType) data [0];
language = data.ToString (StringType.Latin1, 1, 3);
// Instead of splitting into two string, in the format
// [{desc}\0{value}], try splitting into three strings
// in case of a misformatted [{desc}\0{value}\0].
string [] split = data.ToStrings (encoding, 4, 3);
if (split.Length == 0) {
// No data in the frame.
description = String.Empty;
text = String.Empty;
} else if (split.Length == 1) {
// Bad comment frame. Assume that it lacks a
// description.
description = String.Empty;
text = split [0];
} else {
description = split [0];
text = split [1];
}
}
示例15: UserCommentIFDEntry
/// <summary>
/// Construcor.
/// </summary>
/// <param name="tag">
/// A <see cref="System.UInt16"/> with the tag ID of the entry this instance
/// represents
/// </param>
/// <param name="data">
/// A <see cref="ByteVector"/> to be stored
/// </param>
public UserCommentIFDEntry (ushort tag, ByteVector data)
{
Tag = tag;
if (data.StartsWith (COMMENT_ASCII_CODE)) {
Value = data.ToString (StringType.Latin1, COMMENT_ASCII_CODE.Count, data.Count - COMMENT_ASCII_CODE.Count);
return;
}
if (data.StartsWith (COMMENT_UNICODE_CODE)) {
Value = data.ToString (StringType.UTF8, COMMENT_UNICODE_CODE.Count, data.Count - COMMENT_UNICODE_CODE.Count);
return;
}
// Some programs like e.g. CanonZoomBrowser inserts just the first 0x00-byte
// followed by 7-bytes of trash.
if (data.StartsWith ((byte) 0x00) && data.Count >= 8) {
// And CanonZoomBrowser fills some trailing bytes of the comment field
// with '\0'. So we return only the characters before the first '\0'.
int term = data.Find ("\0", 8);
if (term != -1) {
Value = data.ToString (StringType.Latin1, 8, term - 8);
} else {
Value = data.ToString (StringType.Latin1, 8, data.Count - 8);
}
return;
}
if (data.Data.Length == 0) {
Value = String.Empty;
return;
}
throw new NotImplementedException ("UserComment with other encoding than Latin1 or Unicode");
}