Skip to content

Commit

Permalink
docs: add rough readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx committed Dec 12, 2023
1 parent 6842573 commit 7b6c6b8
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# yamcs-protobufjs-static

WIP
This package provides protobufjs definitions and typings for YAMCS.

To use:

```js
// Import the package
import { google, yamcs } from 'yamcs-protobufjs-static';

// Extract the needed types
const { SubscribeParametersRequest } = yamcs.protobuf.processing;
const { ClientMessage, CancelOptions } = yamcs.api;
const { Any } = google.protobuf;

const socket = new WebSocket('ws://localhost:8090/', 'protobuf');
socket.binaryType = 'arraybuffer';

let connected = false;

socket.onopen = () => {
connected = true;
}

// Example of subscribing to a parameter
const id = [yamcs.protobuf.NamedObjectId.create({ name: 'myNamedObject'})];
const message = {
type: 'parameters',
instance: 'myInstance',
processor: 'myProcessor',
id,
sendFromCache: true,
updateOnExpiration: true
};

// Verify that it fits the schema of a `SubscribeParametersRequest`
let err = SubscribeParametersRequest.verify(message);
if (err) {
throw Error(err);
}

let payload = SubscribeParametersRequest.create(message);
const arrayBuffer = SubscribeParametersRequest.encode(payload).finish();
const clientMessagePayload = {
type: dataType,
id: subscriptionId,
options: Any.create({
type_url: SubscribeParametersRequest.getTypeUrl(),
value: arrayBuffer
})
};

// Verify that it fits the schema of a `ClientMessage`
err = ClientMessage.verify(clientMessagePayload);
if (err) {
throw Error(err);
}

const clientMessage = ClientMessage.create(clientMessagePayload);

if(connected) {
socket.send(ClientMessage.encode(clientMessage).finish());
}
```

0 comments on commit 7b6c6b8

Please sign in to comment.