public Serializer putByte(FieldBase field, byte value) { buf.put(value); return this; } public Serializer putShort(FieldBase field, short value) { buf.putShort(value); return this; }
/** Writes this string to the buffer as a 1_4 encoded length in bytes followed by the utf8 bytes */ public void putUtf8String(String value) { byte[] stringBytes = Utf8.toBytes(value); putInt1_4Bytes(stringBytes.length); put(stringBytes); }
/** * Write out the value of raw field * * @param field - field description (name and data type) * @param value - field value */ public void write(FieldBase field, Raw value) { ByteBuffer rawBuf = value.getByteBuffer(); int origPos = rawBuf.position(); buf.putInt(rawBuf.remaining()); buf.put(rawBuf); rawBuf.position(origPos); }
public void write(AlternateSpanList altSpanList) { buf.put(AlternateSpanList.ID); buf.putInt1_2_4Bytes(altSpanList.getNumSubTrees()); for (int i = 0; i < altSpanList.getNumSubTrees(); i++) { buf.putDouble(altSpanList.getProbability(i)); buf.putInt1_2_4Bytes(altSpanList.numChildren(i)); Iterator<SpanNode> children = altSpanList.childIterator(i); while (children.hasNext()) { write(children.next()); } } }
public void write(Span span) { buf.put(Span.ID); if (bytePositions != null) { int byteFrom = bytePositions[span.getFrom()]; int byteLength = bytePositions[span.getFrom() + span.getLength()] - byteFrom; buf.putInt1_2_4Bytes(byteFrom); buf.putInt1_2_4Bytes(byteLength); } else { throw new SerializationException("Cannot serialize Span " + span + ", no access to parent StringFieldValue."); } }
/** * Write out the value of raw field * * @param field - field description (name and data type) * @param value - field value */ public void write(FieldBase field, Raw value) { ByteBuffer rawBuf = value.getByteBuffer(); int origPos = rawBuf.position(); buf.putInt(rawBuf.remaining()); buf.put(rawBuf); rawBuf.position(origPos); }
public void write(AlternateSpanList altSpanList) { buf.put(AlternateSpanList.ID); buf.putInt1_2_4Bytes(altSpanList.getNumSubTrees()); for (int i = 0; i < altSpanList.getNumSubTrees(); i++) { buf.putDouble(altSpanList.getProbability(i)); buf.putInt1_2_4Bytes(altSpanList.numChildren(i)); Iterator<SpanNode> children = altSpanList.childIterator(i); while (children.hasNext()) { write(children.next()); } } }
@Override public void write(FieldBase field, TensorFieldValue value) { if (value.getTensor().isPresent()) { byte[] encodedTensor = TypedBinaryFormat.encode(value.getTensor().get()); buf.putInt1_4Bytes(encodedTensor.length); buf.put(encodedTensor); } else { buf.putInt1_4Bytes(0); } }
public void write(SpanList spanList) { buf.put(SpanList.ID); buf.putInt1_2_4Bytes(spanList.numChildren()); Iterator<SpanNode> children = spanList.childIterator(); while (children.hasNext()) { write(children.next()); } }
@Override public void write(FieldBase field, BoolFieldValue value) { byte v = value.getBoolean() ? (byte)1 : (byte)0; buf.put(v); }
@Override public void write(FieldBase field, PredicateFieldValue value) { byte[] buf = BinaryFormat.encode(value.getPredicate()); this.buf.putInt(buf.length); this.buf.put(buf); }
@Override public void write(FieldBase field, TensorFieldValue value) { if (value.getTensor().isPresent()) { byte[] encodedTensor = TypedBinaryFormat.encode(value.getTensor().get()); buf.putInt1_4Bytes(encodedTensor.length); buf.put(encodedTensor); } else { buf.putInt1_4Bytes(0); } }
public void write(Span span) { buf.put(Span.ID); if (bytePositions != null) { int byteFrom = bytePositions[span.getFrom()]; int byteLength = bytePositions[span.getFrom() + span.getLength()] - byteFrom; buf.putInt1_2_4Bytes(byteFrom); buf.putInt1_2_4Bytes(byteLength); } else { throw new SerializationException("Cannot serialize Span " + span + ", no access to parent StringFieldValue."); } }
@Override public void write(FieldBase field, BoolFieldValue value) { byte asByte = value.getBoolean() ? (byte)1 : (byte)0; buf.put(asByte); }
@Override public void write(FieldBase field, PredicateFieldValue value) { byte[] buf = BinaryFormat.encode(value.getPredicate()); this.buf.putInt(buf.length); this.buf.put(buf); }
public void write(SpanList spanList) { buf.put(SpanList.ID); buf.putInt1_2_4Bytes(spanList.numChildren()); Iterator<SpanNode> children = spanList.childIterator(); while (children.hasNext()) { write(children.next()); } }
/** * Write out the value of byte field * * @param field - field description (name and data type) * @param value - field value */ public void write(FieldBase field, ByteFieldValue value) { buf.put(value.getByte()); }
@Override public void write(FieldBase field, ByteFieldValue value) { buf.put(value.getByte()); }
@Override public void write(FieldBase field, ReferenceFieldValue value) { if (value.getDocumentId().isPresent()) { // We piggyback on DocumentId's existing serialization code, but need to know // whether or not it's present or merely the empty string. buf.put((byte)1); write(value.getDocumentId().get()); } else { buf.put((byte)0); } }
@Override public void write(FieldBase field, ReferenceFieldValue value) { if (value.getDocumentId().isPresent()) { // We piggyback on DocumentId's existing serialization code, but need to know // whether or not it's present or merely the empty string. buf.put((byte)1); write(value.getDocumentId().get()); } else { buf.put((byte)0); } }