import json
import config as cfg
LenFunc = cfg.LenFunc



class Parser():
    def __init__(self):
        print("parser created")
        
    def toJSON(self, data):
        return json.loads(data)

    def toSTRING(self, data):
        return json.dumps(data)

    def toSEND(self, data):
        j = json.dumps(data)
        l = LenFunc - len(str(len(j)))
        return "00000"[0:l]+str(len(j))+j

    def add(self,data,k,v):
        try:
            data[k] = v
            return data
        except:
            print("\33[41m\33[41mAn exception occurred  add\33[0m" )

    def parser(self,data,addr,id):
        data = self.toJSON(data)
        print("Simple parser ->",data)
