public void setBytes(Bytez source, long sourceIndex, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } // unsafe.copyMemory(source, bufoff+sourceIndex, ___bytes, ___offset, len); source.copyTo(___bytes, ___offset, sourceIndex, len); }
public void getBytes(byte[] target, int startIndexInTarget, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } ___bytes.getArr(___offset, target, startIndexInTarget, len); }
public void setBytes(byte[] source, int sourceIndex, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } ___bytes.set(___offset, source, sourceIndex, len); }
/** * @return the number of bytes used by the struct pointed to */ public int getByteSize() { if (!isOffHeap()) { return 0; } return ___bytes.getInt(___offset); }
public int getClzId() { if (!isOffHeap()) throw new RuntimeException("cannot call on heap"); return ___bytes.getInt(___offset + 4); }
/** * important: iterators, array access and access to substructures of a struct always return * pointers, which are cached per thread (one instance only!). To keep a pointer to a struct (e.g. search struct array and find an * element which should be kept as result) you need to detach it (removed from cache). * This method allocates a pointer. */ public <T extends FSTStruct> T detach() { if (isOffHeap()) { ___fac.detach(this); } return (T) this; }
/** * move offsets and memorybase to given pointer and return the pointer. * Eases dereferencing of nested structs without object creation. * If the given pointer is null, a new one will be created (alloc) * <pre> * MyStruct st = FSTStructFactory.getInstance().createEmptyStructPointer(FSTStruct.class); * otherStruct.getEmbeddedMyStruct().to(st); * </pre> */ public <T extends FSTStruct> T detachTo(T pointer) { if ( pointer == null ) { return detach(); } if (isOffHeap()) { pointer.___fac = ___fac; pointer.___bytes = ___bytes; pointer.___elementSize = ___elementSize; pointer.___offset = ___offset; return pointer; } return (T) this; }
/** * important: iterators, array access and access to substructures of a struct always return * pointers, which are cached per thread (one instance only!). To keep a pointer to a struct (e.g. search struct array and find an * element which should be kept as result) you need to detach it (removed from cache). * This method allocates a pointer. */ public <T extends FSTStruct> T detach() { if (isOffHeap()) { ___fac.detach(this); } return (T) this; }
public void setBytes(byte[] source, int sourceIndex, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } ___bytes.set(___offset, source, sourceIndex, len); }
public Class getPointedClass() { if (!isOffHeap()) throw new RuntimeException("cannot call on heap"); Class clazz = ___fac.getClazz(getClzId()); if (clazz == null) { return FSTStruct.class; } return clazz; }
public <T extends FSTStruct> T toStruct(T onHeap, BytezAllocator alloc) { if ( onHeap.isOffHeap() ) { return onHeap; } try { Bytez b = toByteArray(onHeap, alloc); return (T)createWrapper(onHeap.getClass(),b,0); } catch (Exception e) { if ( e instanceof RuntimeException ) throw (RuntimeException)e; else throw new RuntimeException(e); } }
public void setBytes(Bytez source, long sourceIndex, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } // unsafe.copyMemory(source, bufoff+sourceIndex, ___bytes, ___offset, len); source.copyTo(___bytes, ___offset, sourceIndex, len); }
public FSTStruct toOffHeap() { if (isOffHeap()) return this; return FSTStructFactory.getInstance().toStruct(this); }
public void setBytes(ByteSource source, long sourceIndex, int len) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } if (source instanceof BasicBytez) { ((BasicBytez) source).copyTo(___bytes, ___offset, sourceIndex, len); } else { for (long i = 0; i < len; i++) ___bytes.put(___offset + i, source.get(i + sourceIndex)); } }
public FSTStruct toOffHeap() { if (isOffHeap()) return this; return FSTStructFactory.getInstance().toStruct(this); }
/** * returns a complete copy of this object allocating a new Bytez capable of holding the data. * * @return */ public FSTStruct createCopy() { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } byte b[] = new byte[getByteSize()]; HeapBytez res = new HeapBytez(b); getBytes(res, 0); return ___fac.createStructWrapper(res, 0); }
public void getBytes(Bytez target, int startIndexInTarget) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } if (target.length() < startIndexInTarget + getByteSize()) { throw new RuntimeException("ArrayIndexOutofBounds byte len:" + target.length() + " start+size:" + (startIndexInTarget + getByteSize())); } // unsafe.copyMemory(___bytes,___offset, target, bufoff+startIndexInTarget, getByteSize()); ___bytes.copyTo(target, startIndexInTarget, ___offset, getByteSize()); }
public int hashCode() { if (!isOffHeap()) return onHeapHashcode(); return ___bytes.getInt(___offset) ^ ___bytes.getInt(___offset + getByteSize() - 4); }
public void getBytes(Bytez target, int startIndexInTarget) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } if (target.length() < startIndexInTarget + getByteSize()) { throw new RuntimeException("ArrayIndexOutofBounds byte len:" + target.length() + " start+size:" + (startIndexInTarget + getByteSize())); } // unsafe.copyMemory(___bytes,___offset, target, bufoff+startIndexInTarget, getByteSize()); ___bytes.copyTo(target, startIndexInTarget, ___offset, getByteSize()); }
public int hashCode() { if (!isOffHeap()) return onHeapHashcode(); return ___bytes.getInt(___offset) ^ ___bytes.getInt(___offset + getByteSize() - 4); }