Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Audit - rename confusing parser functions #459

Merged
merged 2 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/api-reference/parse-xviz.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# parseStreamMessage
# parseXVIZMessage

```js
import {parseStreamMessage, LOG_STREAM_MESSAGE} from '@xviz/parser';
import {parseXVIZMessage, XVIZ_MESSAGE} from '@xviz/parser';

parseStreamMessage({
parseXVIZMessage({
message,
onResult: data => {
switch (data.type) {
case LOG_STREAM_MESSAGE.METADATA: // do something
case LOG_STREAM_MESSAGE.TIMESLICE: // do something
case LOG_STREAM_MESSAGE.INCOMPLETE: // do something
case XVIZ_MESSAGE.METADATA: // do something
case XVIZ_MESSAGE.TIMESLICE: // do something
case XVIZ_MESSAGE.INCOMPLETE: // do something
}
},
onError: console.error,
Expand All @@ -23,7 +23,7 @@ Parameters:
- `opts` (Object)
- `message` (Object|String|ArrayBuffer) - XVIZ message to decode.
- `onResult` (Function) - callback if the message is parsed successfully. Receives a single
argument `data`. `data.type` is one of `LOG_STREAM_MESSAGE`.
argument `data`. `data.type` is one of `XVIZ_MESSAGE`.
- `onError` (Function) - callback if the parser encouters an error.
- `debug` (Function) - callback to log debug info.
- `worker` (Boolean|String) - use Web Wroker to parse the message. Enabling worker is recommended
Expand All @@ -37,7 +37,7 @@ Parameters:
- `capacity` (Number) - the limit on the number of messages to queue for the workers to process,
has no effect if set ot `null`. Default `null`.

##### LOG_STREAM_MESSAGE
##### XVIZ_MESSAGE

Enum of stream message types.

Expand Down
2 changes: 1 addition & 1 deletion modules/parser/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

/* eslint-disable camelcase */
export const LOG_STREAM_MESSAGE = {
export const XVIZ_MESSAGE_TYPE = {
METADATA: 'METADATA',
TIMESLICE: 'TIMESLICE',
DONE: 'DONE',
Expand Down
20 changes: 14 additions & 6 deletions modules/parser/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {default as xvizStats} from './utils/stats';
// GENERIC XVIZ EXPORTS

// Common constants
export {LOG_STREAM_MESSAGE} from './constants';
export {XVIZ_MESSAGE_TYPE} from './constants';

// Configuration
export {setXVIZConfig, getXVIZConfig} from './config/xviz-config';
Expand All @@ -42,20 +42,28 @@ export {default as XVIZObjectCollection} from './objects/xviz-object-collection'
export {parseLogMetadata} from './parsers/parse-log-metadata';
export {parseVehiclePose} from './parsers/parse-vehicle-pose';
export {parseEtlStream} from './parsers/parse-etl-stream';
export {parseStreamMessage, initializeWorkers} from './parsers/parse-stream-message';
export {parseXVIZMessage, initializeWorkers} from './parsers/parse-xviz-message';
export {
parseStreamDataMessage,
parseStreamLogData,
parseXVIZMessageSync,
parseXVIZData,
isXVIZMessage,
getXVIZMessageType,
getDataFormat,
isEnvelope,
unpackEnvelope
} from './parsers/parse-stream-data-message';
export {parseStreamVideoMessage} from './parsers/parse-stream-video-message';
} from './parsers/parse-xviz-message-sync';

export {default as lidarPointCloudWorker} from './workers/lidar-point-cloud-worker';
export {default as streamDataWorker} from './workers/stream-data-worker';

// Loaders
export {parseBinaryXVIZ, isBinaryXVIZ} from './loaders/xviz-loader/xviz-binary-loader';

// Deprecated
export {parseXVIZMessage as parseStreamMessage} from './parsers/parse-xviz-message';
export {
parseXVIZMessageSync as parseStreamDataMessage,
parseXVIZData as parseStreamLogData
} from './parsers/parse-xviz-message-sync';
export {parseVideoMessageV1 as parseStreamVideoMessage} from './parsers/parse-video-message-v1';
export {XVIZ_MESSAGE_TYPE as LOG_STREAM_MESSAGE} from './constants';
6 changes: 3 additions & 3 deletions modules/parser/src/parsers/parse-timeslice-data-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Extracts a TIMESLICE message v1
import {getXVIZConfig} from '../config/xviz-config';
import {LOG_STREAM_MESSAGE} from '../constants';
import {XVIZ_MESSAGE_TYPE} from '../constants';
import {parseStreamFutures, parseStreamPrimitive, parseStreamVariable} from './parse-xviz-stream';

export default function parseTimesliceData(data, convertPrimitive) {
Expand All @@ -32,13 +32,13 @@ export default function parseTimesliceData(data, convertPrimitive) {

if (!timestamp) {
// Incomplete stream message, just tag it accordingly so client can ignore it
return {type: LOG_STREAM_MESSAGE.INCOMPLETE};
return {type: XVIZ_MESSAGE_TYPE.INCOMPLETE};
}

const newStreams = {};
const result = {
...otherInfo,
type: LOG_STREAM_MESSAGE.TIMESLICE,
type: XVIZ_MESSAGE_TYPE.TIMESLICE,
streams: newStreams,
timestamp
};
Expand Down
12 changes: 6 additions & 6 deletions modules/parser/src/parsers/parse-timeslice-data-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// Extracts a TIMESLICE message v2
import {LOG_STREAM_MESSAGE, STATE_UPDATE_TYPE} from '../constants';
import {XVIZ_MESSAGE_TYPE, STATE_UPDATE_TYPE} from '../constants';
import {getXVIZConfig} from '../config/xviz-config';
import {parseXVIZPose} from './parse-xviz-pose';
import {
Expand All @@ -33,16 +33,16 @@ export default function parseStreamSet(data, convertPrimitive) {

if (!updateType) {
log.error(`update_type of "${update_type}" is not supported.`)();
return {type: LOG_STREAM_MESSAGE.INCOMPLETE, message: 'Unsupported update type'};
return {type: XVIZ_MESSAGE_TYPE.INCOMPLETE, message: 'Unsupported update type'};
}

if (!updates) {
return {type: LOG_STREAM_MESSAGE.INCOMPLETE, message: 'Missing required "updates" property'};
return {type: XVIZ_MESSAGE_TYPE.INCOMPLETE, message: 'Missing required "updates" property'};
}

if (updates && updates.length === 0) {
return {
type: LOG_STREAM_MESSAGE.INCOMPLETE,
type: XVIZ_MESSAGE_TYPE.INCOMPLETE,
message: 'Property "updates" has length of 0, no data?'
};
}
Expand All @@ -66,12 +66,12 @@ export default function parseStreamSet(data, convertPrimitive) {

if (!timestamp) {
// Incomplete stream message, just tag it accordingly so client can ignore it
return {type: LOG_STREAM_MESSAGE.INCOMPLETE, message: 'Missing timestamp in "updates"'};
return {type: XVIZ_MESSAGE_TYPE.INCOMPLETE, message: 'Missing timestamp in "updates"'};
}

const newStreams = {};
const result = {
type: LOG_STREAM_MESSAGE.TIMESLICE,
type: XVIZ_MESSAGE_TYPE.TIMESLICE,
updateType,
streams: newStreams,
timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
* `data` refers to pre-processed data objects (blob, arraybuffer, JSON object)
*/
/* global Blob */
import {LOG_STREAM_MESSAGE} from '../constants';
import {XVIZ_MESSAGE_TYPE} from '../constants';
import {TextDecoder} from '../utils/text-encoding';
import {blobToArrayBuffer} from '../utils/binary';

import {parseLogMetadata} from './parse-log-metadata';

// Handle messages from the stand alone video server
export function parseStreamVideoMessage(message, onResult, onError) {
export function parseVideoMessageV1(message, onResult, onError) {
if (message instanceof Blob) {
blobToArrayBuffer(message)
.then(arrayBuffer => {
parseStreamVideoMessage(arrayBuffer, onResult, onError);
parseVideoMessageV1(arrayBuffer, onResult, onError);
})
.catch(onError);
return;
Expand All @@ -57,13 +57,13 @@ export function parseStreamVideoData(data) {
return parseVideoMetadata(data);
}
// Unknown message
return {type: LOG_STREAM_MESSAGE.ERROR, message: 'Unknown stream data type', data};
return {type: XVIZ_MESSAGE_TYPE.ERROR, message: 'Unknown stream data type', data};
}

// Extract metadata from stream message
function parseVideoMetadata(data) {
const result = parseLogMetadata(data);
result.type = LOG_STREAM_MESSAGE.VIDEO_METADATA;
result.type = XVIZ_MESSAGE_TYPE.VIDEO_METADATA;

return result;
}
Expand All @@ -74,7 +74,7 @@ export function parseVideoFrame(arrayBuffer) {
const view = new DataView(arrayBuffer);

// Read off version
const result = {type: LOG_STREAM_MESSAGE.VIDEO_FRAME};
const result = {type: XVIZ_MESSAGE_TYPE.VIDEO_FRAME};
const littleEndian = true;
const utf8Decoder = new TextDecoder('utf-8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* `data` refers to pre-processed data objects (blob, arraybuffer, JSON object)
*/
/* global Blob, Uint8Array */
import {LOG_STREAM_MESSAGE} from '../constants';
import {XVIZ_MESSAGE_TYPE} from '../constants';
import {
parseBinaryXVIZ,
isBinaryXVIZ,
getBinaryXVIZJSONBuffer
} from '../loaders/xviz-loader/xviz-binary-loader';
import {parseLogMetadata} from './parse-log-metadata';
import {parseStreamVideoMessage} from './parse-stream-video-message';
import {parseVideoMessageV1} from './parse-video-message-v1';
import {TextDecoder} from '../utils/text-encoding';
import parseTimesliceDataV1 from './parse-timeslice-data-v1';
import parseTimesliceDataV2 from './parse-timeslice-data-v2';
Expand Down Expand Up @@ -238,12 +238,12 @@ export function isEnvelope(data) {
}

// Post processes a stream message to make it easy to use for JavaScript applications
export function parseStreamDataMessage(message, onResult, onError, opts) {
export function parseXVIZMessageSync(message, onResult, onError, opts) {
// TODO(twojtasz): better message dispatching
// here, not all arraybuffer may be image (packed point cloud)
// TODO(jlisee): Node.js support for blobs for better unit testing
if (typeof Blob !== 'undefined' && message instanceof Blob) {
parseStreamVideoMessage(message, onResult, onError);
parseVideoMessageV1(message, onResult, onError);
return;
}

Expand All @@ -262,15 +262,15 @@ export function parseStreamDataMessage(message, onResult, onError, opts) {
}

if (parseData) {
const result = parseStreamLogData(data, {...opts, v2Type});
const result = parseXVIZData(data, {...opts, v2Type});
onResult(result);
}
} catch (error) {
onError(error);
}
}

export function parseStreamLogData(data, opts = {}) {
export function parseXVIZData(data, opts = {}) {
// TODO(twojtasz): this data.message is due an
// uncoordinated change on the XVIZ server, temporary.
const typeKey = opts.v2Type || data.type || data.message || data.update_type;
Expand All @@ -282,16 +282,16 @@ export function parseStreamLogData(data, opts = {}) {
return {
...parseLogMetadata(data),
// ensure application sees the metadata type set to the uppercase version
type: LOG_STREAM_MESSAGE.METADATA
type: XVIZ_MESSAGE_TYPE.METADATA
};
case 'transform_log_done':
return {...data, type: LOG_STREAM_MESSAGE.DONE};
return {...data, type: XVIZ_MESSAGE_TYPE.DONE};
case 'error':
return {...data, message: 'Stream server error', type: LOG_STREAM_MESSAGE.ERROR};
return {...data, message: 'Stream server error', type: XVIZ_MESSAGE_TYPE.ERROR};

// v1 types
case 'done':
return {...data, type: LOG_STREAM_MESSAGE.DONE};
return {...data, type: XVIZ_MESSAGE_TYPE.DONE};
default:
// TODO(twojtasz): XVIZ should be tagging this with a type
return parseTimesliceData(data, opts.convertPrimitive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {parseStreamDataMessage} from './parse-stream-data-message';
import {parseXVIZMessageSync} from './parse-xviz-message-sync';
import {postDeserialize} from './serialize';
import {getWorkerFarm, initializeWorkerFarm} from './parse-stream-workerfarm';
import {getWorkerFarm, initializeWorkerFarm} from './parse-xviz-message-workerfarm';

// Public function for initializing workers
export function initializeWorkers({worker, maxConcurrency = 4, capacity = null}) {
initializeWorkerFarm({worker, maxConcurrency, capacity});
}

export function parseStreamMessage({
export function parseXVIZMessage({
message,
// callbacks
onResult,
Expand All @@ -46,6 +46,6 @@ export function parseStreamMessage({
const onMessage = data => onResult(postDeserialize(data));
workerFarm.process(message, onMessage, onError);
} else {
parseStreamDataMessage(message, onResult, onError);
parseXVIZMessageSync(message, onResult, onError);
}
}
4 changes: 2 additions & 2 deletions modules/parser/src/parsers/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Convert stream messages for safe transfer between threads
*/
import {LOG_STREAM_MESSAGE} from '../constants';
import {XVIZ_MESSAGE_TYPE} from '../constants';
import {getXVIZConfig} from '../config/xviz-config';
import XVIZObject from '../objects/xviz-object';

Expand All @@ -41,7 +41,7 @@ function observeObjects(objects, timestamp) {
* @params message {object} - received dehydrated message from other threads
*/
export function postDeserialize(message) {
if (message.type !== LOG_STREAM_MESSAGE.TIMESLICE) {
if (message.type !== XVIZ_MESSAGE_TYPE.TIMESLICE) {
return message;
}

Expand Down
10 changes: 5 additions & 5 deletions modules/parser/src/workers/stream-data-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.

import {setXVIZConfig} from '../config/xviz-config';
import {parseStreamDataMessage} from '../parsers/parse-stream-data-message';
import {parseXVIZMessageSync} from '../parsers/parse-xviz-message-sync';
import {preSerialize} from '../parsers/serialize';
import {getTransferList} from '../utils/worker-utils';
import {LOG_STREAM_MESSAGE} from '../constants';
import {XVIZ_MESSAGE_TYPE} from '../constants';

export default config => self => {
setXVIZConfig(config);
Expand All @@ -25,7 +25,7 @@ export default config => self => {
const transfers = new Set();

switch (message.type) {
case LOG_STREAM_MESSAGE.TIMESLICE:
case XVIZ_MESSAGE_TYPE.TIMESLICE:
for (const streamName in message.streams) {
const stream = message.streams[streamName];
getTransferList(stream.pointCloud, true, transfers);
Expand All @@ -36,7 +36,7 @@ export default config => self => {
}
break;

case LOG_STREAM_MESSAGE.VIDEO_FRAME:
case XVIZ_MESSAGE_TYPE.VIDEO_FRAME:
// v1 video stream
getTransferList(message.imageData, false, transfers);
break;
Expand Down Expand Up @@ -67,7 +67,7 @@ export default config => self => {
if (e.data && e.data.xvizConfig) {
setXVIZConfig(e.data.xvizConfig);
} else if (e.data) {
parseStreamDataMessage(e.data, onResult, onError);
parseXVIZMessageSync(e.data, onResult, onError);
}
};
};
4 changes: 2 additions & 2 deletions test/modules/conformance/renderer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {parseStreamMessage} from '@xviz/parser';
import {parseXVIZMessage} from '@xviz/parser';

export function parseFrame(frame) {
let result;
Expand All @@ -21,7 +21,7 @@ export function parseFrame(frame) {
throw error;
};

parseStreamMessage({
parseXVIZMessage({
message: frame,
onResult: message => {
result = message;
Expand Down
4 changes: 2 additions & 2 deletions test/modules/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import './synchronizers/xviz-stream-buffer.spec';

import './parsers/filter-vertices.spec';
import './parsers/parse-log-metadata.spec';
import './parsers/parse-stream-data-message.spec';
import './parsers/parse-stream-message.spec';
import './parsers/parse-xviz-message-sync.spec';
import './parsers/parse-xviz-message.spec';
import './parsers/parse-vehicle-pose.spec';
import './parsers/parse-xviz-pose.spec';
import './parsers/parse-xviz-stream.spec';
Expand Down
Loading