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

new_protocol has no way to set endianess #63

Open
MattFriedman opened this issue Feb 12, 2017 · 2 comments
Open

new_protocol has no way to set endianess #63

MattFriedman opened this issue Feb 12, 2017 · 2 comments

Comments

@MattFriedman
Copy link

In the function new_protocol

    def new_protocol(self, protocol_name):
        """Start defining a new protocol template.

        All messages sent and received from a connection that uses a protocol
        have to conform to this protocol template.
        """
        if self._protocol_in_progress:
            raise Exception('Can not start a new protocol definition in middle of old.')
        if protocol_name in self._protocols:
            raise Exception('Protocol %s already defined' % protocol_name)
        self._init_new_message_stack(Protocol(protocol_name, library=self))
        self._protocol_in_progress = True

The line self._init_new_message_stack(Protocol(protocol_name, library=self)) gives no option to set the Protocol constructor option for little_endian. Neither does the new_protocol method.

So, there does not seem to be a way to use the robot api, and have this little_endian feature. It would be very useful if the endian setting could be set from the robot api.

At least, that's how it looks to me atm.

Thanks for reviewing this issue.

Cheers,
Matt

@MattFriedman MattFriedman changed the title new_protocol has not way to set endianess new_protocol has no way to set endianess Feb 12, 2017
@MattFriedman
Copy link
Author

So, I tried my fix and change the method to the following:

    def new_protocol(self, protocol_name, little_endian=False):
        """Start defining a new protocol template.

        All messages sent and received from a connection that uses a protocol
        have to conform to this protocol template.
        """
        if self._protocol_in_progress:
            raise Exception('Can not start a new protocol definition in middle of old.')
        if protocol_name in self._protocols:
            raise Exception('Protocol %s already defined' % protocol_name)
        self._init_new_message_stack(Protocol(protocol_name, little_endian, library=self))
        self._protocol_in_progress = True

This maintains backward compatibility and appears to fix the issue I was having. My server now appears to be getting bytes in the correct order. (pending further testing)

I can now write this:
New protocol myProtocol True
which will turn on the little_endian feature.

Would be awesome if you could apply this to your great library.

Thanks,
Matt

@jussimalinen
Copy link
Contributor

Yeah, the endiannes thing was usable only by extending the base library. (It has been used like that)

Thanks for the pull request, I will try to review it soon. I havent had time to look at this library for a long time... :(

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

2 participants