From 41ae66907784df0d87bf37a4fdc5bf20a6f09cc9 Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Sun, 6 Jan 2019 18:42:42 -0800 Subject: [PATCH] Update README and license --- LICENSE | 1 - README.md | 39 ++++++++++++++------------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/LICENSE b/LICENSE index bebad7b..dcf5cab 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,5 @@ MIT License -Copyright (c) 2016 Marco Paland Copyright (c) 2018 NEAR Protocol Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index 176f724..e3c5683 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # assemblyscript-bson -BSON encoder / decoder for AssemblyScript somewhat based on https://github.com/mpaland/bsonfy. +JSON encoder / decoder for AssemblyScript. Special thanks to https://github.com/MaxGraey/bignum.wasm for basic unit testing infra for AssemblyScript. @@ -8,14 +8,7 @@ Special thanks to https://github.com/MaxGraey/bignum.wasm for basic unit testing This is developed for use in smart contracts written in AssemblyScript for https://github.com/nearprotocol/nearcore. This imposes such limitations: -- Only limited data types are supported: - - arrays - - objects - - 32-bit integers - - strings - - booleans - - null - - `Uint8Array` +- Float numbers not supported - We assume that memory never needs to be deallocated (cause these contracts are short-lived). Note that this mostly just defines the way it's currently implemented. Contributors are welcome to fix limitations. @@ -23,16 +16,16 @@ Note that this mostly just defines the way it's currently implemented. Contribut # Usage -## Encoding BSON +## Encoding JSON ```ts // Make sure memory allocator is available import "allocator/arena"; // Import encoder -import { BSONEncoder } from "path/to/module"; +import { JSONEncoder } from "path/to/module"; // Create encoder -let encoder = new BSONEncoder(); +let encoder = new JSONEncoder(); // Construct necessary object encoder.pushObject("obj"); @@ -45,17 +38,17 @@ let bson: Uint8Array = encoder.serialize(); ``` -## Parsing BSON +## Parsing JSON ```ts // Make sure memory allocator is available import "allocator/arena"; // Import decoder -import { BSONDecoder, BSONHandler } from "path/to/module"; +import { JSONDecoder, JSONHandler } from "path/to/module"; -// Events need to be received by custom object extending BSONHandler. +// Events need to be received by custom object extending JSONHandler. // NOTE: All methods are optional to implement. -class MyBSONEventsHandler extends BSONHandler { +class MyJSONEventsHandler extends JSONHandler { setString(name: string, value: string): void { // Handle field } @@ -72,10 +65,6 @@ class MyBSONEventsHandler extends BSONHandler { // Handle field } - setUint8Array(name: string, value: Uint8Array): void { - // Handle field - } - pushArray(name: string): bool { // Handle array start return true; // true means that nested object needs to be traversed, false otherwise @@ -96,13 +85,13 @@ class MyBSONEventsHandler extends BSONHandler { } // Create decoder -let decoder = new BSONDecoder(new MyBSONEventsHandler()); +let decoder = new JSONDecoder(new MyJSONEventsHandler()); -// Let's assume BSON data is available in this variable -let bson: Uint8Array = ...; +// Let's assume JSON data is available in this variable +let json: Uint8Array = ...; -// Parse BSON -decoder.deserialize(bson); // This will send events to MyBSONEventsHandler +// Parse JSON +decoder.deserialize(json); // This will send events to MyJSONEventsHandler ```