tsfoster / elm-bytes-extra Goto Github PK
View Code? Open in Web Editor NEWHelpers for working with elm/bytes
Home Page: https://package.elm-lang.org/packages/TSFoster/elm-bytes-extra/latest/
License: BSD 3-Clause "New" or "Revised" License
Helpers for working with elm/bytes
Home Page: https://package.elm-lang.org/packages/TSFoster/elm-bytes-extra/latest/
License: BSD 3-Clause "New" or "Revised" License
slice
is a great function to extract chunks out of a Bytes
sequence. However, it would be very practical if one could have a quick way of decoding with offsets(where there's no easy access to Bytes
). That's why I am proposing this offset Decoder as a combinator for a Decoder
.
Example Implementation
-- in the Bytes.Extra.Decode module
withOffset : Int -> Decoder a -> Decoder a
withOffset offset decoder =
Bytes.Decode.bytes (max 0 offset) |> andThen (\_ -> decoder)
-- can then be used like this
import Bytes.Decode exposing (float64)
import Bytes.Decode.Extra exposing (withOffset)
withOffset 8 float64 -- will first skip 8 bytes and then decode a 64 bit-float
Concrete use case
I am currently trying to decode buffer data out of buffers in GLTF data (3d model format). In many cases the data is not densely packed, so it is necessary to skip some bytes while decoding to get to the later data.
PS: Thanks for this useful package. <3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.