Examples / Myra Codec

Order Book Snapshot

myra-codec-orderbook

Encode and decode full order book snapshots with repeated levels, optional fields, and metadata.

Codec Gradle Java 25 View source

Overview

This example builds a full market snapshot using schema generated writers, then decodes it with flyweights. It also loads JSON snapshots from data/order_book_snapshot.json and maps them into repeated bids, asks, and metadata entries.

Clone and run

  1. Install Java 25 and Git, then confirm the toolchain.

    java --version
  2. Clone the examples repository.

    git clone https://github.com/mvp-express/examples.git
  3. Move into the order book example folder.

    cd examples/myra-codec-orderbook
  4. Generate sources and the lock file.

    ./gradlew codegen
  5. Run the demo app.

    ./gradlew run

If you are on Windows, use gradlew.bat instead of ./gradlew.

Concepts highlighted

  • Repeated bids and asks via LevelArrayWriter and flyweight readers.
  • Optional fields such as tradingStatus and lastTrade with presence checks.
  • Metadata key/value entries serialized as repeated fields.
  • Zero copy decode path using OrderBookSnapshotFlyweight and MessageHeader.
  • Pooled segments and scratch buffers for low allocation encoding.

Files to explore

  • src/main/resources/schemas/order_book.myra.yml
  • src/main/resources/data/order_book_snapshot.json
  • src/main/java/express/mvp/myra/codec/examples/ExampleApp.java

At a glance

  • Type: Myra Codec
  • Build: Gradle
  • Main: ExampleApp
  • Schema: order_book.myra.yml
  • Output: Console logs
Open on GitHub

Learn more

Dig deeper into schema design and flyweights in the codec docs.

Myra Codec Docs