in shims/amqpnetlite/src/amqp_large_content_test/Sender/Sender.cs [462:601]
public MbSpec(string sizeSpec)
{
MbBlock curMbBlock = new MbBlock();
Int32 curInt = 0; ;
ParseState ps = ParseState.START;
int pos = -1;
foreach (char ch in sizeSpec)
{
pos += 1;
//Console.WriteLine("ch = '{0}', position = {1}", ch, pos);
string err = "";
switch (ps)
{
case ParseState.START:
if (ch == '[')
{
MbBlocks = new List<MbBlock>();
ps = ParseState.NEW_MBBLOCK;
}
else
err = "no leading '['";
break;
case ParseState.NEW_MBBLOCK:
if (ch == ']')
{
MbBlocks.Add(curMbBlock);
ps = ParseState.END;
}
else if (ch == '[')
{
curMbBlock = new MbBlock();
ps = ParseState.M_BYTES;
curInt = 0;
}
else if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else
err = "NEW_MBBLOCK expects '[' or ']'";
break;
case ParseState.M_BYTES:
if (Char.IsDigit(ch))
{
curInt *= 10;
curInt += (int)(ch - '0');
}
else if (ch == ',')
{
curMbBlock.mBytes = curInt;
curInt = 0;
ps = ParseState.NEW_NCHUNKS;
}
else if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else
err = "M_BYTES expects digit or ','";
break;
case ParseState.NEW_NCHUNKS:
if (ch == '[')
{
curMbBlock.nChunks = new List<Int32>();
ps = ParseState.NCHUNK;
}
else if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else
err = "NEW_NCHUNKS expects digit or '['";
break;
case ParseState.NCHUNK:
if (Char.IsDigit(ch))
{
curInt *= 10;
curInt += (int)(ch - '0');
}
else if (ch == ',')
{
curMbBlock.nChunks.Add(curInt);
curInt = 0;
}
else if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else if (ch == ']')
{
curMbBlock.nChunks.Add(curInt);
curInt = 0;
ps = ParseState.END_NCHUNK;
}
else
err = "NCHUNK expects digit, ',', or ']'";
break;
case ParseState.END_NCHUNK:
if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else if (ch == ']')
{
MbBlocks.Add(curMbBlock);
curMbBlock = new MbBlock();
ps = ParseState.END_MBBLOCK;
}
else
err = "END_MBBLOCK expects ']'";
break;
case ParseState.END_MBBLOCK:
if (Char.IsWhiteSpace(ch))
{
// ignore whitespace
}
else if (ch == ',')
{
ps = ParseState.NEW_MBBLOCK;
}
else if (ch == ']')
{
ps = ParseState.END;
}
else
err = "END_MBBLOCK expects ',', ']', or '['";
break;
case ParseState.END:
err = "illegal characters after JSON end of object";
break;
}
if (err != "")
{
throw new ApplicationException(String.Format("Size spec parse error at position {0}, state {1}: {2}", pos, ps, err));
}
}
}