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

Expose way to access the two wrapped ints #6

Open
anmolitor opened this issue Oct 9, 2022 · 1 comment
Open

Expose way to access the two wrapped ints #6

anmolitor opened this issue Oct 9, 2022 · 1 comment

Comments

@anmolitor
Copy link

I'm currently trying to add int64 encoders and decoders to elm-protocol-buffers
and I'm struggling to implement the VarInt encoding.
The int32 version currently converts the number to base 128, right shifts and continues in a loop.

This is the code:

toVarIntEncoders : Int -> List Encode.Encoder
toVarIntEncoders value =
    let
        base128 =
            Bitwise.and 0x7F value

        higherBits =
            Bitwise.shiftRightZfBy 7 value
    in
    if higherBits /= 0x00 then
        Encode.unsignedInt8 (Bitwise.or 0x80 base128) :: toVarIntEncoders higherBits

    else
        [ Encode.unsignedInt8 base128 ]

I cannot do this with Int64, since the inner values are not exposed.
Using Int64.encode instead of Encode.unsignedInt8 has the correct first two bytes but too many zeros afterwards.

@anmolitor
Copy link
Author

I used Int64.getByteValues instead, the resulting code feels a bit weird but works.

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

1 participant