public void PopulateDictionary(byte[] data, int position, int length, IDictionary<string,object> output)
{
// We need a simple state machine so we know how to handle
// embedded '=' in the value.
State state = State.Tag;
int tagBegin = position;
int tagLength = 0;
int valueBegin = 0;
for (int index = position; index < position + length; ++index )
{
if(data[index]==FieldSeparator && tagLength > 0)
{
string tag = Encoding.ASCII.GetString(data, tagBegin, tagLength);
tagLength = 0;
string value = Encoding.UTF8.GetString(data, valueBegin, index - valueBegin);
output[tag] = value;
tagBegin = index+1;
tagLength = 0;
state = State.Tag;
}
else if(data[index]==TagValueSeparator && state == State.Tag)
{
tagLength = index - tagBegin;
state = State.Value;
valueBegin = index + 1;
}
}
}