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

View File

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

View File

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