npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

byte-parse-as

v0.1.0

Published

Parse bytes using lexer combinators.

Downloads

5

Readme

byte-parse-as

This library was designed out of necesity. In order to parse a stream of bytes, there needs to be a higher level concept of dealing with streams, concatenating bytes together to ensure that things can be parsed meangingfully, and over time. In fact, because assemblyscript has numerous ways of expressing byte arrays, it becomes incredibly difficult to read the bytes into a stream and use references in a performant way. This is why byte-parse-as exists, to ensure that developers can confidently tokenize and parse through their data in a performant way.

Usage

import { ByteSink, EqualsRule, EveryRule } from "byte-parse-as/assembly";

// some bytes input
let bytes = [0x10, 0x20, 0x30];

// create a sink and write the bytes
let sink = new ByteSink();
sink.write(bytes);

// create a bunch of byte rules
let Ten = new EqualsRule(0x10);
let Twenty = new EqualsRule(0x20);
let Thirty = new EqualdRule(0x30);

// combine them using EveryRule
let Parser = new EveryRule([Ten, Twenty, Thirty]);

// create a range object, referencing the sink
let range = new Range(0, 0, sink);

// test the rule
Parser.test(sink, 0 /* Index */, range); // true

// range is now set, if `Parser.test()` returns true
let bytes = range.toArrayBuffer(); // array buffer containing [0x10, 0x20, 0x30]

Working with strings and utf16 would likely be difficult, so using the ByteSink method will convert strings passed to the write() function to utf8 in the internal buffer.

let sink = new ByteSink();
sink.write("Hello");
sink.byteLength; // 5

Need a pointer to the data? Easy.

sink.dataStart; // usize

Rules

Rules are classes with a Test method that read from the byte sink, typically starting at the index provided.

It must set the Range provided and return true if there is a match.

export abstract class Rule {
  abstract test(buffer: ByteSink, index: i32, range: Range): bool;
}

Equals Rule

The equals rule tests a single byte in the sink.

// Create the rule
let A = new EqualsRule(0x41); // "A"

// make a sink and write some bytes to it.
let sink = new ByteSink();
sink.write("TEST A");

// Create a range, you only need one
let range = new Range(0, 0, sink);

// test the rule and pull out the bytes
A.test(sink, 5, range); // true!

range.toString(); // "A"

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.