--- a/src/lib/AbstractParser.cpp Sat Jun 12 22:37:44 2021 +0200
+++ b/src/lib/AbstractParser.cpp Sat Jun 19 12:59:07 2021 +0200
@@ -16,6 +16,7 @@
*/
#include "AbstractParser.h"
+#include "TransactionalBuffer.h"
namespace relpipe {
namespace in {
@@ -24,7 +25,9 @@
class AbstractParserImpl {
private:
+ friend AbstractParser;
AbstractParser* interface;
+ TransactionalBuffer buffer;
public:
AbstractParserImpl(AbstractParser* interface) : interface(interface) {
@@ -43,12 +46,15 @@
}
void AbstractParser::write(const char* buffer, const size_t length) {
- // TODO: update pointers and positions
try {
+ // TODO: do not write to the buffer, just append in read()/peek() and write just the part that was not read during this cycle
+ implementation->buffer.write(buffer, length);
+
// TODO: call an overridable method to get preferred minimum block size and run cycle only if we have enough data or EOF
+ // and/or remember the length of last failed (rollbacked) read() call
update();
commit();
- } catch (const AbstractParser::ReadBufferUnderflowException& e) {
+ } catch (const TransactionalBuffer::ReadBufferUnderflowException& e) {
rollback();
} catch (const AbstractParser::ExplicitRollbackException& e) {
rollback();
@@ -56,20 +62,24 @@
}
void AbstractParser::close() {
+ // TODO: check remaining data + call update() or just let parsers override this method?
}
void AbstractParser::rollback() {
- // FIXME: store content of the current buffer + update pointers and positions
// TODO: notify rollback listeners? (they can monitor the performance / frequency of rollbacks)
+ implementation->buffer.rollbackRead();
}
void AbstractParser::commit() {
+ implementation->buffer.commitRead();
}
void AbstractParser::read(char* buffer, const size_t length) {
+ implementation->buffer.read(buffer, length);
}
void AbstractParser::peek(char* buffer, const size_t length) {
+ implementation->buffer.read(buffer, length);
}
}