Getting started (TypeScript)
Getting Started with Bebop in TypeScript
Bebop is a high-performance serialization framework designed for efficient data transfer. This guide will walk you through setting up Bebop in your TypeScript project, creating schemas, and using the generated code.
Installation
First, let’s install the necessary packages:
Package | Downloads |
---|---|
bebop | |
bebop-tools |
Install Bebop Runtime
Install Bebop Compiler
Project Initialization
Initialize your Bebop project:
This command creates a bebop.json
file in your project root. Open this file and add a TypeScript generator:
This configuration tells Bebop to:
- Include all
.bop
files in your project - Generate TypeScript code
- Output the generated code to
src/bops.gen.ts
Creating Bebop Schemas
Bebop uses its own schema language to define data structures. Create a new file with a .bop
extension (e.g., schemas.bop
) and define your schemas:
Generating TypeScript Code
After defining your schemas, generate the TypeScript code:
This command will generate TypeScript code based on your Bebop schemas.
Using Generated Code
Now you can use the generated code in your TypeScript project. Here’s an example of how to create and encode a Person
object:
JSON Serialization (JSON-Over-Bebop)
Bebop supports JSON serialization using JSON-Over-Bebop. This format allows for efficient serialization and deserialization of Bebop objects to and from JSON.
For more information on JSON-Over-Bebop, refer to the JSON-Over-Bebop specification.
Here’s how to use JSON serialization: