• Stars
    star
    17
  • Rank 1,257,181 (Top 25 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Leap Motion cross-format, cross-platform declarative serialization library

Introduction to LeapSerial

LeapSerial is a cross-format, declarative, serialization and deserialization library written and maintained by Leap Motion. This library is built with CMake, and makes heavy use of C++11.

LeapSerial is mainly intended to provide users with a way to describe how their types should be serialized without being too concerned about the wire format serialization should take. Users should be able to directly annotate and serialize/deserialize their business objects rather than having to convert to and from DTOs generated by tools like protoc.

The following four output formats are currently supported:

  • JSON
  • Protobuf
  • Flatbuffers
  • LeapSerial Proprietary

LeapSerial also provides a simple stream concept, some wrapper classes, and a few standard implementations. These streams may be composed with one another similarly to how it's done with Protobuf streams.

  • Wrapper for std::istream and std::ostream
  • AES-256 encryption
  • Zlib compression
  • BZip2 compression
  • Memory stream

Users may also write their own.

Quick Start

Here's how you mark the fields to be serialized:

#include <LeapSerial/LeapSerial.h>

class MyClass {
  int my_member;

  static leap::descriptor GetDescriptor() {
    return {
      &MyClass::my_member
    };
  }
};

Serialization one-liner:

MyClass myClass;
std::stringstream os;
leap::Serialize(os, myClass);

Deserialization is also a one-liner:

std::shared_ptr<MyClass> a = leap::Deserialize<MyClass>(ss, myClass);

If your type doesn't use native pointers (either directly or transitively), you can also deserialize in-place.

MyClass b;
leap::Deserialize(ss, b);

Alternative Archivers

LeapSerial has a few output formats that are well supported. The leap::Serialize call, by default, will use the internal LeapSerial archiver, which formats data in a custom bitstream format. You can use other formats, though, such as Protobuf, but this requires that your fields are numbered or named. The following sections all use the following numbered and named data structure:

class MyProtobufObject {
public:
  int a = 949;
  std::string b = "Hello world!";
  std::vector<int> c {4, 5, 6};

  static leap::descriptor GetDescriptor(void) {
    return{
      "MyProtobufObject",
      {
        { 424, "a", &MyProtobufObject::a },
        { 425, "b", &MyProtobufObject::b },
        { 426, "c", &MyProtobufObject::c }
      }
    };
  }
};

Protobuf

Protobuf serialization can be done with OArchiveProtobuf:

#include <LeapSerial/IArchiveProtobuf.h>
#include <LeapSerial/OArchiveProtobuf.h>

void Foo() {
  MyProtobufObject myobj;
  std::stringstream ss;

  leap::Serialize<leap::OArchiveProtobuf>(ss, defaultPerson);
}

The resulting object can be parsed by Protobuf, if you have a schema for MyProtobufObject. You can also create the corresponding proto file by serializing the descriptor, like this:

std::stringstream ss;
leap::Serialize<leap::protobuf_v1>(
  ss,
  MyProtobufObject::GetDescriptor()
);

This is what you get:

message MyProtobufObject {
  required sint32 a = 424;
  optional string b = 425;
  repeated sint32 c = 426;
}

Right now, leap::protobuf_v1 and leap::protobuf_v2 are supported to ensure the generated proto file can be parsed by your chosen version of protoc.

JSON

JSON serialization is also supported. The protov3 specification's JSON mapping is used wherever possible. Currently, deserialization is not supported, but there is a leap::IArchiveJSON type which will provide deserialization once it's implemented.

#include <LeapSerial/ArchiveJSON.h>

void Foo() {
  MyProtobufObject obj;
  std::stringstream ss;
  leap::Serialize<leap::OArchiveJSON>(ss, obj);
}

Here's the resulting JSON:

{
  "a": 949,
  "b": "Hello world!",
  "c": [ 4, 5, 6 ]
}

Alternative Streams

You can also serialize to a memory buffer, if you don't like std::stringstream:

leap::MemoryStream ms;
MyClass b;
leap::Serialize(ms, b);

// In case you want to do something with the data
std::vector<uint8_t>& data = ms.GetDatadata();

// Or you can just round trip right from here
std::shared_ptr<MyClass> c = leap::Deserialize(ms);

Maybe you have a buffer already that you want to deserialize

char buf[1024];
FillMyBuffer(buf, 1024);

leap::BufferedStream bs{buf, sizeof(buf), sizeof(buf)};
std::shared_ptr<MyClass> mc = leap::Deserialize<MyClass>(bs);

Encryption and compression are supported, too. Encrypting and compressing streams are declared as a filter. Protobuf's zero copy streams are similarly implemented. Here's how you might encrypt a file directly to disk with an std::ofstream. Make sure you fill key with a cryptographic function or you might be vulnerable to a related key attack.

std::array<uint8_t, 32> myKey;

std::ofstream of("myfile.dat");
leap::OutputStreamAdapter osa(of);
leap::CompressionStream<Zlib> cs { osa };
leap::AESEncryptionStream ecs { cs, myKey };
MyObject obj;
leap::Serialize(ecs, obj);

If you use encryption and compression, make sure the compression step happens before the encryption step, otherwise you will wind up making the file size larger.

More Repositories

1

leapjs

JavaScript client for the Leap Motion Controller
JavaScript
1,980
star
2

ProjectNorthStar

The open-source files comprising Leap Motion's Project North Star AR Headset.
C
1,616
star
3

LeapMotionCoreAssets

Unity Assets for Leap Motion v2 Skeletal Tracking
C#
164
star
4

autowiring

A C++ Inversion of Control Framework
C++
147
star
5

javascript

Leap Motion Javascript / LeapJS Examples
JavaScript
113
star
6

leapjs-plugins

A collection of plugins available to be used with LeapJS.
JavaScript
112
star
7

leapuvc

Examples in Python, Matlab, and C for interpreting data from UVC-Enabled Leap Motion Peripherals
Python
96
star
8

leapjs-rigged-hand

Control hand models with the Leap Motion
CoffeeScript
93
star
9

LeapUnrealModules

Leap Motion Unreal modules and example content.
C#
62
star
10

Leap-Three-Camera-Controls

Camera Controls for Three.js using Leap Motion
JavaScript
61
star
11

InteractionEngine101

"What does the Interaction Engine do?"
C#
59
star
12

VRIntro

Leap Motion's intro to VR
C++
56
star
13

AppExperiments

Experimental applications and home of AppModules, a wide-ranging app toolkit.
C#
51
star
14

leapjs-widgets

LeapJS 3D Buttons, scrolling, and more
JavaScript
51
star
15

leapjs-playback

Record and play back Leap Motion frame data
JavaScript
48
star
16

Button-Builder

Build Buttons!
C#
38
star
17

leapjs-network

Use WebRTC to send LeapMotion data p2p
JavaScript
36
star
18

Paint

Leap-enabled 3D VR Painting.
C#
31
star
19

MagneticMesh

A Leap Motion Cinder interactive music visualizer. Pinch to create gravitational fields.
C++
25
star
20

VRCollage

Experiment w/ Leap Motion and Virtual Reality
JavaScript
18
star
21

Particles

Leap Motion experimental application: Particles!
C#
16
star
22

handmodels

15
star
23

ar-screen

Hackathon project for augmented reality screen
C++
15
star
24

touchless

Touchless Control for your PC, from Leap Motion V1
C++
15
star
25

LeapIPC

Leap Motion interprocess communications framework
C++
14
star
26

mt-windows

A MultiTouch driver for touch injection on Windows 7
C
12
star
27

cmake-modules

Helpful CMake modules - 3.0+
CMake
11
star
28

chrome-draw

JavaScript
10
star
29

sculpting

Beauty in design (formerly known as Freeform)
C++
10
star
30

Leap-TiltFive-Testing

Unity test scenes of hand tracking interactions with Tiltfive AR glasses
C#
10
star
31

QuickSwitch

QuickSwitch, VR to Passthrough
10
star
32

LeapShape

Browser BRep CAD in WebXR
JavaScript
9
star
33

tensorheaven

C++
9
star
34

PlasmaBall

Manipulate the Plasma Ball with ghostly hands
7
star
35

Galaxies

C#
7
star
36

DShowBaseClasses

Microsoft DirectShow base classes wrapped in CMake
C++
7
star
37

ArmHUD

ArmHUD Alpha
6
star
38

os-controls

Shortcuts, with libraries for GPU-accelerated overlays and more
C++
6
star
39

beer-pong

JavaScript
4
star
40

CityVisualizerVR

Fly around and interact with the city in VR
4
star
41

FlockingVR

Flocking fish demo in VR
4
star
42

libjpeg-turbo

git-svn mirror of sourceforge's libjpeg-turbo svn repository
C
4
star
43

FragmentalVR

A HMD version of the Fragmental 3D app
4
star
44

homebrew-leapmotion

Collection of homebrew formulas for Leap Motion libraries
Ruby
4
star
45

MirrorTest

Move squares on top of a mirror interface
C
4
star
46

Playground

Leap Motion V2 Introduction app and play zone!
C#
4
star
47

Leap3DObjectBrowser

Pull yourself through space by grabbing.
C
4
star
48

IconExtractor

A simple project for extracting the main icon from a Windows PE
C++
4
star
49

leap-excel

Leap Motion plugin for Excel
C#
3
star
50

RobotsVR

Put together dancing robots!
3
star
51

rawviewer

RawViewer for Leap Motion Controllers
C
3
star
52

LeapC-samples

The LeapSDK LeapC samples configured to build under Visual Studio 2017
C
3
star
53

ColliderVR

Straight-up cruisin' through the supercollider with Leap Motion and VR
3
star
54

Leap-Motion-Player

JavaScript
3
star
55

PlasmaBallVR

Plasma Ball for VR Head Mounted Display and Leap Motion Controller
3
star
56

LeapIntoOculus

A basic example of using the Leap Motion Controller with the Oculus Rift in C++
C
3
star
57

pipeman

A high-performance pipe manager for capturing images from Unity3D
C++
3
star
58

jenkins-build-per-branch

Groovy
2
star
59

dragon410c

kernel source of dragon410c for LeapMotion
C
2
star
60

DeskVR

Leap Desk VR
2
star
61

DualCameraAPI1

Simple DualCamera Preview App
Java
2
star
62

cpp

C++
2
star
63

RiggedHandVisualizer

GLSL
2
star
64

FreeImage

Modifications to build FreeImage for the Leap Motion environment
C
2
star
65

standard

A library containing the skeleton set for all new external library projects
CMake
2
star
66

BattleshipVR

BattleshipVR
2
star
67

pyopticam

A nanobind wrapper for NaturalPoint's Optitrack Camera SDK
C++
2
star
68

leapmusic

Java
2
star
69

orientation

Leap Motion's V1 Orientation
C++
2
star
70

FurnitureDestructionDemo

2
star
71

AppSwitcher

A very simple XML configurable application switcher utility
C#
2
star
72

WrenAR-VR-UI

WrenAR VR/UI
2
star
73

ImageAPIinObjectiveC

Demonstrates how to use the Image API in Objective-C projects
Objective-C
2
star
74

GrayImageViewer

This is a tool to view 8bit gray images
C++
2
star
75

Flocking

Flocking VR
CMake
1
star
76

punch-out

Boxing game demo from the April 2014 Leap Motion V2 hackathon
Python
1
star
77

apphome

Leap Motion App Home
JavaScript
1
star
78

VRHelloWorld

C
1
star
79

leap-facebook-chat

JavaScript
1
star
80

ShieldVR

Shield VR Example Project
1
star
81

usbbldr

USB descriptor builder repository
C++
1
star
82

mipivideo

A low level MIPI video transport API consumed by LeapSvc!
C++
1
star
83

hudson-tray-tracker

C#
1
star
84

leapCopter

JavaScript
1
star
85

FoxBlox

MATLAB
1
star
86

LeapHTTP

The libraries used by Leap Motion to perform certain HTTP operations
C++
1
star
87

hackathon-leap-signature

CSS
1
star
88

LaserVR

LaserVR Example
1
star
89

talks

Talks Given
JavaScript
1
star
90

VRQuickSwitch

The Leap Motion VR/AR Quick Switcher Experiment
1
star
91

leapshell

3D File system, "Utility" category winner from the April 2014 Leap Motion V2 hackathon
C++
1
star
92

anttweakbar

Leap Motion's modifications of anttweakbar repo
C++
1
star
93

OSCTutorialSite

OSCTutorialSite
CSS
1
star