-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from NASA-AMMOS/issue-299
Issue #299 - Update server 0MQ data passing
- Loading branch information
Showing
6 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Advanced Multi-Mission Operations System (AMMOS) Instrument Toolkit (AIT) | ||
# Bespoke Link to Instruments and Small Satellites (BLISS) | ||
# | ||
# Copyright 2021, by the California Institute of Technology. ALL RIGHTS | ||
# RESERVED. United States Government Sponsorship acknowledged. Any | ||
# commercial use must be negotiated with the Office of Technology Transfer | ||
# at the California Institute of Technology. | ||
# | ||
# This software may be subject to U.S. export control laws. By accepting | ||
# this software, the user agrees to comply with all applicable U.S. export | ||
# laws and regulations. User has the responsibility to obtain export licenses, | ||
# or other export authority as may be required before exporting such | ||
# information to foreign countries or providing access to foreign persons. | ||
|
||
|
||
import pickle | ||
|
||
|
||
def encode_message(topic, data): | ||
"""Encode a message for sending via 0MQ | ||
Given a string topic name and a pickle-able data object, encode and prep | ||
the data for sending via `send_multipart` | ||
Returns a list of the form: | ||
[ | ||
Bytes object of String (UTF-8), | ||
Pickled data object | ||
] | ||
If encoding fails None will be returned. | ||
""" | ||
try: | ||
enc = [bytes(topic, 'utf-8'), pickle.dumps(data)] | ||
except: | ||
enc = None | ||
|
||
return enc | ||
|
||
|
||
def decode_message(msg): | ||
"""Decode a message received via 0MQ | ||
Given a message received from `recv_multipart`, decode the components. | ||
Returns a tuple of the form: | ||
( | ||
UTF-8 string | ||
De-pickled data object | ||
) | ||
If decoding fails a tuple of None objects will be returned. | ||
""" | ||
[topic, message] = msg | ||
|
||
try: | ||
tpc = topic.decode('utf-8') | ||
msg = pickle.loads(message) | ||
except: | ||
tpc = None | ||
msg = None | ||
|
||
return (tpc, msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ait.core.server.utils module | ||
============================ | ||
|
||
.. automodule:: ait.core.server.utils | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |