def prepareLoiData(self): sys.path.append("./protobuf_messages") from loi_pb2 import LOIForegroundBlobData MSG = LOIForegroundBlobData() loiFileList = glob.glob('templates/loi_template_??.blobproto') loiFileList.sort() timeStr = time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime(self.prevDataTimestamp)) nameStr = str(self.name)+"_es_loi_"+timeStr+"_0_%s_%s_%s.blobproto"\ %(self.dataIndex, self.isOverlapped, self.isLastData) pathName = "%s/data/loi/%s"%(self.name, nameStr) with open(loiFileList[random.randint(0,2)], 'rb') as fp: MSG.ParseFromString(fp.read()) MSG.placementName = self.name MSG.viewId = 0 MSG.startTimestamp = self.prevDataTimestamp MSG.endTimestamp = self.currDataTimestamp with open(pathName, "wb") as outfile: outfile.write(MSG.SerializeToString()) outfile.close()
#!/usr/bin/env python import sys sys.path.append("./protobuf_messages") from loi_pb2 import LOIForegroundBlobData MSG = LOIForegroundBlobData() with open("templates/loi_template_01.blobproto",'rb') as infile: MSG.ParseFromString(infile.read()) print MSG MSG.startTimestamp = 1 MSG.endTimestamp =2 with open("test.out",'wb') as outfile: outfile.write(MSG.SerializeToString()) outfile.close()