Skip to content

Commit

Permalink
[parser]handle the condition when no data provided
Browse files Browse the repository at this point in the history
  • Loading branch information
wkgcass committed Jun 16, 2024
1 parent 076b754 commit 9ca9172
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ protected AbstractParser(Set<Integer> terminateStates) {
}

public int feed(RingBuffer buffer) {
if (buffer.used() == 0) {
// nothing provided
return -1;
}
while (buffer.used() != 0) {
chnl.reset();
buffer.writeTo(chnl);
Expand All @@ -42,6 +46,10 @@ public int feed(RingBuffer buffer) {
}

public int feed(ByteArrayChannel chnl) {
if (chnl.used() == 0) {
// nothing provided
return -1;
}
while (chnl.used() != 0) {
byte b = chnl.read();
state = doSwitch(b);
Expand Down

0 comments on commit 9ca9172

Please sign in to comment.