JSON Codec

Source code: https://github.com/yomorun/yomo/tree/master/example/json

This example represents how to use JSON Codec in YoMo.

  1. In source, use json.Marshal(data) to encode the data via JSON.
// Encode data via JSON.
sendingBuf, _ := json.Marshal(data)

// send data to YoMo-Zipper via QUIC stream.
_, err := stream.Write(sendingBuf)
  1. In stream-fn, use Unmarshal operator to decode the data via JSON, and then use Marshal operator to encode the data back to the stream.
func Handler(rxstream rx.Stream) rx.Stream {
    stream := rxstream.
        Unmarshal(json.Unmarshal, func() interface{} { return &NoiseData{} }).
        Map(computePeek).
        Marshal(json.Marshal)

    return stream
}

How to run the example

1. Install YoMo CLI

Please visit YoMo Getting Started for details.

2. Run YoMo-Zipper

yomo serve -c ./zipper/workflow.yaml

3. Run Stream-Function

yomo run ./stream-fn/app.go -n Noise

4. Run YoMo-Source

go run ./source/main.go