public int ReadInt32() { if (CurrentType != AmqpToken.Array || _itemType != AmqpType.Int) { throw new InvalidOperationException(); } if (_currentLength < sizeof(int)) { throw new InvalidOperationException(); } int value = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(_current)); _current += sizeof(int); _currentLength -= sizeof(int); if (_currentLength == 0) { CurrentType = AmqpToken.ArrayEnd; } return(value); }
public AmqpToken MoveNext() { _buffer = _buffer.Slice(_next); _next = 0; if (_buffer.Length == 0) { return(AmqpToken.EndOfData); } var constructor = (AmqpType)_buffer[0]; switch (constructor) { case AmqpType.Descriptor: _next++; CurrentType = AmqpToken.Descriptor; break; case AmqpType.Binary8: if (_buffer.Length == 1) { return(AmqpToken.EndOfData); } _currentLength = _buffer[1]; _current = 2; _next += _currentLength + _current; CurrentType = AmqpToken.Binary; break; case AmqpType.Binary32: _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)); _current = 5; _next += _currentLength + _current; CurrentType = AmqpToken.Binary; break; case AmqpType.String8: _current = 2; _currentLength = _buffer[1]; _next += _currentLength + _current; CurrentType = AmqpToken.String; break; case AmqpType.String32: _current = 5; _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)); _next += _currentLength + _current; CurrentType = AmqpToken.String; break; case AmqpType.Array8: { if (_buffer.Length < 4) { return(AmqpToken.EndOfData); } var itemSize = _buffer[1]; _currentLength = _buffer[2]; _itemType = (AmqpType)_buffer[3]; _current = 4; _next = _current + (_currentLength * itemSize); CurrentType = AmqpToken.Array; break; } case AmqpType.Array32: { if (_buffer.Length < 10) { return(AmqpToken.EndOfData); } var dataSize = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)) - 5; _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(5)) * sizeof(int); _itemType = (AmqpType)_buffer[9]; _current = 10; _next = _current + dataSize; CurrentType = AmqpToken.Array; break; } default: throw new NotImplementedException(); } return(CurrentType); }