protected abstract int ParseFrame(
byte[] buffer,
int offset,
int length
)
Protected MustOverride Function ParseFrame (
buffer As Byte(),
offset As Integer,
length As Integer
) As Integer
protected:
virtual int ParseFrame(
array<unsigned char>^ buffer,
int offset,
int length
) abstract
function ParseFrame(buffer, offset, length);
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.