#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ===------------------------------*  Python  *------------------------------===
#             THIS FILE IS GENERATED BY INVAR. DO NOT EDIT !!!
# ===------------------------------------------------------------------------===

try:
    from cStringIO import StringIO
except:
    from StringIO import StringIO
from InvarCodec import DataWriter
from InvarCodec import DataReader

class Protoc2S(object):

    """客户端请求的公共数据"""
    CRC32_ = 0xC0869FC2
    SIZE_  = 5

    __slots__ = (
        '_sessionId',
        '_hotfix')
   #__slots__

    def __init__(self):
        self._sessionId = ''
        self._hotfix    = None
   #def __init__

    def __str__(self):
        s = StringIO()
        s.write(u'{')
        s.write(u' ')
        s.write(u'Protoc2S')
        s.write(u',')
        s.write(u' ')
        s.write(u'sessionId')
        s.write(u':')
        s.write(u'"')
        s.write(self._sessionId)
        s.write(u'"')
        s.write(u',')
        s.write(u' ')
        s.write(u'hotfix')
        s.write(u':')
        if self._hotfix is None:
            s.write(u'null')
        else:
            s.write(u'[')
            s.write(str(len(self._hotfix)))
            s.write(u']')
        s.write(u' ')
        s.write(u'}')
        result = s.getvalue()
        s.close()
        return result
   #def __str__

    def __len__(self):
        size = Protoc2S.SIZE_
        size += len(self._sessionId)
        if self._hotfix is not None:
            size += 4
            for (k1,v1) in self._hotfix.items():
                size += len(k1)
                size += len(v1)
        return size
   #def __len__

    def read(r):
        self._sessionId = r.readString()
        hotfixExists = r.readInt8()
        if 0x01 == hotfixExists:
            if self._hotfix == None:
                self._hotfix = dict()
            lenHotfix = r.readUInt32()
            num = 0
            while num < lenHotfix:
                num += 1
                k1 = r.readString()
                v1 = r.readString()
                self._hotfix[k1] = v1
        elif 0x00 == hotfixExists:
            self._hotfix = None
        else:
            raise InvarError(498, 'Protoc read error: The value of \'hotfixExists\' is invalid.')
   #def read

    def write(w):
        w.writeString(self._sessionId)
        if self._hotfix != None:
            w.writeUInt8(0x01)
            w.writeUInt32(len(self._hotfix))
            for (k1,v1) in self._hotfix.items():
                w.writeString(k1)
                w.writeString(v1)
        else:
            w.writeUInt8(0x00)
   #def write

#class Protoc2S

if '__main__' == __name__:
    print('dir(Protoc2S()) =>\n' + '\n'.join(dir(Protoc2S())))
    print('Protoc2S.__doc__ => ' + Protoc2S.__doc__)
    print('Protoc2S.__len__ => ' + str(len(Protoc2S())))
    print('Protoc2S.__str__ => ' + str(Protoc2S()))
