Parse() public méthode

public Parse ( byte data, int offset ) : int
data byte
offset int
Résultat int
Exemple #1
0
        protected override Frame ParseFrame(byte[] data)
        {
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            FixedLengthAsciiTextField imageFormatField=new FixedLengthAsciiTextField(3);
            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.");
            }
        }
        public void DoTest()
        {
            foreach(string testCase in _asciiTestCases)
            {
                FixedLengthAsciiTextField field=new FixedLengthAsciiTextField(testCase);
                MemoryStream stream=new MemoryStream();

                field.WriteToStream(stream);

                FixedLengthAsciiTextField field2=new FixedLengthAsciiTextField(testCase.Length);
                field2.Parse(stream.GetBuffer(), 0);

                Assert.AreEqual(field.Text, field2.Text);
            }
        }
        protected static string ParseExtendedTextFrame(byte[] data, out string description, out LanguageCode language)
        {
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            FixedLengthAsciiTextField langField=new FixedLengthAsciiTextField(3);
            place+=langField.Parse(data, place);

            TextField descriptinoField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value);
            place+=descriptinoField.Parse(data, place);

            TextField textField=TextField.CreateTextField(false,(EncodingScheme)encodingField.Value);
            place+=textField.Parse(data, place);

            if(!Enum.IsDefined(typeof(LanguageCode), langField.Text))
            {
                langField.Text="Unknown";
            }
            language=(LanguageCode)Enum.Parse(typeof(LanguageCode), langField.Text);
            description=descriptinoField.Text;
            return textField.Text;
        }