Code Monkey home page Code Monkey logo

Comments (10)

pm47 avatar pm47 commented on June 1, 2024

Note: instead it silently pads with zeroes.

from scodec.

mpilquist avatar mpilquist commented on June 1, 2024

Hm, I think the padding behavior is desirable in many cases (and folks are likely relying on this behavior as coded). We could add a bytesStrict method which does what the documentation claims though. What do you think?

from scodec.

pm47 avatar pm47 commented on June 1, 2024

I think the padding behavior is definitely needed in some cases, adding a bytesStrict method would certainly be acceptable.

But on a related note I think the naming of fixedSizeBytes and paddedFixedSizeBytes is a little bit misleading because both do add padding. I realized it because I expected to bypass the issue I had with bytes by composing it with fixedSizeBytes but the result was the same. So another possibility would be to just fix bytes documentation, and change the behavior of fixedSizeBytes so that it does what its name advertises?

Cheers,
Pierre

edit: of course 2nd proposition would break backward compatibility and that is a big deal

from scodec.

mpilquist avatar mpilquist commented on June 1, 2024

Yeah, the compatibility breakage is my concern -- specifically that it is a silent breakage that folks would only notice if they have explicit tests which cover the behavior change. If not for that, I'd say let's fix the implementation and leave docs as-is.

from scodec.

pm47 avatar pm47 commented on June 1, 2024

Agreed, I guess bytesStrict is the way to go then. Should we still fix the def sizeBound = SizeBound.exact(size * 8L) or leave it as is?

If you give me some insight on how you'd do it I can submit a PR.

from scodec.

pm47 avatar pm47 commented on June 1, 2024

On the other hand, not fixing fixedSizeBytes is a hard decision because its misleading name can lead to bugs. Actually I am pretty sure the documentation bug in bytes is related to its implementation relying upon fixedSizeBytes 😁

One option could be to:

  • add bytesStrict
  • remove fixedSizeBytes
  • maybe add a zeroPaddedFixedSizeBytes (or defaulting paddedFixedSizeBytes with a zero padder)

This would break compatibility, but in a non-silent way and maybe prevent future bugs in implementations.

from scodec.

mpilquist avatar mpilquist commented on June 1, 2024

Hm, I think I'd rather keep fixedSizeBytes and fixedSizeBits as they are -- the docs on fixedSizeBits correctly define what happens if the encoded value is less than the specified size. Plus, these methods are used a lot in implementations of existing protocols, so renaming w/ a deprecation cycle adds busywork for those downstream projects. I don't think the potential confusion over the name is enough to offset the downstream impacts.

So I guess that means we just need to add bytesStrict and bitsStrict.

Should we still fix the def sizeBound = SizeBound.exact(size * 8L) or leave it as is?

I think the existing implementation is correct -- SizeBound.exact(size * 8L) -- which says that no matter how many bytes you encode with bytes(n), you are guaranteed to get n bytes in the output. Right?

from scodec.

pm47 avatar pm47 commented on June 1, 2024

Should we still fix the def sizeBound = SizeBound.exact(size * 8L) or leave it as is?

I think the existing implementation is correct -- SizeBound.exact(size * 8L) -- which says that no matter how many bytes you encode with bytes(n), you are guaranteed to get n bytes in the output. Right?

Right!

from scodec.

mpilquist avatar mpilquist commented on June 1, 2024

@pm47 Were you still planning on opening a PR for addingbytesStrict and bitsStrict?

from scodec.

mpilquist avatar mpilquist commented on June 1, 2024

Fixed in #99

from scodec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.