simplify custom encoder/decoder
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user