private static void prepWriteFragmentSpecificProcessing(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { if (FieldReferenceOffsetManager.isTemplateStart(from, cursorPosition)) { prepWriteMessageStart(pipe, cursorPosition, from); } else { //this fragment does not start a new message but its start position must be recorded for usage later pipe.ringWalker.activeWriteFragmentStack[from.fragDepth[cursorPosition]]=Pipe.workingHeadPosition(pipe); } }
/** * Check to see if specified pipe has room to write * @param pipe to be checked * @return <code>true</code> if pipe has room else <code>false</code> */ public static boolean hasRoomForWrite(Pipe pipe) { assert(Pipe.singleThreadPerPipeWrite(pipe.id)); assert(pipe!=null); assert(Pipe.isInit(pipe)); assert(pipe.usingHighLevelAPI); return StackStateWalker.hasRoomForFragmentOfSizeX(pipe, pipe.ringWalker.nextWorkingHead - (pipe.sizeOfSlabRing - FieldReferenceOffsetManager.maxFragmentSize( Pipe.from(pipe)))); }
public static <T extends MessageSchema<T>> int closeHighLevelField(DataOutputBlobWriter<T> writer, int targetFieldLoc) { //this method will also validate the length was in bound and throw unsupported operation if the pipe was not large enough //instead of fail fast as soon as one field goes over we wait to the end and only check once. int len = length(writer); //Appendables.appendUTF8(System.err, writer.byteBuffer, writer.startPosition, len, writer.byteMask); PipeWriter.writeSpecialBytesPosAndLen(writer.backingPipe, targetFieldLoc, len, writer.startPosition); writer.backingPipe.closeBlobFieldWrite(); //Appendables.appendUTF8(System.out, writer.getPipe().blobRing, writer.startPosition, len, writer.getPipe().blobMask); return len; }
public static <S extends MessageSchema<S>> void writeLL(Pipe<S> pipe, int msgIdx, long field1, long field2) { assert(FieldReferenceOffsetManager.isValidMsgIdx(Pipe.from(pipe), msgIdx)); assert(6==Pipe.from(pipe).fragDataSize[msgIdx]) : "This constant does not this fragment size"; int size = Pipe.addMsgIdx(pipe, msgIdx); Pipe.addLongValue(field1, pipe); Pipe.addLongValue(field2, pipe); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); }
private void publishOpenWrite() { //log.trace("write block"); totalBytesWritten = totalBytesWritten + (outputStreamFlyweight.closeLowLevelField()); Pipe.confirmLowLevelWrite(pipe, Pipe.sizeOf(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1)); Pipe.publishWrites(pipe); hasOpenWrite = false; }
private void closeEncoder(Pipe<RawDataSchema> workingPipeOut, DataOutputBlobWriter<RawDataSchema> outputStream) { DataOutputBlobWriter.closeLowLevelField(outputStream); Pipe.confirmLowLevelWrite(workingPipeOut); Pipe.publishWrites(workingPipeOut); } }
/** * 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)); }
public int closeLowLevelField() { int len = length(); Pipe.addAndGetBlobWorkingHeadPosition(p, len); Pipe.addBytePosAndLenSpecial(p,startPosition,len); p.closeBlobFieldWrite(); return len; }
public int closeHighLevelField(int targetFieldLoc) { //this method will also validate the length was in bound and throw unsupported operation if the pipe was not large enough //instead of fail fast as soon as one field goes over we wait to the end and only check once. int len = length(); PipeWriter.writeSpecialBytesPosAndLen(p, targetFieldLoc, len, startPosition); p.closeBlobFieldWrite(); return len; }
/** * Checks pipe to see if message equals expected * @param pipe to be checked * @param expected used for comparison with message * @return <code>true</code> if message == expected, else <code>false</code> */ public static boolean peekMsg(Pipe pipe, int expected) { assert(Pipe.singleThreadPerPipeRead(pipe.id)); return StackStateWalker.hasContentToRead(pipe) && (expected == Pipe.readValue(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.nextWorkingTail)); }
public <S extends MessageSchema<S>> PipeConfig<S> addConfig(int minimumFragmentsOnPipe, int maximumLengthOfVariableLengthFields, Class<S> clazz) { PipeConfig<S> newConfig = MessageSchema .findInstance(clazz) .newPipeConfig(minimumFragmentsOnPipe, maximumLengthOfVariableLengthFields); return addConfig(newConfig); }
/** * Take optional Long which may be null. Null is defined as specific long value in FROM * @param pipe Ping source * @return Long value */ public static <S extends MessageSchema<S>> Long takeOptionalLong(Pipe<S> pipe) { long absent64Value = FieldReferenceOffsetManager.getAbsent64Value(Pipe.from(pipe)); return takeOptionalLong(pipe, absent64Value); }
public static <T extends MessageSchema<T>> void setIntBackData(DataOutputBlobWriter<T> writer, int value, int pos) { assert(value<=writer.position()) : "wrote "+value+" but all the data is only "+writer.position(); assert(pos>=0) : "Can not write beyond the end. Index values must be zero or positive"; write32(writer.byteBuffer, writer.byteMask, writer.startPosition+Pipe.blobIndexBasePosition(writer.backingPipe)-(4*(pos+1)), value); }
@Override public int read(byte[] b) throws IOException { if ((byteMask & position) == bytesLimit) { return -1; } int max = bytesRemaining(this); int len = b.length>max? max : b.length; Pipe.copyBytesFromToRing(backing, position, byteMask, b, 0, Integer.MAX_VALUE, len); position += b.length; return b.length; }
/** * Writes blob to specified field in pipe * calls selectStruct(id) only after setting all the object fields * @param assoc field association showing where to write * @return channelWriter */ public ChannelWriter writeBlob(Object assoc) { assert(DataOutputBlobWriter.getStructType(channelWriter)<=0) : "call selectStruct(id) only after setting all the object fields."; storeAssocAndPosition(assoc); return channelWriter; }
public static <S extends MessageSchema<S>> void writeLII(Pipe<S> pipe, int msgIdx, long field1, int field2, int field3) { assert(FieldReferenceOffsetManager.isValidMsgIdx(Pipe.from(pipe), msgIdx)); assert(6==Pipe.from(pipe).fragDataSize[msgIdx]) : "This constant does not this fragment size"; int size = Pipe.addMsgIdx(pipe, msgIdx); Pipe.addLongValue(field1, pipe); Pipe.addIntValue(field2, pipe); Pipe.addIntValue(field3, pipe); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); }
/** * Check to see if specified pipe has room to write * @param pipe to be checked * @return <code>true</code> if pipe has room else <code>false</code> */ public static boolean hasRoomForWrite(Pipe pipe) { assert(Pipe.singleThreadPerPipeWrite(pipe.id)); assert(pipe!=null); assert(Pipe.isInit(pipe)); assert(pipe.usingHighLevelAPI); return StackStateWalker.hasRoomForFragmentOfSizeX(pipe, pipe.ringWalker.nextWorkingHead - (pipe.sizeOfSlabRing - FieldReferenceOffsetManager.maxFragmentSize( Pipe.from(pipe)))); }
public int closeHighLevelField(int targetFieldLoc) { //this method will also validate the length was in bound and throw unsupported operation if the pipe was not large enough //instead of fail fast as soon as one field goes over we wait to the end and only check once. int len = length(); PipeWriter.writeSpecialBytesPosAndLen(p, targetFieldLoc, len, startPosition); p.closeBlobFieldWrite(); return len; }
private static void prepWriteFragmentSpecificProcessing(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { if (FieldReferenceOffsetManager.isTemplateStart(from, cursorPosition)) { prepWriteMessageStart(pipe, cursorPosition, from); } else { //this fragment does not start a new message but its start position must be recorded for usage later pipe.ringWalker.activeWriteFragmentStack[from.fragDepth[cursorPosition]]=Pipe.workingHeadPosition(pipe); } }
public static <S extends MessageSchema<S>> void writeI(Pipe<S> pipe, int msgIdx, int field1) { assert(FieldReferenceOffsetManager.isValidMsgIdx(Pipe.from(pipe), msgIdx)); assert(3==Pipe.from(pipe).fragDataSize[msgIdx]) : "This constant does not this fragment size"; int size = Pipe.addMsgIdx(pipe, msgIdx); Pipe.addIntValue(field1, pipe); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); } }