/** * Reads int bits from specified pipe and converts to float * @param pipe to be read * @param loc location of int bits to read * @return float bits converted from int */ public static float readIntBitsToFloat(Pipe pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); return Float.intBitsToFloat(readInt(pipe,loc)); }
/** * * @param pipe to be updated * @param loc for the field to be updated * @param value float to write to specified location */ public static void writeFloatAsIntBits(Pipe pipe, int loc, float value) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); writeInt(pipe, loc, Float.floatToIntBits(value)); }
/** * Writes byte to specified pipe * @param pipe to be updated * @param loc for the field to be updated * @param value byte to write to specified location */ public static void writeByte(Pipe pipe, int loc, byte value) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); Pipe.slab(pipe)[pipe.slabMask &((int)pipe.ringWalker.activeWriteFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))] = value; }
/** * Writes byte to specified pipe * @param pipe to be updated * @param loc for the field to be updated * @param value byte to write to specified location */ public static void writeByte(Pipe pipe, int loc, byte value) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); Pipe.slab(pipe)[pipe.slabMask &((int)pipe.ringWalker.activeWriteFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))] = value; }
public static ByteBuffer[] wrappedUnstructuredLayoutBuffer(Pipe pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); return wrappedUnstructuredLayoutBufferImpl(pipe, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK & (loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * Copies int from specified pipe ring to target pipe ring * @param sourceRing to copy from * @param targetRing to copy to * @param sourceLOC location of the int to copy * @param targetLOC location to put the copied int */ public static void copyInt(final Pipe sourceRing, final Pipe targetRing, int sourceLOC, int targetLOC) { assert(LOCUtil.isLocOfAnyType(sourceLOC, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(sourceLOC); assert(LOCUtil.isLocOfAnyType(targetLOC, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(targetLOC); Pipe.slab((Pipe<?>) targetRing)[targetRing.slabMask &((int)targetRing.ringWalker.activeWriteFragmentStack[PipeWriter.STACK_OFF_MASK&(targetLOC>>PipeWriter.STACK_OFF_SHIFT)] + (PipeWriter.OFF_MASK&targetLOC))] = Pipe.slab((Pipe<?>) sourceRing)[sourceRing.slabMask & (int)(sourceRing.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(sourceLOC>>STACK_OFF_SHIFT)]+(OFF_MASK&sourceLOC))]; }
/** * Writes byte to specified pipe * @param pipe to be updated * @param loc for the field to be updated * @param value byte to write to specified location */ public static void writeByte(Pipe pipe, int loc, byte value) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); Pipe.slab(pipe)[pipe.slabMask &((int)pipe.ringWalker.activeWriteFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))] = value; }
/** * Peeks at input stream of specified pipe before Trie parse is run * @param pipe pipe to read * @return stream */ public static <S extends MessageSchema<S>> DataInputBlobReader<S> peekInputStream(Pipe<S> pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc)+" b"+Integer.toBinaryString(loc); DataInputBlobReader<S> stream = Pipe.inputStream(pipe); DataInputBlobReader.peekHighLevelAPIField(stream, loc); return stream; }
/** * Peeks at input stream of specified pipe before Trie parse is run * @param pipe pipe to read * @return stream */ public static <S extends MessageSchema<S>> DataInputBlobReader<S> peekInputStream(Pipe<S> pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc)+" b"+Integer.toBinaryString(loc); DataInputBlobReader<S> stream = Pipe.inputStream(pipe); DataInputBlobReader.peekHighLevelAPIField(stream, loc); return stream; }
/** * Reads byte from specified pipe * @param pipe to be read * @param loc location of byte to read * @return data from specified location */ public static byte readByte(Pipe pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); return (byte)Pipe.readInt(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)]+(OFF_MASK&loc)); }
/** * Reads long from specified pipe * @param pipe to be read * @param loc location of long to read * @return data from specified location */ public static long readLong(Pipe pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.LongSigned, TypeMask.LongSignedOptional, TypeMask.LongUnsigned, TypeMask.LongUnsignedOptional)): "Value found "+LOCUtil.typeAsString(loc); return Pipe.readLong(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] +(OFF_MASK&loc)); }
/** * Reads int securely from specified pipe * @param pipe to read from * @param loc location of int to read * @param clearValue value to replace previous int with * @return data from specified location */ public static int readIntSecure(Pipe pipe, int loc, int clearValue) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional, TypeMask.GroupLength)): "Value found "+LOCUtil.typeAsString(loc); return Pipe.readIntSecure(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)]+(OFF_MASK&loc),clearValue); }
/** * Peeks at internal data; advanced feature */ public static byte[] peekDataBackingArray(Pipe pipe, int loc) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); int pos = Pipe.slab(pipe)[pipe.slabMask & (int)(pipe.ringWalker.nextWorkingTail+ (OFF_MASK&loc))]; return pos<0 ? pipe.blobConstBuffer : Pipe.blob(pipe); }
/** * Peeks ahead to specified field in pipe before Trie parsing is done * @param pipe pipe to read * @param loc field to peek in * @return int data in that field */ public static int peekInt(Pipe pipe, int loc) { assert(PipeReader.hasContentToRead(pipe)) : "results would not be repeatable, before peek hasContentToRead must be called."; assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional, TypeMask.GroupLength)): "Value found "+LOCUtil.typeAsString(loc); return Pipe.readValue(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.nextWorkingTail+(OFF_MASK&loc)); }
/** * Reads ASCII from specified pipe * @param pipe to read from * @param loc location of data to read * @return ASCII data */ public static Appendable readASCII(Pipe pipe, int loc, Appendable target) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); int pos = Pipe.slab(pipe)[pipe.slabMask & (int)(pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))]; int len = PipeReader.readBytesLength(pipe,loc); return Pipe.readASCII(pipe, target, pos, len); }
/** * Writes int to specified pipe * @param pipe pipe to be written to * @param loc location to write int * @param value int value to be written */ public static void writeInt(Pipe pipe, int loc, int value) { //allow for all types of int and for length assert(LOCUtil.isLocOfAnyType(loc, TypeMask.IntegerSigned, TypeMask.IntegerSignedOptional, TypeMask.IntegerUnsigned, TypeMask.IntegerUnsignedOptional, TypeMask.GroupLength)): "Value found "+LOCUtil.typeAsString(loc); long p = structuredPositionForLOC(pipe, loc); assert(p < pipe.ringWalker.nextWorkingHead-1L) : "Is this field applicable for the this pipes schema? "+pipe.schemaName(pipe); Pipe.slab(pipe)[pipe.slabMask & (int)p] = value; }
/** * Reads ASCII from specified pipe * @param pipe to read from * @param loc location of data to read * @return ASCII data */ public static Appendable readASCII(Pipe pipe, int loc, Appendable target) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); int pos = Pipe.slab(pipe)[pipe.slabMask & (int)(pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))]; int len = PipeReader.readBytesLength(pipe,loc); return Pipe.readASCII(pipe, target, pos, len); }
public static ByteBuffer readBytes(Pipe pipe, int loc, ByteBuffer target) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); long tmp = pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc); int pos = Pipe.slab(pipe)[pipe.slabMask & (int)(tmp)]; int len = Pipe.slab(pipe)[pipe.slabMask & (int)(tmp + 1)]; return Pipe.readBytes(pipe, target, pos, len); }
/** * Writes given int as String in specified pipe * @param pipe to be written to * @param loc field to write data * @param value int value to be converted */ public static void writeIntAsText(Pipe pipe, int loc, int value) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); int max = 12+ Pipe.getWorkingBlobHeadPosition((Pipe<?>) pipe); int len = Pipe.leftConvertIntToASCII(pipe, value, max); finishWriteBytesAlreadyStarted(pipe, loc, len); Pipe.addAndGetBlobWorkingHeadPosition(pipe,len); }
/** * Writes UTF8 to defined location in specified pipe * @param pipe to be written to * @param loc field to be written to * @param source char[] to write to specified location */ public static void writeUTF8(Pipe pipe, int loc, char[] source) { assert(LOCUtil.isLocOfAnyType(loc, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(loc); int sourceLen = null==source? -1 : source.length; Pipe.validateVarLength(pipe, sourceLen<<3); //UTF8 encoded bytes are longer than the char count (6 is the max but math for 8 is cheaper) Pipe.setBytePosAndLen(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeWriteFragmentStack[PipeWriter.STACK_OFF_MASK&(loc>>PipeWriter.STACK_OFF_SHIFT)] + (PipeWriter.OFF_MASK&loc), Pipe.getWorkingBlobHeadPosition((Pipe<?>) pipe), Pipe.copyUTF8ToByte(source, sourceLen, pipe), Pipe.bytesWriteBase(pipe)); }