Summary

WriteEndMark method writes additional stopping mark into resulting stream to allow corresponding de-serializer to be able to correctly stop at this position, even if the stream contains some additional data.

Syntax

procedure WriteEndMark;

Remarks

If the resulting stream is intended to contain more data, then written by the serializer itself, that is, if some other data will be written into the stream after serializer data, its required to call WriteEndMark method to store additional stoping mark into the stream. This will allow de-serializer to stop at the serialized data end without attempting to read additional data (which will result in read error or data corruption with high probability).

At the same time if the stream will be filled by a single serializer object only, then there are no need to call WriteEndMark method.

The call to WriteEndMark method should be the last call, all other serialization related method calls will throw invalid state error after this call. Flushing buffer by calling  NG.Serialization.Binary.TBinarySerializer.FlushBuffer method is also prohibited, WriteEndMark will perform last buffer flush automatically.

Examples

DelphiCopyCode imageCopy Code
stream := TMemoryStream.Create;
binszr := TBinarySerializer.Create(stream);
try
  binszr.Value<TMyObject>(obj);
  binszr.WriteEndMark;

  MyMemo.Lines.SaveToStream(stream); // Save additional data.
finally
  binszr.Free;
  stream.Free;
end;