def _value(self, offset, amount): from lobvar import vt_CLOB, vt_NCLOB """Return a portion (or all) of the data in the external LOB variable.""" lob_type = self.lob_var.type # modify the arguments if offset < 0: offset = 1 if amount < 0: amount = self._internal_size() amount = amount - offset + 1; if amount <= 0: amount = 1 buffer = self._internal_read(offset, amount) if lob_type == vt_CLOB: #if self.lob_var.environment.fixedWidth: # length = length * self.lob_var.environment.maxBytesPerCharacter result = cxString_from_encoded_string(buffer, self.lob_var.environment.encoding) elif lob_type == vt_NCLOB: result = buffer.decode(self.lob_var.environment.encoding) else: result = bytes(buffer) return result
def _value(self, offset, amount): from lobvar import vt_CLOB, vt_NCLOB """Return a portion (or all) of the data in the external LOB variable.""" lob_type = self.lob_var.type # modify the arguments if offset < 0: offset = 1 if amount < 0: amount = self._internal_size() amount = amount - offset + 1 if amount <= 0: amount = 1 buffer = self._internal_read(offset, amount) if lob_type == vt_CLOB: #if self.lob_var.environment.fixedWidth: # length = length * self.lob_var.environment.maxBytesPerCharacter result = cxString_from_encoded_string( buffer, self.lob_var.environment.encoding) elif lob_type == vt_NCLOB: result = buffer.decode(self.lob_var.environment.encoding) else: result = bytes(buffer) return result
def parse(self, c): if len(c) == 0: # no data received return False if DEBUG: # print(self.__parse_state) print(repr(c)) if self.__parse_state == ParseState.WAITING_FOR_HEAD: # reset msg self.__msg_id = None self.__checksum = 0 self.__data = b'' if c == bytes(HEAD): if DEBUG: print('got head') self.__checksum += ord(c) self.__parse_state += 1 return False if self.__parse_state == ParseState.WAITING_FOR_ID: if DEBUG: print('got id ', ord(c)) self.__msg_id = ord(c) self.__checksum += ord(c) self.__parse_state += 1 return False if self.__parse_state == ParseState.WAITING_FOR_LEN: if DEBUG: print('got len ', ord(c)) self.__msg_len = ord(c) self.__checksum += ord(c) self.__parse_state += 1 return False if self.__parse_state == ParseState.WAITING_FOR_DATA: if self.__msg_len > 0: self.__data += c self.__checksum += ord(c) self.__msg_len -= 1 else: if DEBUG: print('got complete data') self.__parse_state = ParseState.CHECKSUM if self.__parse_state == ParseState.CHECKSUM: if DEBUG: print(ord(c), " ", self.__checksum & 0xff) if ord(c) == self.__checksum & 0xff: if DEBUG: print('checksum ok') self.__new_message = self.__msg_id self.__parse_state = ParseState.WAITING_FOR_HEAD return True else: if DEBUG: print('checksum error, message discarded') self.__parse_state = ParseState.WAITING_FOR_HEAD return False
def encode(self, msg_id, msg): ''' encodes a message returns a bytes str ready to send @param msg_id: message id @param msg: a message object --- @return b_msg: bytes str ''' head = bytes(HEAD) msg_id = bytes(msg_id) data = msg.pack() msg_len = bytes(len(data)) lb_msg = head + msg_id + msg_len + data checksum = 0 for i in range(len(lb_msg)): checksum += int(lb_msg[i]) checksum = checksum & 0xff b_msg = lb_msg + bytes(checksum) return b_msg
def get_value(self, var, pos): base_ptr_address = ctypes.addressof(var.data) + var.bufferSize * pos c_length = oci.ub4.from_address(base_ptr_address) length = c_length.value start_address = var.bufferSize * pos + ctypes.sizeof(oci.ub4) the_contents = var.data[start_address: start_address + length] if var.type == vt_LongBinary: return bytes(the_contents) return cxString_from_encoded_string(the_contents, var.environment.encoding)
def get_value(self, var, pos): base_ptr_address = ctypes.addressof(var.data) + var.bufferSize * pos c_length = oci.ub4.from_address(base_ptr_address) length = c_length.value start_address = var.bufferSize * pos + ctypes.sizeof(oci.ub4) the_contents = var.data[start_address:start_address + length] if var.type == vt_LongBinary: return bytes(the_contents) return cxString_from_encoded_string(the_contents, var.environment.encoding)