Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to deserialize TABLE_MAP and ROTATE events to byte arrays #29

Closed
thomasdziedzic opened this issue Feb 14, 2015 · 8 comments
Closed

Comments

@thomasdziedzic
Copy link

Related to #28 since the library depends on those being deserialized to a specific type.

@shyiko
Copy link
Owner

shyiko commented Feb 14, 2015

I think you can try something similar to:

public class CustomRotateEventData extends RotateEventData {

    private byte[] data;

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }
}

public class CustomRotateEventDataDeserializer extends RotateEventDataDeserializer {

    @Override
    public RotateEventData deserialize(ByteArrayInputStream inputStream) throws IOException {
        byte[] data = inputStream.read(inputStream.available());
        RotateEventData eventData = super.deserialize(new ByteArrayInputStream(data));
        CustomRotateEventData result = new CustomRotateEventData();
        result.setData(data);
        result.setBinlogPosition(eventData.getBinlogPosition());
        result.setBinlogFilename(eventData.getBinlogFilename());
        return result;
    }
}

eventDeserializer.setEventDataDeserializer(EventType.ROTATE, new CustomRotateEventDataDeserializer());

Obviously, the same has to be done for TableMapEventData.

@thomasdziedzic
Copy link
Author

This works, though I don't think it's ideal.

If I were to go with this solution, I would have to special case fetching byte data for all rotate and table_map events.

I think another solution could be to attach a getData method to the EventDataDeserializer class so that we can have a common interface for accessing byte data for all event types.

@shyiko
Copy link
Owner

shyiko commented Feb 14, 2015

Oh, I know it's far from being ideal. The workaround above I literally wrote while driving back home :) It's something that you can use now and not wait for me to change the internal flow (which is on its way).

@shyiko
Copy link
Owner

shyiko commented Feb 17, 2015

Fix available in 0.1.2-SNAPSHOT. Starting from 0417068 EventDataDeserializer can be specified regardless of the event type (= no special treatment for TABLE_MAP/ROTATE).

@shyiko
Copy link
Owner

shyiko commented Feb 17, 2015

0.1.2 should become available through Maven Central in the next 24h.

@shyiko shyiko closed this as completed Feb 17, 2015
@thomasdziedzic
Copy link
Author

@shyiko oh man, thanks for the quick implementation. I didn't want to sound ungrateful in my original post about your workaround. I just wanted to point out that it would be not ideal. Anyways, it seems like you went the extra step for this issue! cheers! 🍺

@shyiko
Copy link
Owner

shyiko commented Feb 17, 2015

I didn't want to sound...

Not at all, man. I truly appreciate your feedback. 🍻

@chenyun
Copy link
Contributor

chenyun commented Apr 7, 2015

@shyiko Thanks a lot, after reading #29 #28 , I understand your design. 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants