Skip to content

Refactoring the codec to be used solely with MQTT/SSE - #3

Merged
QuintinWillison merged 14 commits into
masterfrom
refactorings-and-tests
Mar 30, 2020
Merged

Refactoring the codec to be used solely with MQTT/SSE#3
QuintinWillison merged 14 commits into
masterfrom
refactorings-and-tests

Conversation

@codemerx

Copy link
Copy Markdown
Contributor

With the generic client library codecs infrastructure gone and plugins stepping in this library should be used standalone only and only in the cases where client library is not available. This should be closer to its final form in that case.

Comment threaddelta-codec/src/test/java/io/ably/deltacodec/VcdiffDecoderTest.java Outdated
Comment threaddelta-codec/src/main/java/io/ably/deltacodec/VcdiffDecoder.java Outdated
@QuintinWillison

Copy link
Copy Markdown
Contributor

I've requested a review from @marto83, given he's been working on this very recently for .NET.

@marto83marto83 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a general comment about the Vcdiff decoder class. It works 👍 which is great and we can make it better.
As @QuintinWillison said it will be better to avoid accepting object for applyDelta when all we care for is byte[] or base64 string. How about we make 2 methods applyDelta(byte[]) and applyDeltaBase64(string). This way people will explicitly have to call the right method. I doubt somebody will receive a mix of the 2. It will either be base64 messages on a text transport or byte[] on a binary transport.
The other method setBase also invites errors. You should be able to create an un-initialised Decoder class. Can we make the constructor private and have 3 factory methods.

  • Create(byte[], (optional) baseId)
  • Create(string, (optional) baseId)
  • CreateFromBase64(string, (optional) baseId)
    This way we can make setBase private and it will be harder for people to unintentionally create a scenario where the decoder is invalid.

@QuintinWillison

Copy link
Copy Markdown
Contributor

As @QuintinWillison said it will be better to avoid accepting object for applyDelta when all we care for is byte[] or base64 string. How about we make 2 methods applyDelta(byte[]) and applyDeltaBase64(string). This way people will explicitly have to call the right method. I doubt somebody will receive a mix of the 2. It will either be base64 messages on a text transport or byte[] on a binary transport.

My preference is still per my original comment and implement as an overload. Java has a strong type system so that approach is more idiomatic.

@codemerx

codemerx commented Dec 11, 2019

Copy link
Copy Markdown
ContributorAuthor

This is a general comment about the Vcdiff decoder class. It works 👍 which is great and we can make it better.
As @QuintinWillison said it will be better to avoid accepting object for applyDelta when all we care for is byte[] or base64 string. How about we make 2 methods applyDelta(byte[]) and applyDeltaBase64(string). This way people will explicitly have to call the right method. I doubt somebody will receive a mix of the 2. It will either be base64 messages on a text transport or byte[] on a binary transport.

There might be a string message that is not base64 encoded binary.

The other method setBase also invites errors. You should be able to create an un-initialised Decoder class. Can we make the constructor private and have 3 factory methods.

* Create(byte[], (optional) baseId)
* Create(string, (optional) baseId)
* CreateFromBase64(string, (optional) baseId)
This way we can make setBase private and it will be harder for people to unintentionally create a scenario where the decoder is invalid.

That was the initial implementation. @mattheworiordan requested it to be changed to the current form. As far as I can remember that was done so that less code needs to be written, i.e. deltas are simpler to use albeit not completely fail safe. We had a long discussion about it and I do not know whether it makes sense to reopen that discussion again and flip the implementation once more.

@marto83

Copy link
Copy Markdown

There might be a string message that is not base64 encoded binary.

I thought when you are applying deltas you will only either get a base64 or a byte[].

Regarding the other comment. Moving to factory methods will add an extra check. Currently the user will only have to check if the message is a base64 encoded message. The other disadvantage is that you will have to wait to create the Decoder until the first message arrives.

@codemerx

Copy link
Copy Markdown
ContributorAuthor

I completely refactored the API and made it truly generic. There was a lot of legacy coming from the old codecs infrastructure. Actually the changes I made were specified in https://github.com/ably/wiki/blob/bd7b4f44174a65f17856283c1943d621bbe0b9ea/pages/ImplementingDeltasForANewTech.md but we are keeping too many things in the air now and I lose track.

@QuintinWillison@marto83 check out the API now and let me know what you think.

Comment threaddelta-codec/src/main/java/io/ably/deltacodec/VcdiffDecoder.java Outdated
Comment threaddelta-codec/src/main/java/io/ably/deltacodec/VcdiffDecoder.java Outdated
This was referenced Dec 13, 2019
@QuintinWillison
QuintinWillison removed the request for review from paddybyersDecember 13, 2019 10:38
@paddybyers
paddybyers changed the base branch from feature-base-functionality to masterJanuary 6, 2020 17:06
Comment threaddelta-codec/src/main/java/io/ably/deltacodec/BaseVcdiffDecoder.java Outdated
@codemerx
codemerxforce-pushed the refactorings-and-tests branch from f8918ee to d7e6470CompareMarch 9, 2020 08:08
@QuintinWillison
QuintinWillison merged commit b8126f2 into masterMar 30, 2020
@QuintinWillison
QuintinWillison deleted the refactorings-and-tests branch March 30, 2020 15:28
@codemerxcodemerx removed their assignment Oct 21, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@codemerx@QuintinWillison@marto83@tsviatko