Giter Site home page Giter Site logo

messages-encoding's Introduction

Usage

The code provided includes a TypeScript implementation of the binary message encoding scheme along with unit tests. The implementation includes a MessageCodec interface and a createMessageCodec function to create an instance of the codec.

Installation

  1. Clone the repository:

    git clone https://github.com/pavloPyrig0/messages-encoding.git
  2. Install dependencies:

    cd binary-message-encoding
    npm install

Example

Here's an example of how to use the MessageCodec:

  import { createMessageCodec, Message } from './src';
  
  // Create an instance of the message codec
  const messageCodec = createMessageCodec();
  
  // Create a message
  const message: Message = {
     headers: new Map([
        ['Header1', 'Value1'],
        ['Header2', 'Value2'],
     ]),
     payload: new Uint8Array([1, 2, 3, 4, 5]),
  };
  
  // Encode the message to binary
  const encodedData = messageCodec.encode(message);
  
  console.log(encodedData);
  
  // Decode the binary data back to a message
  const decodedMessage = messageCodec.decode(encodedData);
  
  console.log(decodedMessage);

API Reference

createMessageCodec(): MessageCodec

Creates an instance of the MessageCodec interface.

Message

An interface representing a binary message.

  • headers: A Map containing the header name-value pairs.
  • payload: A Uint8Array representing the binary payload.

MessageCodec

An interface for encoding and decoding binary messages.

  • encode(message: Message): Uint8Array: Encodes a Message object into a Uint8Array.
  • decode(data: Uint8Array): Message: Decodes a Uint8Array into a Message object.

Limitations

  • Header names and values are limited to ASCII-encoded strings.
  • Header names and values are limited to 1023 bytes each.
  • A message can have a maximum of 63 headers.
  • The message payload is limited to 256 KiB.

Testing

The project includes unit tests implemented using the Jest testing framework. To run the tests, use the following command:

npm test

messages-encoding's People

Contributors

pavlopyrig0 avatar

Watchers

 avatar

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.