# -*- coding: cp936 -*-

import ctypes
import logging
import os
import sys


#各版本处理的基类，不需要修改，其它的继承即可
class BaseProc:
    def __init__(self, old, new):
        self.old = old
        self.new = new

    def GetOldNew(self):
        return self.old, self.new

    

# ActivePython 2.6.6.15
# Windows 7 
# 2010.10.30
# PM 12:26
# xialulee

def struct2stream(s):
    length  = ctypes.sizeof(s)
    p       = ctypes.cast(ctypes.pointer(s), ctypes.POINTER(ctypes.c_char * length))
    return p.contents.raw

def stream2struct(string, stype):
    if not issubclass(stype, ctypes.LittleEndianStructure):
        raise ValueError('The type of the struct is not a ctypes.LittleEndianStructure')
    length      = ctypes.sizeof(stype)
    stream      = (ctypes.c_char * length)()
    stream.raw  = string
    p           = ctypes.cast(stream, ctypes.POINTER(stype))
    return p.contents

