"""LCM type definitions
This file automatically generated by lcm.
DO NOT MODIFY BY HAND!!!!
"""

try:
    import cStringIO.StringIO as BytesIO
except ImportError:
    from io import BytesIO
import struct

import mbari.header_t

class phi_theta_psi_t(object):
    __slots__ = ["header", "phi", "theta", "psi"]

    __typenames__ = ["mbari.header_t", "double", "double", "double"]

    __dimensions__ = [None, None, None, None]

    def __init__(self):
        self.header = mbari.header_t()
        self.phi = 0.0
        self.theta = 0.0
        self.psi = 0.0

    def encode(self):
        buf = BytesIO()
        buf.write(phi_theta_psi_t._get_packed_fingerprint())
        self._encode_one(buf)
        return buf.getvalue()

    def _encode_one(self, buf):
        assert self.header._get_packed_fingerprint() == mbari.header_t._get_packed_fingerprint()
        self.header._encode_one(buf)
        buf.write(struct.pack(">ddd", self.phi, self.theta, self.psi))

    def decode(data):
        if hasattr(data, 'read'):
            buf = data
        else:
            buf = BytesIO(data)
        if buf.read(8) != phi_theta_psi_t._get_packed_fingerprint():
            raise ValueError("Decode error")
        return phi_theta_psi_t._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = phi_theta_psi_t()
        self.header = mbari.header_t._decode_one(buf)
        self.phi, self.theta, self.psi = struct.unpack(">ddd", buf.read(24))
        return self
    _decode_one = staticmethod(_decode_one)

    _hash = None
    def _get_hash_recursive(parents):
        if phi_theta_psi_t in parents: return 0
        newparents = parents + [phi_theta_psi_t]
        tmphash = (0x1cd8079225ae36f0+ mbari.header_t._get_hash_recursive(newparents)) & 0xffffffffffffffff
        tmphash  = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff
        return tmphash
    _get_hash_recursive = staticmethod(_get_hash_recursive)
    _packed_fingerprint = None

    def _get_packed_fingerprint():
        if phi_theta_psi_t._packed_fingerprint is None:
            phi_theta_psi_t._packed_fingerprint = struct.pack(">Q", phi_theta_psi_t._get_hash_recursive([]))
        return phi_theta_psi_t._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

