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

5m-proto

v1.0.0

Published

Package for easy use of protobuf in FiveM environments

Downloads

71

Readme

Project Name

Overview

This project is a TypeScript-based lib that deals with encoding, decoding, and extracting data. It utilizes Protocol Buffers (protobufjs) for message serialization, and employs a set of custom modules for handling these operations.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/Purpose-Dev/5m-proto.git
    cd 5m-proto
  2. Install dependencies using pnpm:

    pnpm add 5m-proto

Usage

To get started with the project:

  1. Build the project:

    pnpm run build
  2. Run tests:

    pnpm test

Project Structure

The project structure includes several TypeScript files with specific purposes:

  • index.ts: Main entry point exporting core functionalities from other modules.
  • decode.ts: Contains functions for decoding buffers.
  • encode.ts: Responsible for loading and encoding messages.
  • extractData.ts: Functions for extracting data from various sources.
  • Payload.ts: Defines and handles payload structures.
// index.ts
export { decodeBuffer } from "./decode";
export { loadAndEncodeMessage } from "./encode";
export { extractData } from "./extractData";
export { Payload } from "./Payload";

Contributing

We welcome contributions! Please fork the repository and submit a pull request for any changes you would like to contribute.

  1. Fork the repository

  2. Create a new branch

    git checkout -b feature-branch
  3. Make your changes

  4. Commit your changes

    git commit -m "Description of changes"
  5. Push to your branch

    git push origin feature-branch
  6. Open a pull request

Examples

  • proto file
syntax = "proto3";

package fivem;

message Position {
  float x = 1;
  float y = 2;
  float z = 3;
}

message Vehicle {
  string model = 1;
  string plate = 2;
  Position position = 3;
  bool is_owned = 4;
}

message WeaponAccessory {
  string name = 1;
}

message Weapon {
  string name = 1;
  int32 ammo_count = 2;
  repeated WeaponAccessory accessories = 3;
}

message Player {
  int32 id = 1;
  string name = 2;
  Position position = 3;
  int32 health = 4;
  int32 armor = 5;
  float cash = 6;
  float bank = 7;
  string job = 8;
  repeated Weapon weapon = 9;
  Vehicle current_vehicle = 10;
}

Server Part:

import { loadAndEncodeMessage } from "5m-proto";
import {Player} from "@protoDefs/fivem_pb";
import * as path from "path";

const protoPath = path.join(GetCurrentResourceName(), "proto");

const payload: Player = {
   id: 1,
   name: "John Doe",
   position: {
      x: 129.99,
      y: 512.47,
      z: 487.45
   },
   health: 154,
   armor: 80,
   cash: 1050.25,
   bank: 475.87,
   job: "developer",
   weapon: [
      {
         name: "Pistol",
         ammo: 30,
         accessories: [
            {
               name: "Silencer",
            },
            {
               name: "Extended Magazine",
            }
         ]
      }
   ],
   currentVehicle: {
      model: "Zentorno",
      plate: "ABC123",
      position: {
         x: 129.99,
         y: 512.47,
         z: 487.45
      },
      isOwned: false,
   },
};

RegisterCommand("sendData", async () => {
   console.log("Sending data...");
   const encoded = await loadAndEncodeMessage(`${protoPath}/awesome.proto`, "fivem.Player", payload);
   emitNet("proto:SendPlayerData", 1, encoded);
   console.log("Data sent");
}, false);

Client Part:

import { decodeBuffer, extractData } from "5m-proto";
import {Player} from "@protoDefs/fivem_pb";

onNet("proto:SendPlayerData", (encodedData: Uint8Array) => {
    const decodedData = decodeBuffer(encodedData, `${GetCurrentResourceName()}/proto/awesome.proto`, "fivem.Player");
    const playerData: Player = extractData(decodedData);
    console.log(playerData);
});

License

This project is licensed under the MIT License. See the LICENSE file for details.