-2

I have a component which is writing into a blob different information by using the TWriter class. The problem is that some blobs have been saved incorrect into blob(or under another data sequence), and I need to correct somehow those errors. The problem arrives when I'm expectin an WriteListBegin or WriteListEnd and I get an EReadError "Invalid property value". I'm thinking of reading the stream byte by byte, and to know where these separators are located. How can I know that I'm encountering a WriteListBegin or WriteListEnd?

LE: The issue can not be solved as easily the comments suggest. I don't know the vendor, so I can not ask for details. Concerning of what is behind the TWriter mechanism, this is the following assembly routine, which I don't understand what bytes writes as a

start-of-list marker to the writer object's associated stream

procedure TWriter.Write(const Buf; Count: Longint); assembler;

Probably I will start to write my own custom TReader in order to fix the bogus streams.

RBA
  • 12,337
  • 16
  • 79
  • 126
  • 2
    I'm not sure how we are going to help without details of how these bogus blobs can be made. – David Heffernan Mar 25 '13 at 17:24
  • 1
    Doesn't *Classes.pas* show what `TWriter.WriteListBegin` writes to the stream? Simply look for that. – Rob Kennedy Mar 25 '13 at 19:44
  • @RBA If your goal is save and restore component(s) to/from blob (or any other data "containers" e.g. file) - you can use [TStream.WriteComponent](http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Classes_TStream_WriteComponent.html) and [TStream.ReadComponent](http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Classes_TStream_ReadComponent.html). 10 years ago it worked as I remember :) Only one limitation: published properties must have type which able to store/restore itself. – Abelisto Mar 25 '13 at 19:47
  • @Abelisto That would only make matters worse here. Switching to `ReadComponent` will mean that none of the existing data can be read. – David Heffernan Mar 25 '13 at 20:00
  • @DavidHeffernan Because of this I posted comment instead of answer :) Yes, you are right: if we initially had corrupted data - there is a lot of ways to correct them (if it possible). – Abelisto Mar 25 '13 at 20:09
  • @Abelisto - it's not about writing/reading component properties. It's about writing different chunks of different data types in a blob. – RBA Mar 26 '13 at 08:53
  • Thank all, especially for the -1... – RBA Mar 26 '13 at 09:00

2 Answers2

1

If I unraveled your question well, then I understand you have corrupt data which, obviously, does not let itself get parsed correctly. Specifically, the list begin and end markings are missing or, are in the wrong order or at the wrong place.

I can think of four solutions to fix that:

  1. See to get the data uncorrupted (ask supplier).
  2. Fix the data manually (if within reasonable size).
  3. Write an own custom parser to fix the markings automatically, and use that in advance.
  4. Using TWriter, for every line; remember current Position, check current line, rewrite, substitute or ignore that line in case of corruption and return to old position if necessary.

In case of several data chunks being corrupted in the same manner, maybe a partial manual investigation (2) may lead to custom parser (3) in no time.

NGLN
  • 43,011
  • 8
  • 105
  • 200
0

I solved the problem by reading data type until reader.EndOfList separator for most of the blobs.

Thank all, especially for the -1's

RBA
  • 12,337
  • 16
  • 79
  • 126