Package 'rtson'

Title: Typed JSON
Description: TSON, short for Typed JSON, is a binary-encoded serialization of JSON like document that support JavaScript typed data (https://github.com/tercen/TSON).
Authors: Alexandre Maurel
Maintainer: Alexandre Maurel <[email protected]>
License: Apache License Version 2.0
Version: 1.6.1
Built: 2024-11-01 06:10:28 UTC
Source: https://github.com/tercen/tson

Help Index


Deserialize a raw vector

Description

This function convert a raw vector into a list following TSON specification binary-encoded format.

Usage

fromTSON(bytes)

Arguments

bytes

A raw vector

Value

A list

Examples

## Example

library(rtson)

list = list(integer=42L,
            double=42,
            bool=TRUE,
            uint8=tson.uint8.vec(c(42,0)),
            uint16=tson.uint16.vec(c(42,0)),
            uint32=tson.uint32.vec(c(42,0)),
            int8=tson.int8.vec(c(42,0)),
            int16=tson.int16.vec(c(42,0)),
            int32=as.integer(c(42,0)),
            float32=tson.float32.vec(c(0.0, 42.0)),
            float64=c(42.0,42.0),
            map=list(x=42, y=42, label="42"),
            list=list("42",42)
)

bytes = toTSON(list)
object = fromTSON(bytes)

Deserialize a connection

Description

Read TSON specification binary-encoded format from a connection.

Usage

readTSON(con)

Arguments

con

A connection or a raw vector

Value

A list

Examples

## Example

library(rtson)

list = list(integer=42L,
            double=42,
            bool=TRUE,
            uint8=tson.uint8.vec(c(42,0)),
            uint16=tson.uint16.vec(c(42,0)),
            uint32=tson.uint32.vec(c(42,0)),
            int8=tson.int8.vec(c(42,0)),
            int16=tson.int16.vec(c(42,0)),
            int32=as.integer(c(42,0)),
            float32=tson.float32.vec(c(0.0, 42.0)),
            float64=c(42.0,42.0),
            map=list(x=42, y=42, label="42"),
            list=list("42",42)
)

con = rawConnection(raw(0), "r+")
writeTSON(list, con)
bytes = rawConnectionValue(con)
close(con)
con = rawConnection(bytes, "r")
object = readTSON(con)

Serialize a list

Description

This function convert a list into raw following TSON specification binary-encoded format.

Usage

toTSON(object)

Arguments

object

A list

Value

A raw vector

Examples

## Example

library(rtson)

list = list(integer=42L,
            double=42,
            bool=TRUE,
            uint8=tson.uint8.vec(c(42,0)),
            uint16=tson.uint16.vec(c(42,0)),
            uint32=tson.uint32.vec(c(42,0)),
            int8=tson.int8.vec(c(42,0)),
            int16=tson.int16.vec(c(42,0)),
            int32=as.integer(c(42,0)),
            float32=tson.float32.vec(c(0.0, 42.0)),
            float64=c(42.0,42.0),
            map=list(x=42, y=42, label="42"),
            list=list("42",42)
)

bytes = toTSON(list)

Make a tson character

Description

Make a tson character

Usage

tson.character(object)

Arguments

object

A vector or list

Value

A tson character


Make a tson double

Description

Make a tson double

Usage

tson.double(object)

Arguments

object

A vector or list

Value

A tson double


Make a tson float32 vector

Description

Make a tson float32 vector

Usage

tson.float32.vec(object)

Arguments

object

A vector or list

Value

A tson float32 vector


Make a tson integer

Description

Make a tson integer

Usage

tson.int(object)

Arguments

object

A vector or list

Value

A tson integer


Make a tson int16 vector

Description

Make a tson int16 vector

Usage

tson.int16.vec(object)

Arguments

object

A vector or list

Value

A tson int16 vector


Make a tson int16 vector

Description

Make a tson int16 vector

Usage

tson.int64.vec(object)

Arguments

object

A vector or list

Value

A tson int64 vector


Make a tson int8 vector

Description

Make a tson int8 vector

Usage

tson.int8.vec(object)

Arguments

object

A vector or list

Value

A tson int8 vector


Make a tson map

Description

Required to generate empty map.

Usage

tson.map(object)

Arguments

object

A vector or list

Value

A tson map


Make a tson scalar (ie: singleton)

Description

Make a tson scalar (ie: singleton)

Usage

tson.scalar(obj)

Arguments

object

A vector or list

Value

A tson scalar


Make a tson uint16 vector

Description

Make a tson uint16 vector

Usage

tson.uint16.vec(object)

Arguments

object

A vector or list

Value

A tson uint16 vector


Make a tson uint32 vector

Description

Make a tson uint32 vector

Usage

tson.uint32.vec(object)

Arguments

object

A vector or list

Value

A tson uint32 vector


Make a tson uint64 vector

Description

Make a tson uint64 vector

Usage

tson.uint64.vec(object)

Arguments

object

A vector or list

Value

A tson uint64 vector


Make a tson uint8 vector

Description

Make a tson uint8 vector

Usage

tson.uint8.vec(object)

Arguments

object

A vector or list

Value

A tson uint8 vector


Serialize a list

Description

Write TSON specification binary-encoded format to a connection.

Usage

writeTSON(object, con)

Arguments

object

A list

con

A connection

Value

invisibly NULL

Examples

## Example

library(rtson)

list = list(integer=42L,
            double=42,
            bool=TRUE,
            uint8=tson.uint8.vec(c(42,0)),
            uint16=tson.uint16.vec(c(42,0)),
            uint32=tson.uint32.vec(c(42,0)),
            int8=tson.int8.vec(c(42,0)),
            int16=tson.int16.vec(c(42,0)),
            int32=as.integer(c(42,0)),
            float32=tson.float32.vec(c(0.0, 42.0)),
            float64=c(42.0,42.0),
            map=list(x=42, y=42, label="42"),
            list=list("42",42)
)

con = rawConnection(raw(0), "r+")
writeTSON(list, con)
bytes = rawConnectionValue(con)
close(con)
con = rawConnection(bytes, "r")
object = readTSON(con)