Giter Site home page Giter Site logo

tsfoster / elm-bytes-extra Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 51 KB

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

Elm 98.53% Makefile 1.47%

elm-bytes-extra's People

Contributors

folkertdev avatar tsfoster avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

folkertdev

elm-bytes-extra's Issues

Add decoder to decode with offset

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

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.