public class

JsonStreamer

extends VehicleMessageStreamer
java.lang.Object
   ↳ com.openxc.messages.streamers.VehicleMessageStreamer
     ↳ com.openxc.messages.streamers.JsonStreamer

Class Overview

A class to deserialize and serialize JSON-formatted vehicle messages from byte streams. The JsonStreamer wraps the JsonFormatter and handles messages delimiting. It uses a delimiter as specified by the OpenXC message format. Unlike the JsonFormatter, the JsonStreamer is not stateless. It maintains an internal buffer of bytes so that if partial messages is received it can eventually receive an parse the entire thing.

Summary

Public Constructors
JsonStreamer()
Public Methods
static boolean containsJson(String buffer)
Return true if the buffer *most likely* contains JSON (as opposed to a protobuf).
VehicleMessage parseNextMessage()
Deserialize and return the next messages from the internally buffered stream.
void receive(byte[] bytes, int length)
Add additional bytes to the buffer from the data source.
byte[] serializeForStream(VehicleMessage message)
Serialize the message and insert any required delimiters for insertion into a message stream.
[Expand]
Inherited Methods
From class com.openxc.messages.streamers.VehicleMessageStreamer
From class java.lang.Object

Public Constructors

public JsonStreamer ()

Public Methods

public static boolean containsJson (String buffer)

Return true if the buffer *most likely* contains JSON (as opposed to a protobuf).

public VehicleMessage parseNextMessage ()

Deserialize and return the next messages from the internally buffered stream.

Returns
  • the next deserialized VehicleMessage.

public void receive (byte[] bytes, int length)

Add additional bytes to the buffer from the data source.

Parameters
bytes an array of bytes received from the interface.
length number of bytes received, and thus the amount that should be read from the array.

public byte[] serializeForStream (VehicleMessage message)

Serialize the message and insert any required delimiters for insertion into a message stream.

Parameters
message the message to serialize.