[fpc-devel] Method for write string into TStreamt

thaddy at thaddy.com thaddy at thaddy.com
Tue Jul 22 18:17:09 CEST 2014

What I was a little bit more than hinting at in my previous answers is 
that it is impossible for an abstract read stream to know that there's a 
string to read. There is at least one higher level of implementation 
necessary: one that recognizes a string.
That means probably something like  storing the length and  storing a 
string marker and/or use RTTI for strings, to be consistent.

In practice, I use json for that kind of streaming. And that is already 
in place.

On 22-7-2014 14:37, Dmitry Boyarintsev wrote:
> On Tue, Jul 22, 2014 at 6:46 AM, thaddy at thaddy.com 
> <mailto:thaddy at thaddy.com> <thaddy at thaddy.com 
> <mailto:thaddy at thaddy.com>> wrote:
>     A case for ternary computing is not really a bad idea ;)
>     On 21-7-2014 21:42, Hans-Peter Diettrich wrote:
>         Dmitry Boyarintsev schrieb:
>             How about introducing a default parameter?
>             The parameter keeps the method backward compatible,
>             allowing write a string without the prefix.
>             public procedure TStream.WriteAnsiString(
>               const S: string;
>               withLength: Boolean = true;
>         How should a string without a length be read back?
>         DoDi
> I didn't see DoDi's email anywhere in the thread, though it seems like 
> there're two threads anyway:
> "Re: [fpc-devel] Method for write string into TStream" and 
> "[fpc-devel] Method for write string into TStream"
> Anyways, answering DoDi's question.
> It definitely won't be able to read a string without a size, but it 
> doesn't mean that the string size should immediately precede the 
> string content.
> So maybe a modification like this could help
> procedure TStream.ReadAnsiString(knownsize: Integer=-1)
>    if knownsize<0 then
>      TheSize := ...readsize
>   else
>      TheSize := knownsize
> thanks,
> Dmitry
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140722/8142447d/attachment.html>

More information about the fpc-devel mailing list