Class BinaryGenerator
Abstract class providing mechanisms supporting generating documents from binary template files.
Inherited Members
Namespace: SuperOffice.IO
Assembly: SoCore.dll
Syntax
public abstract class BinaryGenerator : Generator
Constructors
BinaryGenerator(Stream, TagContainer, GeneratorEncoding)
Protected constructor used by sub-classes
Declaration
protected BinaryGenerator(Stream template, TagContainer tags, GeneratorEncoding encoding)
Parameters
Type | Name | Description |
---|---|---|
Stream | template | Stream holding a template. |
TagContainer | tags | Class holding values for the tags used by the generator |
GeneratorEncoding | encoding | Format of the document. |
Properties
GeneratorState
Abstract class providing mechanisms supporting generating documents from binary template files.
Declaration
protected BinaryGenerator.State GeneratorState { get; }
Property Value
Type | Description |
---|---|
BinaryGenerator.State |
Reader
BinaryReader that the template is read from.
Declaration
protected BinaryReader Reader { get; }
Property Value
Type | Description |
---|---|
BinaryReader |
Writer
BinaryWriter that the document is written to.
Declaration
protected BinaryWriter Writer { get; }
Property Value
Type | Description |
---|---|
BinaryWriter |
Methods
AbortTag()
Abort seeking for an end tag and start seeking for a start tag.
Declaration
protected void AbortTag()
AbortTag(Int32)
Abort seeking for an end tag and start seeking for a start tag.
Declaration
protected void AbortTag(int bytes)
Parameters
Type | Name | Description |
---|---|---|
Int32 | bytes |
Remarks
After a start tag is found, the search for an end-tag can be aborted.
This method aborts seeking for an end tag. If a next start tag is found
while seeking for a start tag, the input argument will contain the number
of bytes that should be re-parsed looking for a start tag.
Examples
case BinaryGenerator.State.LookForTagEnd:
{
int bytes = StartTag(buffer);
if (bytes > 0)
{
AbortTag(bytes);
SetState(BinaryGenerator.State.LookForTagEnd, bytes);
break;
}
EndTag(Int32)
Identify a tag end.
Declaration
protected abstract int EndTag(int buffer)
Parameters
Type | Name | Description |
---|---|---|
Int32 | buffer | Last 4 bytes parsed. This method is called each time a new byte is read from the template. |
Returns
Type | Description |
---|---|
Int32 | 0 if no tag has been identified. A positive number is the number of bytes held by the end tag. |
Generate(Stream)
Generate the document from the template.
Declaration
public override void Generate(Stream output)
Parameters
Type | Name | Description |
---|---|---|
Stream | output |
Overrides
IsValidTagData(Int32)
Called for each byte in a tag, to verify that the data within the tags are valid.
Declaration
protected virtual bool IsValidTagData(int buffer)
Parameters
Type | Name | Description |
---|---|---|
Int32 | buffer |
Returns
Type | Description |
---|---|
Boolean | True if it is valid data. |
Remarks
The default implementation will allways return true.
OnEnd()
Called when the template has been parsed.
Declaration
protected abstract void OnEnd()
OnProcessData(Int64, Int32, BinaryGenerator.State)
Process data as it is read from the template.
Declaration
protected virtual void OnProcessData(long position, int buffer, BinaryGenerator.State state)
Parameters
Type | Name | Description |
---|---|---|
Int64 | position | Current position in the template, where the first byte in the template is 1. |
Int32 | buffer | Last 4 bytes parsed. This method is called each time a new byte is read from the template. |
BinaryGenerator.State | state | State of the generator. The state is either to look for a start or to look for an end tag. |
OnProcessTag(Int64, Byte[])
Called when a tag has been extracted from the template file.
Declaration
protected abstract byte[] OnProcessTag(long position, byte[] tagBuffer)
Parameters
Type | Name | Description |
---|---|---|
Int64 | position | Position in the template where the tag starts. |
Byte[] | tagBuffer | Buffer holding the tag, including tag start and stop bytes, |
Returns
Type | Description |
---|---|
Byte[] | Buffer holding data to be written to the document instead of the tag. |
OnStart()
Called when starting to parse the template.
Declaration
protected abstract void OnStart()
SetState(BinaryGenerator.State, Int32)
Change the state of the parser between seeking for start or end tag.
Declaration
protected void SetState(BinaryGenerator.State state, int tagSize)
Parameters
Type | Name | Description |
---|---|---|
BinaryGenerator.State | state | The new state. |
Int32 | tagSize | Size of the tag in bytes. |
StartTag(Int32)
Identify a tag start.
Declaration
protected abstract int StartTag(int buffer)
Parameters
Type | Name | Description |
---|---|---|
Int32 | buffer | Last 4 bytes parsed. This method is called each time a new byte is read from the template. |
Returns
Type | Description |
---|---|
Int32 | 0 if no tag has been identified. A positive number is the number of bytes held by the start tag. |