Skip to content

relaxed04/rlp-motoko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RLP Motoko

A Motoko implementation of Recursive Length Prefix (RLP).

INSTALL

Add the following to your package-set.dhall file

{ name = "rlp"
, version = "master"
, repo = "https://github.com/relaxed04/rlp-motoko"
, dependencies = [] : List Text
}

Include it in your vessel.dhall file dependencies:

  dependencies = [ "base", "rlp" ],

USAGE

import RLP "mo:rlp";
import RLPTypes "mo:rlp/types";
import D "mo:base/Debug";

let encoded: RLPTypes.Uint8Array = switch(RLP.encode(#string("dog"))) {
  case(#ok(val)) { val };
  case(#err(val)) { 
    D.trap("do something with error");
   };
};

let decoded: RLPTypes.Decoded = switch(RLP.decode(#Uint8Array(encoded))) {
  case(#ok(val)) { val };
  case(#err(val)) { 
    D.trap("do something with error");
   };
};

// SAME AS

let decoded2: RLPTypes.Decoded = switch(RLP.decode(#Uint8Array(Buffer.fromArray<Nat8>([131, 100, 111, 103])))) {
  case(#ok(val)) { val };
  case(#err(val)) { 
    D.trap("do something with error");
   };
};

API

Both Encode and Decode functions accept an Input type.
Type definitions for inputs and outputs are located in the /src/types module.

TESTS

Tests runner is: testing

To run tests, install npm, and run:

npm run test

About

RLP implementation on motoko

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published