def get_int(self,rp): #log("Pipe.get_int(%s) read_size=%s"%(self,self.read_size())) sz=rp.read_size() if sz: rmem=rp.reader_mem() s=sonic.ptrvalue(rmem,0,"char")[:] #print s rp.consume(sz) try: return int(s) except ValueError: return None return None
def get_char(self,rp): #log("Pipe.get_char(%s) read_size=%s"%(self,self.read_size())) sz=rp.read_size() if sz: rmem=rp.reader_mem() s="" log("rmem = ",rmem) for i in range(sz): c=sonic.ptrvalue(rmem,i,"char")[0] # [0] discards junk ... s=s+c rp.consume(sz) return string.join(s) return None
def read_short(self): assert self.read_size()>1 x=sonic.ptrvalue(self.reader_mem(),0,"short") self.consume(2) assert type(x)==int return x