private static void openSequenceWhileInsideFragment(Pipe ringBuffer, final StackStateWalker ringBufferConsumer, long tmpNextWorkingTail, int lastScriptPos) { //this is a groupLength Sequence that starts inside of a fragment int seqLength = Pipe.slab((Pipe<?>) ringBuffer)[(int)(ringBufferConsumer.from.fragDataSize[lastScriptPos] + tmpNextWorkingTail)&ringBuffer.slabMask]; //now start new sequence ringBufferConsumer.seqStack[++ringBufferConsumer.seqStackHead] = seqLength; ringBufferConsumer.seqCursors[ringBufferConsumer.seqStackHead] = ringBufferConsumer.nextCursor; }
private static int readMsgIdx(Pipe ringBuffer, StackStateWalker ringBufferConsumer, final long tmpNextWorkingTail) { int i = ringBuffer.slabMask & (int)(tmpNextWorkingTail + ringBufferConsumer.from.templateOffset); int idx = Pipe.slab(ringBuffer)[i]; assert(isMsgIdxStartNewMessage(idx, ringBufferConsumer)) : "Bad msgIdx is not a starting point."; return idx; }
/** * Checks pipe to see if message does not equal expected * @param pipe to be checked * @param expected1 used for comparison * @param expected2 used for comparison * @return <code>true</code> if message != expected1 and message != expected2, else <code>false</code> */ public static boolean peekNotMsg(Pipe pipe, int expected1, int expected2) { return StackStateWalker.hasContentToRead(pipe) && (expected1 != Pipe.readValue(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.nextWorkingTail)) && (expected2 != Pipe.readValue(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.nextWorkingTail)); }
/** * Reads decimal exponent from specified pipe * @param pipe to read from * @param loc location to read from * @return decimal */ public static int readDecimalExponent(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readInt(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * 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; }
/** * Checks specified pipe to see if charSeq and value at specific location are equal * @param pipe pipe to be checked * @param loc location of value to compare * @param charSeq CharSequence to compare * @return <code>true</code> if the values are equal else <code>false</code> */ public static boolean isEqual(Pipe pipe, int loc, CharSequence charSeq) { int pos = Pipe.slab(pipe)[pipe.slabMask & (int)(pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc))]; return Pipe.isEqual(pipe, charSeq, pos, PipeReader.readBytesLength(pipe,loc)); }
/** * Reads decimal exponent from specified pipe * @param pipe to read from * @param loc location to read from * @return decimal */ public static int readDecimalExponent(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readInt(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * Reads decimal mantissa from specified pipe * @param pipe to read from * @param loc location to read from * @return mantissa */ public static long readDecimalMantissa(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readLong(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc) + 1);//plus one to skip over exponent }
/** * Writes double to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value double to be written * @param places to write values in */ public static void writeDouble(Pipe pipe, int loc, double value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }
/** * 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); }
private static void prepWriteMessageStart(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { assert(isValidStart(from,cursorPosition)) : "cursorPosition must be a valid message start but it is not. Value is "+cursorPosition; //each time some bytes were written in the previous fragment this value was incremented. //now it becomes the base value for all byte writes Pipe.markBytesWriteBase(pipe); //Start new stack of fragments because this is a new message pipe.ringWalker.activeWriteFragmentStack[0] = Pipe.workingHeadPosition(pipe); Pipe.slab(pipe)[pipe.slabMask &(int)(Pipe.workingHeadPosition(pipe) + from.templateOffset)] = cursorPosition; }
/** * 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 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)); }
public static void writeUInt(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_UINT32_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_UINT32_LOC); Pipe.addIntValue((int)typeExtractor.activeFieldLong, output); }
public static void writeDecimal(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_DECIMAL_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_DECIMAL_LOC); Pipe.addDecimal(TypeExtractor.decimalPlaces(typeExtractor), typeExtractor.activeFieldLong*TypeExtractor.signMult(typeExtractor), output); }
public static void writeInt(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_INT32_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_INT32_LOC); Pipe.addIntValue((int)typeExtractor.activeFieldLong*TypeExtractor.signMult(typeExtractor), output); TypeExtractor.signMult(typeExtractor); }