protected override Frame ParseFrame(byte[] data) { int place=0; SingleByteField encodingField=new SingleByteField(); place+=encodingField.Parse(data, place); TextField imageFormatField=TextField.CreateTextField(true,EncodingScheme.Ascii); place+=imageFormatField.Parse(data, place); SingleByteField pictureTypeField=new SingleByteField(); place+=pictureTypeField.Parse(data, place); TextField descriptionField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value); place+=descriptionField.Parse(data, place); BinaryField dataField=new BinaryField(); place+=dataField.Parse(data, place); System.IO.MemoryStream memoryImageBuffer=new System.IO.MemoryStream(dataField.Data); try { System.Drawing.Image image=System.Drawing.Image.FromStream(memoryImageBuffer); return new PictureFrame(dataField.Data, image, descriptionField.Text, (PictureType)pictureTypeField.Value); } catch(ArgumentException) { throw new FrameParsingException("Unrecognized picture format found in Picture frame."); } }
protected override Frame ParseFrame(byte[] data) { //Text encoding $xx //MIME type <text string> $00 //Filename <text string according to encoding> $00 (00) //Content description <text string according to encóding> $00 (00) //Encapsulated object <binary data> int place=0; SingleByteField encodingField=new SingleByteField(); place+=encodingField.Parse(data, place); TextField mimeTypeField=TextField.CreateTextField(true,EncodingScheme.Ascii); place+=mimeTypeField.Parse(data, place); TextField fileNameField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value); place+=fileNameField.Parse(data, place); TextField contentDescriptionField=TextField.CreateTextField(true, (EncodingScheme)encodingField.Value); place+=contentDescriptionField.Parse(data, place); BinaryField dataField=new BinaryField(); place+=dataField.Parse(data, place); return new GeneralEncapsulatedObjectFrame( fileNameField.Text, contentDescriptionField.Text, mimeTypeField.Text, dataField.Data); }
protected override Frame ParseFrame(byte[] data) { int place=0; BinaryField dataField=new BinaryField(); place+=dataField.Parse(data, place); return new MusicCDIdentifierFrame(dataField.Data); }
protected override Frame ParseFrame(byte[] data) { int place=0; TextField ownerField=TextField.CreateTextField(true, EncodingScheme.Ascii); place+=ownerField.Parse(data, place); BinaryField dataField=new BinaryField(); place+=dataField.Parse(data, place); return new UniqueFileIdentifierFrame(dataField.Data,ownerField.Text); }
public void TestWrite() { for(int testCase=0;testCase<100;testCase++) { byte[] randomData=new byte[_randomNumberGenerator.Next(1, 50000)]; _randomNumberGenerator.NextBytes(randomData); BinaryField field=new BinaryField(randomData, 0, randomData.Length); MemoryStream stream=new MemoryStream(); field.WriteToStream(stream); Assert.AreEqual(stream.Length, randomData.Length); for(int i = 0;i < randomData.Length;i++) { Assert.AreEqual(randomData[i], stream.GetBuffer()[i]); } } }
public void TestRead() { for(int testCase=0;testCase<100;testCase++) { byte[] randomData=new byte[_randomNumberGenerator.Next(1, 50000)]; int offset=_randomNumberGenerator.Next(0, randomData.Length-1); _randomNumberGenerator.NextBytes(randomData); BinaryField field=new BinaryField(); field.Parse(randomData, offset); Assert.AreEqual(field.Data.Length, randomData.Length-offset); Assert.AreEqual(field.Length, randomData.Length-offset); Assert.AreEqual(field.Length, field.Data.Length); for(int i = offset;i < randomData.Length;i++) { Assert.AreEqual(randomData[i], field.Data[i-offset]); } } }
protected override Frame ParseFrame(byte[] data) { int place=0; BinaryField dataField=new BinaryField(); place+=dataField.Parse(data, place); if(dataField.Data.Length!=4) { throw new FrameParsingException("Length of a Play Counter frame should be exactly 4. Larger frames are not yet supported."); } int counter= (((int)dataField.Data[0]) << 24) + (((int)dataField.Data[1]) << 16) + (((int)dataField.Data[2]) << 8) + ((int)dataField.Data[3]); return new PlayCounterFrame(counter); }