# Path: groundstation/gref.py
# def valid_path(path):
#     def __init__(self, store, channel, identifier):
#     def __str__(self):
#     def exists(self):
#     def tips(self):
#     def node_path(self):
#     def write_tip(self, tip, signature):
#     def tip_path(self, tip):
#     def __iter__(self):
#     def get_signature(self, tip):
#     def remove_tip(self, tip, silent=False):
#     def direct_parents(self, tip):
#     def parents(self, tips=None):
#     def marshall(self, crypto_adaptor=None):
#         def _process(node):
#     def as_dict(self):
# class Gref(object):
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


import struct
import base64
import quietnet.listen as listen
from groundstation.gref import Gref, Tip
from groundstation import logger
                    header_bytes[0] |= char_value & 0xf
                    header_byte_count += 1
                elif header_byte_count == 1:
                    header_bytes[0] |= (char_value & 0xf) << 4
                    header_byte_count += 1
                elif header_byte_count == 2:
                    header_bytes[1] |= (char_value & 0xf)
                    header_byte_count += 1
                elif header_byte_count == 3:
                    header_bytes[1] |= (char_value & 0xf) << 4
                    header_byte_count += 1
                    header_length = struct.unpack(">h", ''.join(map(chr, header_bytes)))[0]
                    log.info("Reading %d bytes of payload" % header_length)
                    payload = reset_payload()
                elif header_byte_count == 4:
                    log.warning("Got header bytes while still expecting payload")
                    payload.append(char)

            else: # Payload byte
                if header_length == 0:
                    log.warning("Got payload bytes when expecting header")
                payload.append(char)
                if len(payload) % 8 == 0:
                    log.info("Got %d bytes so far" % (len(payload)))
                if len(payload) == header_length:
                    log.info("Got all of object")
                    decoded = base64.b64decode(''.join(payload))
                    log.info("Writing payload to DB")
                    oid = self.station.write(decoded)
                    log.info("Wrote object, got: %s" % (repr(oid)))

# Path: groundstation/gref.py
# def valid_path(path):
#     def __init__(self, store, channel, identifier):
#     def __str__(self):
#     def exists(self):
#     def tips(self):
#     def node_path(self):
#     def write_tip(self, tip, signature):
#     def tip_path(self, tip):
#     def __iter__(self):
#     def get_signature(self, tip):
#     def remove_tip(self, tip, silent=False):
#     def direct_parents(self, tip):
#     def parents(self, tips=None):
#     def marshall(self, crypto_adaptor=None):
#         def _process(node):
#     def as_dict(self):
# class Gref(object):
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


# Path: groundstation/audio_receiver.py
import struct
import base64
import quietnet.listen as listen
from groundstation.gref import Gref, Tip
from groundstation import logger

                    header_bytes[0] |= char_value & 0xf
                    header_byte_count += 1
                elif header_byte_count == 1:
                    header_bytes[0] |= (char_value & 0xf) << 4
                    header_byte_count += 1
                elif header_byte_count == 2:
                    header_bytes[1] |= (char_value & 0xf)
                    header_byte_count += 1
                elif header_byte_count == 3:
                    header_bytes[1] |= (char_value & 0xf) << 4
                    header_byte_count += 1
                    header_length = struct.unpack(">h", ''.join(map(chr, header_bytes)))[0]
                    log.info("Reading %d bytes of payload" % header_length)
                    payload = reset_payload()
                elif header_byte_count == 4:
                    log.warning("Got header bytes while still expecting payload")
                    payload.append(char)

            else: # Payload byte
                if header_length == 0:
                    log.warning("Got payload bytes when expecting header")
                payload.append(char)
                if len(payload) % 8 == 0:
                    log.info("Got %d bytes so far" % (len(payload)))
                if len(payload) == header_length:
                    log.info("Got all of object")
                    decoded = base64.b64decode(''.join(payload))
                    log.info("Writing payload to DB")
                    oid = self.station.write(decoded)
                    log.info("Wrote object, got: %s" % (repr(oid)))

                    Gref(self.station.store, "soundstation", "demo")