Comments (10)
Note: instead it silently pads with zeroes.
from scodec.
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.
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.
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.
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.
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 defaultingpaddedFixedSizeBytes
with a zero padder)
This would break compatibility, but in a non-silent way and maybe prevent future bugs in implementations.
from scodec.
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.
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.
@pm47 Were you still planning on opening a PR for addingbytesStrict
and bitsStrict
?
from scodec.
Fixed in #99
from scodec.
Related Issues (20)
- Summoner evaluates to null HOT 2
- Question: Leverage ordering in `discriminated` codec to facilitate migration HOT 2
- pbcd codec pads right instead of left. HOT 1
- Maven artifactId changed in 1.10.4 release HOT 1
- intelliJ IDEA No implicit for prameter auto HOT 1
- Padding in Base64Url encoding should be optional HOT 2
- Typecase on tuple2 is throwing ClassCastException (1.11.3, 1.10.3. Scala 2.12.8) HOT 1
- ConstrainedVariableSizeCodec sizeBound is incorrect
- SizeBound of VarLongCodec and VarIntCodec?
- Make a release with new scodec-bits HOT 4
- Consider codecs of union types
- Consider adopting shapeless-deriving HOT 2
- BitVector.reverseBitOrder unreliable on non-whole-byte BitVectors HOT 1
- Method too large HOT 2
- varlong should not throw on negative Numbers
- Cross-Compiling scala 2.13 and scala 3 against scodec-core HOT 3
- No issue - just a thank you HOT 1
- CodecSuite.roundtrip has no Equality HOT 1
- How to decode uint8 length 10 into string in C language HOT 2
- constantLenient is incorrect when streaming HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scodec.