Skip to content

Support for floats? #45

Open
Open

Description

@idubz33

I've just come across this library and after checking out the documentation at https://digidotcom.github.io/python-suitcase/latest/api.html I was wondering why there isn't support for floats?

Activity

  1. rtzoeller commented on Dec 15, 2016

    @rtzoeller
    Contributor

    Likely because no one had needed them in a use case up until now -- AFAIK, the addition of new field types has largely been on an as-needed basis.

    Is there a particular protocol you have in mind that requires floats to be encoded as bytes, as opposed to a text-based implementation?

  2. idubz33 commented on Dec 16, 2016

    @idubz33
    ContributorAuthor

    Fair enough, I'm not working with a particular protocol but rather with parsing and repacking some uncommon 3D graphic model files (as you can imagine a lot of vector fields containing floats). Originally I used the struct library which had float support but suitcase is vastly more eloquent... I can't go back :P

    I'm not sure what you mean by a text-based implementation, can you please elaborate? If its possible to cover 16/32/64 bit floats I'd be really grateful.

  3. posborne commented on Dec 16, 2016

    @posborne
    Contributor

    I would accept a PR adding floating point support. You should be able to add basic support easily by using the struct format strings similar to the existing ones like https://github.com/digidotcom/python-suitcase/blob/master/suitcase/fields.py#L1055

  4. idubz33 commented on Dec 22, 2016

    @idubz33
    ContributorAuthor

    Sorry to reopen this again but @posborne its seems that the way this package unpacks data can't be done for floats. I'm getting the following error:

      File "/Library/Python/2.7/site-packages/suitcase/fields.py", line 1005, in unpack
        value |= (byte << (i * 8))
    suitcase.exceptions.SuitcaseParseError: Unexpected exception while unpacking field 'Rotation_X': unsupported operand type(s) for <<: 'float' and 'int'
    

    The unpack definition would require change to allow floats https://github.com/digidotcom/python-suitcase/blob/master/suitcase/fields.py#L998. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions