示例#1
0
const protobuf = require("protobufjs/light");
const simWorldRoot = protobuf.Root.fromJSON(
    require("proto_bundle/sim_world_proto_bundle.json")
);
const SimWorldMessage = simWorldRoot.lookupType("apollo.dreamview.SimulationWorld");
const mapMessage = simWorldRoot.lookupType("apollo.hdmap.Map");
const pointCloudRoot = protobuf.Root.fromJSON(
    require("proto_bundle/point_cloud_proto_bundle.json")
);
const pointCloudMessage = pointCloudRoot.lookupType("apollo.dreamview.PointCloud");

self.addEventListener("message", event => {
    let message = null;
    const data = event.data.data;
    switch (event.data.source) {
        case "realtime":
            if (typeof data === "string") {
                message = JSON.parse(data);
            } else {
                message = SimWorldMessage.toObject(
                    SimWorldMessage.decode(new Uint8Array(data)),
                    { enums: String });
                message.type = "SimWorldUpdate";
            }
            break;
        case "map":
            message = mapMessage.toObject(
                mapMessage.decode(new Uint8Array(data)),
                {enums: String});
            message.type = "MapData";
            break;
示例#2
0
import {Centrifuge} from './centrifuge.js';

const protobuf = require('protobufjs/light');
const proto = protobuf.Root.fromJSON(require('./client.proto.json'));

const methodValues = proto.lookupEnum('MethodType').values;

const protobufMethodType = {
  CONNECT: methodValues.CONNECT,
  SUBSCRIBE: methodValues.SUBSCRIBE,
  UNSUBSCRIBE: methodValues.UNSUBSCRIBE,
  PUBLISH: methodValues.PUBLISH,
  PRESENCE: methodValues.PRESENCE,
  PRESENCE_STATS: methodValues.PRESENCE_STATS,
  HISTORY: methodValues.HISTORY,
  PING: methodValues.PING,
  RPC: methodValues.RPC,
  SEND: methodValues.SEND,
  REFRESH: methodValues.REFRESH,
  SUB_REFRESH: methodValues.SUB_REFRESH
};

const methodSchema = {
  CONNECT: [
    proto.lookupType('proto.ConnectRequest'),
    proto.lookupType('proto.ConnectResult')
  ],
  REFRESH: [
    proto.lookupType('proto.RefreshRequest'),
    proto.lookupType('proto.RefreshResult')
  ],