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

digi-dungeon-protobuf

v0.2.11

Published

Digi Dungeon API protocol buffers

Downloads

32

Readme

Introduction

This library is used in the official client and server for Digi-Dungeon to reduce network bandwidth between clients and server.

If you're looking at this you've probably realized that the data sent around is in Uint8Arrays instead of the regular JSON you might be used to seeing in JavaScript. The server encodes the messages in this buffer and then the clients have to decode thebuffer into JSON objects or whatever data they mean to send around.

How to (using the original proto files)

To use this library in your own client (typescript example), you need to import * as protobuf from 'protobufjs'; then use the following code as a guide for your own implementation

encodeResponse(lookupType: string, message: any) {
  // Lookup buffer type
  let responseProto = this.protoRoot.lookupType(lookupType);
  // Check errors lol
  let err = responseProto.verify(message);
  if (err) console.log('Error lol');
  // Create the message payload
  let payload = responseProto.create(message);
  // Encode the buffer
  let buffer = responseProto.encode(payload).finish();
  return buffer;
}

The lookupType is a string and in this library it will be always start with the dd as its namespace package identifier. All the message structures can then be accessed with the following table:

| Message Name | Digi-Dungeon API reference | Notes | | ------------ | -------------------------- | ----------------- | | dd.shard | ddapi.Shard | | dd.map | ddapi.Map | | dd.auth | ddapi.Auth | | dd.event | ddapi.Event | | dd.util | ddapi.Util | | dd.sheet | ddapi.Sheet | @notImplemented |

Then whatever data structure you want to encode in has the same name as the API reference.

How to (using the module)

Use the higly advanced ProtoBufCringe class included to lookup the message types without having to write that whole scpiel up there. Something along the lines of this:

// send it lol
import ProtoBufCringe from 'digi-dungeon-protobuf';

let authloginrequest = { username: 'username', password: 'password' };
ProtoBufCringe.encode_request(authloginrequest, 'dd.auth.UserLoginData').then(
  (buffer) => {
    // your code that sends this buffer to the server
    // to be noted that the server like the data you send to look like this:
    let data_to_send = { data: buffer };
  }
);

// recieve it also
import ProtoBufCringe from 'digi-dungeon-protobuf';
// You recieve the `buffer` from the server in a little buffer pouch
let buffer = you_recieved_this_from_the_server;
ProtoBufCringe.decode_request_typed<AuthResponse>(
  buffer,
  'dd.auth.AuthResponse'
).then((response) => {
  // response is the decoded object
});

If you are a javascript boy instead of Typescript you can use:

import ProtoBufCringe from 'digi-dungeon-protobuf';
// You recieve the `buffer` from the server in a little buffer pouch
let buffer = you_recieved_this_from_the_server;
ProtoBufCringe.decode_request(buffer, 'dd.auth.AuthResponse').then(
  (response) => {
    // response is the decoded object
  }
);

Extra crumbs in the cookie jar

This readme and library will be expanded with all data structures soon™️

*This Protocol Buffer library for Digi-Dungeon only supports hexgrids based on the axial coordinate system (Vector2).

Tests don't work by the way :)

You can thank me not spending enough time on this