Skip to content

Data serialization

Jitar comes with a powerful (de)serializer that is used for sharing data between workers. In this section you'll find more information on this topic..

Note: The serializer is available as a separate NPM package that you can use in your own project. You can find more information on this in the readme of the package.

Build-in serializers

We try to support all JavaScript built-in types. Currently we support:

  • Primitives (bool, number, string, etc.)
  • Objects (plain and class instances)
  • Collections (Array, Map and Set)
  • Data buffers (Typed Arrays)
  • Others (BigInt, Date, RegExp and URL)

Adding your own

The serialization package is open for implementing your own serializers in case your application has special (de)serialization needs. This can be done by creating a custom serializer and adding it to the server. Documentation how to build a custom serializer can be found in the readme of the serialization package.

ts
//src/jitar.ts
import { buildServer } from 'jitar';
import CustomSerializer from './CustomSerializer.js';

const moduleImporter = async (specifier: string) => import(specifier);

const server = await buildServer(moduleImporter);

server.addSerializer(new CustomSerializer());

process.on('SIGINT', async () => server.stop());

server.start();

Jitar uses a default class loader. If you need the class loader in your custom serializer you can get it from the server instance.

ts
const classLoader = server.classLoader;

Jitar is a project by Masking Technology