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

This commit is contained in:
akwizgran
2012-12-15 05:07:03 +00:00
parent 3e2e7286fe
commit 28af51b156
3 changed files with 6 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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++;