simplify custom encoder/decoder

This commit is contained in:
nkzawa
2017-07-14 11:50:25 +09:00
parent 7279919ef9
commit 3d98ed9fe9
3 changed files with 6 additions and 20 deletions

View File

@@ -149,10 +149,8 @@ public class Manager extends Emitter {
this.uri = uri;
this.encoding = false;
this.packetBuffer = new ArrayList<Packet>();
Parser parser = opts.parser != null ? opts.parser : new IOParser();
this.encoder = parser.getEncoder();
this.decoder = parser.getDecoder();
this.encoder = opts.encoder != null ? opts.encoder : new IOParser.Encoder();
this.decoder = opts.decoder != null ? opts.decoder : new IOParser.Decoder();
}
private void emitAll(String event, Object... args) {
@@ -634,7 +632,8 @@ public class Manager extends Emitter {
public long reconnectionDelay;
public long reconnectionDelayMax;
public double randomizationFactor;
public Parser parser;
public Parser.Encoder encoder;
public Parser.Decoder decoder;
/**
* Connection timeout (ms). Set -1 to disable.

View File

@@ -1,5 +1,6 @@
package io.socket.parser;
import io.socket.client.IO;
import io.socket.hasbinary.HasBinary;
import org.json.JSONException;
import org.json.JSONTokener;
@@ -18,17 +19,7 @@ final public class IOParser implements Parser {
return new Packet<String>(ERROR, "parser error");
}
public IOParser() {}
@Override
public Parser.Encoder getEncoder () {
return new Encoder();
}
@Override
public Parser.Decoder getDecoder () {
return new Decoder();
}
private IOParser() {}
final public static class Encoder implements Parser.Encoder {

View File

@@ -63,10 +63,6 @@ public interface Parser {
"BINARY_ACK"
};
public Encoder getEncoder();
public Decoder getDecoder();
public static interface Encoder {
public void encode(Packet obj, Callback callback);