-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for deltas using VCDiff codec.
- Loading branch information
Showing
15 changed files
with
477 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.ably.lib.types; | ||
|
||
import java.util.Map; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class DecodingContext { | ||
|
||
private String lastMessageString; | ||
private byte[] lastMessageBinary; | ||
|
||
public DecodingContext() | ||
{ | ||
lastMessageBinary = null; | ||
lastMessageString = null; | ||
} | ||
|
||
public byte[] getLastMessageData() { | ||
if(lastMessageBinary != null) | ||
return lastMessageBinary; | ||
else if(lastMessageString != null) { | ||
return lastMessageString.getBytes(StandardCharsets.UTF_8); | ||
} | ||
else | ||
return null; | ||
} | ||
|
||
public void setLastMessageData(String message) { | ||
lastMessageString = message; | ||
lastMessageBinary = null; | ||
} | ||
|
||
public void setLastMessageData(byte[] message) { | ||
lastMessageBinary = message; | ||
lastMessageString = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.ably.lib.types; | ||
|
||
import io.ably.lib.util.Log; | ||
import org.msgpack.core.MessageFormat; | ||
import org.msgpack.core.MessagePacker; | ||
import org.msgpack.core.MessageUnpacker; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeltaExtras { | ||
private static final String TAG = DeltaExtras.class.getName(); | ||
|
||
public String format; | ||
public String from; | ||
|
||
void writeMsgpack(MessagePacker packer) throws IOException { | ||
packer.packMapHeader(2); | ||
|
||
packer.packString("format"); | ||
packer.packString(this.format); | ||
|
||
packer.packString("from"); | ||
packer.packString(this.from); | ||
} | ||
|
||
private DeltaExtras readMsgpack(MessageUnpacker unpacker) throws IOException { | ||
int fieldCount = unpacker.unpackMapHeader(); | ||
for(int i = 0; i < fieldCount; i++) { | ||
String fieldName = unpacker.unpackString(); | ||
MessageFormat fieldFormat = unpacker.getNextFormat(); | ||
if(fieldFormat.equals(MessageFormat.NIL)) { | ||
unpacker.unpackNil(); | ||
continue; | ||
} | ||
|
||
if(fieldName.equals("format")) { | ||
this.format = unpacker.unpackString(); | ||
} else if (fieldName.equals("from")) { | ||
this.from = unpacker.unpackString(); | ||
} else { | ||
Log.v(TAG, "Unexpected field: " + fieldName); | ||
unpacker.skipValue(); | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
static DeltaExtras fromMsgpack(MessageUnpacker unpacker) throws IOException { | ||
return (new DeltaExtras()).readMsgpack(unpacker); | ||
} | ||
} |
Oops, something went wrong.