Skip to content
Snippets Groups Projects
Commit 28af51b1 authored by akwizgran's avatar akwizgran
Browse files

SLIP classes don't need to depend on SLTP classes.

parent 3e2e7286
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
SlipEncoder encoder = new SlipEncoder(this);
final Sender sender = new Sender(clock, encoder);
receiver = new Receiver(clock, sender);
decoder = new SlipDecoder(receiver);
decoder = new SlipDecoder(receiver, Data.MAX_LENGTH);
inputStream = new ReceiverInputStream(receiver);
outputStream = new SenderOutputStream(sender);
running = true;
......@@ -97,12 +97,12 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
return outputStream;
}
// The transport calls this method to pass data up to the SLIP decoder
// The lower layer calls this method to pass data up to the SLIP decoder
public void handleRead(byte[] b) throws IOException {
if(running) decoder.handleRead(b);
}
// The SLIP encoder calls this method to pass data down to the transport
// The SLIP encoder calls this method to pass data down to the lower layer
public void handleWrite(byte[] b) {
if(running && b.length > 0) writes.add(b);
}
......
......@@ -11,13 +11,14 @@ class SlipDecoder implements ReadHandler {
private static final byte TEND = (byte) 220, TESC = (byte) 221;
private final ReadHandler readHandler;
private final byte[] buf;
private byte[] buf = new byte[Data.MAX_LENGTH];
private int decodedLength = 0;
private boolean escape = false;
SlipDecoder(ReadHandler readHandler) {
SlipDecoder(ReadHandler readHandler, int maxDecodedLength) {
this.readHandler = readHandler;
buf = new byte[maxDecodedLength];
}
public void handleRead(byte[] b) throws IOException {
......
......@@ -17,7 +17,6 @@ class SlipEncoder implements WriteHandler {
}
public void handleWrite(byte[] b) throws IOException {
if(b.length > Data.MAX_LENGTH) throw new IllegalArgumentException();
int encodedLength = b.length + 2;
for(int i = 0; i < b.length; i++)
if(b[i] == END || b[i] == ESC) encodedLength++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment