def _write_bytes(mongocrypt_binary, data): """Writes the given data to a mongocrypt_binary_t.""" buf = lib.mongocrypt_binary_data(mongocrypt_binary) if buf == ffi.NULL: raise MongoCryptError('mongocrypt_binary_data returned NULL') ffi.memmove(buf, data, len(data))
def to_bytes(self): """Returns this mongocrypt_binary_t as bytes.""" data = lib.mongocrypt_binary_data(self.bin) if data == ffi.NULL: return b'' data_len = lib.mongocrypt_binary_len(self.bin) return ffi.unpack(ffi.cast("char*", data), data_len)
def _to_bytes(mongocrypt_binary): """Returns this mongocrypt_binary_t as bytes.""" data = lib.mongocrypt_binary_data(mongocrypt_binary) if data == ffi.NULL: raise MongoCryptError('mongocrypt_binary_data returned NULL') data_len = lib.mongocrypt_binary_len(mongocrypt_binary) return ffi.unpack(ffi.cast("char*", data), data_len)