Click or drag to resize

BinaryImageParserBaseParseFrame Method

Protocol specific frame parsing algorithm.

Namespace: GSF.Parsing
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.181-beta
Syntax
protected abstract int ParseFrame(
	byte[] buffer,
	int offset,
	int length
)
View Source

Parameters

buffer  Byte
Buffer containing data to parse.
offset  Int32
Offset index into buffer that represents where to start parsing.
length  Int32
Maximum length of valid data from offset.

Return Value

Int32
The length of the data that was parsed.
Remarks

Implementers can choose to focus on parsing a single frame in the buffer even if there are other frames available in the buffer. Base class will continue to move through buffer on behalf of derived class until all the buffer has been processed. Just return the total amount of data was parsed and the remaining unparsed will be prepended to next received buffer.

Derived implementations should return an integer value that represents the length of the data that was parsed, and zero if not enough data was able to be parsed. Note that exceptions are expensive when parsing fast moving streaming data and a good coding practice for implementations of this method will be to not throw an exception when there is not enough data to parse the data, instead check the length property to verify there is enough buffer data to represent the desired image. If there is not enough data to represent the image return zero and base class will prepend buffer onto next incoming set of data.

Because of the expense incurred when an exception is thrown, any exceptions encountered in the derived implementations of this method will cause the current data buffer to be discarded and a ParsingException event to be raised. Doing this prevents exceptions from being thrown repeatedly for the same data. If your code implementation recognizes a malformed image, you can raise a custom event to indicate this instead of throwing as exception and keep moving through the buffer as an optimization.

See Also