@Override public int closeHighLevelField(int targetFieldLoc) { return closeHighLevelField(this, targetFieldLoc); }
public void openField(int loc, MsgCommandChannel commandChannel) { //assert(this.loc == -1) : "Already open for writing, can not open again."; this.commandChannel = commandChannel; this.loc = loc; DataOutputBlobWriter.openField(this); }
public void populate(DataOutputBlobWriter<?> writer) { int location = writer.position(); DataOutputBlobWriter.setIntBackData(writer, location, fieldPos); writer.writeShort(textBytes.length); writer.write(textBytes); prev.populate(writer); } };
@Override public void writeUTF8Text(CharSequence s) { if (null!=s) { encodeAsUTF8(this,s); } else { writeShort(-1); } }
/** * Close field and record its length as the number of bytes consumed by the BlobWriter * @param writer */ public static <T extends MessageSchema<T>> int closeLowLevelField(DataOutputBlobWriter<T> writer) { return closeLowLeveLField(writer, length(writer)); }
@Override public void writeUTF(CharSequence s) { if (null!=s) { activePosition = writeUTF(this, s, s.length(), byteMask, byteBuffer, activePosition); } else { writeShort(-1); } }
/** * Writes boolean to specified field in pipe * @param value true or false * @param fieldId field to write to */ public void writeBoolean(boolean value, long fieldId) { assert(Pipe.structRegistry(channelWriter.backingPipe).fieldType(fieldId) == StructType.Boolean); DataOutputBlobWriter.commitBackData(channelWriter, StructRegistry.extractStructId(fieldId)); DataOutputBlobWriter.setIntBackData( channelWriter, channelWriter.position(), StructRegistry.extractFieldPosition(fieldId)); channelWriter.writeBoolean(value); assert confirmDataDoesNotWriteOverIndex(fieldId) : "Data has written over index data"; }
public void writeShortNull(long fieldId) { assert(Pipe.structRegistry(channelWriter.backingPipe).fieldType(fieldId) == StructType.Short); DataOutputBlobWriter.commitBackData(channelWriter, StructRegistry.extractStructId(fieldId)); DataOutputBlobWriter.setIntBackData( channelWriter, channelWriter.position(), StructRegistry.extractFieldPosition(fieldId)); channelWriter.writePackedNull(); assert confirmDataDoesNotWriteOverIndex(fieldId) : "Data has written over index data"; }
int writePosition = writer.position(); writer.writePackedLong(length); writer.writeShort((short)type); writer.writeBoolean(true); //true for chunked payloadLengthData[i] = -1; //marked as chunking DataOutputBlobWriter.setIntBackData(writer, writePosition, StructRegistry.FIELD_MASK & (int)headerToken);
private void closeEncoder(Pipe<RawDataSchema> workingPipeOut, DataOutputBlobWriter<RawDataSchema> outputStream) { DataOutputBlobWriter.closeLowLevelField(outputStream); Pipe.confirmLowLevelWrite(workingPipeOut); Pipe.publishWrites(workingPipeOut); } }
private void publishConnectionFeedback() { if (connectionFeedbackTopic != null) { PipeWriter.presumeWriteFragment(output, IngressMessages.MSG_PUBLISH_103); PipeWriter.writeUTF8(output, IngressMessages.MSG_PUBLISH_103_FIELD_TOPIC_1, connectionFeedbackTopic); DataOutputBlobWriter<IngressMessages> stream = PipeWriter.outputStream(output); DataOutputBlobWriter.openField(stream); stream.write(connectResult); stream.closeHighLevelField(IngressMessages.MSG_PUBLISH_103_FIELD_PAYLOAD_3); PipeWriter.publishWrites(output); } } }
/** * Writes null boolean to specified field in pipe * @param fieldId field to write to */ public void writeBooleanNull(long fieldId) { assert(Pipe.structRegistry(channelWriter.backingPipe).fieldType(fieldId) == StructType.Boolean); DataOutputBlobWriter.commitBackData(channelWriter, StructRegistry.extractStructId(fieldId)); DataOutputBlobWriter.setIntBackData( channelWriter, channelWriter.position(), StructRegistry.extractFieldPosition(fieldId)); channelWriter.writeBooleanNull(); assert confirmDataDoesNotWriteOverIndex(fieldId) : "Data has written over index data"; }
/** * * @param blockId long arg used in PipeWriter.writeLong * @param w Writable arg used to write(stream) * @return if (PipeWriter.tryWriteFragment(target, PersistedBlobStoreProducerSchema.MSG_BLOCK_1)) true else false */ public boolean store(long blockId, Writable w) { if (PipeWriter.tryWriteFragment(target, PersistedBlobStoreProducerSchema.MSG_BLOCK_1)) { PipeWriter.writeLong(target,PersistedBlobStoreProducerSchema.MSG_BLOCK_1_FIELD_BLOCKID_3, blockId); DataOutputBlobWriter<PersistedBlobStoreProducerSchema> stream = PipeWriter.outputStream(target); DataOutputBlobWriter.openField(stream); w.write(stream); DataOutputBlobWriter.closeHighLevelField(stream, PersistedBlobStoreProducerSchema.MSG_BLOCK_1_FIELD_BYTEARRAY_2); PipeWriter.publishWrites(target); return true; } else { return false; } }
private void writeBytesToOutput(Pipe<PhastCodecSchema> output1, Pipe<RawDataSchema> output2, DataOutputBlobWriter<RawDataSchema> output2Writer, DataInputBlobReader<RawDataSchema> reader) { Pipe.addMsgIdx(output1, PhastCodecSchema.MSG_BLOBCHUNK_1000); Pipe.confirmLowLevelWrite(output1, Pipe.sizeOf(output1, PhastCodecSchema.MSG_BLOBCHUNK_1000)); Pipe.addMsgIdx(output2, RawDataSchema.MSG_CHUNKEDSTREAM_1); output2Writer.openField(); DataOutputBlobWriter.writeBytes(output2Writer, reader, bytesRemainingToCopy); output2Writer.closeLowLevelField(); bytesRemainingToCopy = 0; Pipe.confirmLowLevelWrite(output2, Pipe.sizeOf(output2, RawDataSchema.MSG_CHUNKEDSTREAM_1)); Pipe.publishWrites(output2); Pipe.publishWrites(output1); }
/** * Copies bytes from specified pipe to target pipe * @param sourcePipe to copy from * @param targetPipe to copy to * @param sourceLOC location of bytes to copy * @param targetLOC location to put bytes * @return length of copied bytes */ public static int copyBytes(final Pipe sourcePipe, final Pipe targetPipe, int sourceLOC, int targetLOC) { assert(LOCUtil.isLocOfAnyType(sourceLOC, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(sourceLOC); assert(LOCUtil.isLocOfAnyType(targetLOC, TypeMask.TextASCII, TypeMask.TextASCIIOptional, TypeMask.TextUTF8, TypeMask.TextUTF8Optional, TypeMask.ByteVector, TypeMask.ByteVectorOptional)): "Value found "+LOCUtil.typeAsString(targetLOC); //alternate implementation DataInputBlobReader src = PipeReader.inputStream(sourcePipe, sourceLOC); DataOutputBlobWriter tgt = PipeWriter.outputStream(targetPipe); DataOutputBlobWriter.openField(tgt); int len = src.available(); tgt.writeStream(src, len); if (src.isStructured) { src.readFromEndInto(tgt); } DataOutputBlobWriter.closeHighLevelField(tgt, targetLOC); return len; }
@Test public void decodeStringTest() throws IOException{ Pipe<RawDataSchema> pipe = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); pipe.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(pipe); DataOutputBlobWriter.writePackedInt(writer, -63); writer.writeUTF("This is a test"); writer.close(); DataInputBlobReader<RawDataSchema> reader = new DataInputBlobReader<RawDataSchema>(pipe); String stest = PhastDecoder.decodeString(reader, false); reader.close(); assertTrue(stest.compareTo("This is a test") == 0); }
/** * Writes long as UTF8 with specified length to Pipe * @param digitBuffer Pipe reference * @param length length of int to add * @return outputStream of Pipe */ public static <S extends MessageSchema<S>> int addLongAsUTF8(Pipe<S> digitBuffer, int length) { validateVarLength(digitBuffer, 21); DataOutputBlobWriter<S> outputStream = Pipe.outputStream(digitBuffer); outputStream.openField(); Appendables.appendValue(outputStream, length); return outputStream.closeLowLevelField(); }
private void streamingRequest(Pipe<ClientHTTPRequestSchema> pipe, int httpRequestResponseId) { PipeWriter.presumeWriteFragment(pipe, ClientHTTPRequestSchema.MSG_GET_200); assert(httpRequestResponseId>=0); PipeWriter.writeInt(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_SESSION_10, httpRequestResponseId); PipeWriter.writeInt(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_PORT_1, port); int hostId = ClientCoordinator.registerDomain(host); PipeWriter.writeInt(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_HOSTID_2, hostId); PipeWriter.writeLong(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_CONNECTIONID_20, -1 ); PipeWriter.writeInt(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_DESTINATION_11, httpRequestResponseId); PipeWriter.writeUTF8(pipe, ClientHTTPRequestSchema.MSG_GET_200_FIELD_PATH_3, path); DataOutputBlobWriter<ClientHTTPRequestSchema> stream = PipeWriter.outputStream(pipe); DataOutputBlobWriter.openField(stream); myAuth.addHeaders(stream, "GET").append("\r\n"); //myAuth.addHeaders(System.out, "GET"); DataOutputBlobWriter.closeHighLevelField(stream, ClientHTTPRequestSchema.MSG_GET_200_FIELD_HEADERS_7); PipeWriter.publishWrites(pipe); }
/** * Data written so far is directly copied to the destination writer. * @param writer target writer */ public void replicate(DataOutputBlobWriter<?> writer) { writer.write(backingPipe.blobRing, startPosition, activePosition-startPosition, backingPipe.blobMask); }
public void selectStructFromCachedIndexes(int[] indexOffsets) { StructRegistry structRegistry = Pipe.structRegistry(channelWriter.backingPipe); assert(DataOutputBlobWriter.getStructType(channelWriter)<=0) : "call selectStruct(id) only after setting all the object fields."; DataOutputBlobWriter.commitBackData(channelWriter, indexOffsets[indexOffsets.length-1]);//last pos is structId int p = pos; while (--p>=0) { DataOutputBlobWriter.setIntBackData(channelWriter, positions[p], indexOffsets[p]); } pos = 0;//cleared for next time; }