Cookie Cutter

Cookie Cutter

  • Introduction
  • API
  • Help

›Components

Introduction

  • Getting Started
  • Inputs
  • Message Handling
  • Outputs
  • Versioning and Contribution Guide

Components

  • Dispatch Context
  • State
  • Metrics
  • Tracing
  • Logging
  • Validation
  • Encoding
  • Config
  • Testing

Modules

  • Kafka
  • Azure
  • AMQP
  • gRPC
  • ValidateJS
  • MSSQL
  • Timer
  • StatsD
  • Protobuf
  • Prometheus
  • Redis
  • S3
  • Google PubSub

Encoding

Input sources, output sinks and state providers will typically require a mechanism to decode a message coming off the wire or encode a message to put onto the write respectively. Cookie Cutter provides this functionality via its IMessageEncoder abstraction.

Interfaces

export interface IMessageEncoder {
    readonly mimeType: string;
    encode(msg: IMessage): Uint8Array;
    decode(data: Uint8Array, typeName: string): IMessage;
}

export interface IEncodedMessageEmbedder {
    toJsonEmbedding(encoded: Uint8Array): any;
    fromJsonEmbedding(embedding: any): Uint8Array;
}

Any encoder must implement IMessageEncoder and may optionally implement IEncodedMessageEmbedder. The latter is used for storage mechanisms that use JSON natively and it allows the data to be formatted nicely so it remains human-readable; for example the encode function of the JsonMessageEncoder returns a byte array that contains the serialized JSON. If the underlying storage mechanism itself is JSON then we wouldn't want the data to be stored as a base64 representation of that byte array, but as the data itself.

JsonMessageEncoder

The JsonMessageEncoder encodes the payload of IMessage as JSON. On the decoding side it requires a typeName hint to be passed in as the JSON itself doesn't contain any information about the type name.

CsvMessageEncoder

The CsvMessageEncoder encodes the payload of IMessage as CSV. The constructor requires the names of the header columns (which have to match the field names of the payload object), the delimiter to use and optionally a fixed type name if no type name hint can be passed into the decode function.

← ValidationConfig →
  • Interfaces
  • JsonMessageEncoder
  • CsvMessageEncoder
Cookie Cutter
Docs
IntroductionKafka
More
Blog
Copyright © 2023 Walmart Inc.