diff --git a/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java b/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java index 1c397b7..c5e397f 100644 --- a/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java +++ b/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.google.common.base.Utf8; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufHolder; import io.netty.buffer.Unpooled; import javax.annotation.Nonnull; @@ -37,7 +38,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; @JsonSerialize(using = Utf8String.JsonSerializer.class) @SuppressWarnings("UnstableApiUsage") -public final class Utf8String implements CharSequence, Comparable { +public final class Utf8String implements ByteBufHolder, CharSequence, Comparable { public static final Utf8String EMPTY = new Utf8String(Unpooled.EMPTY_BUFFER, 0); public static final Utf8String NULL = new Utf8String(); @@ -74,6 +75,114 @@ public final class Utf8String implements CharSequence, Comparable { return this.buffer == null; } + /** + * Returns a reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String} + *

+ * A value of {@code null} is returns, if this {@link Utf8String} is null. + * @return reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String}. + */ + @Nullable + public ByteBuf content() { + return this.buffer; + } + + /** + * Creates a deep copy of this {@link Utf8String} + */ + @Override + public Utf8String copy() { + throw new UnsupportedOperationException(); + } + + /** + * Duplicates this {@link Utf8String} + *

+ * Be aware that this will not automatically call {@link #retain()}. + */ + @Override + public Utf8String duplicate() { + throw new UnsupportedOperationException(); + } + + /** + * Duplicates this {@link Utf8String} + *

+ * This method returns a retained duplicate unlike {@link #duplicate()}. + * + * @see ByteBuf#retainedDuplicate() + */ + @Override + public Utf8String retainedDuplicate() { + throw new UnsupportedOperationException(); + } + + /** + * Returns a new {@link Utf8String} which contains the specified {@code content} + * + * @param content text of the {@link Utf8String} to be created. + */ + @Override + public Utf8String replace(ByteBuf content) { + throw new UnsupportedOperationException(); + } + + /** + * Returns the reference count of this {@link Utf8String} + *

+ * If {@code 0}, it means this object has been deallocated. + */ + @Override + public int refCnt() { + return this.buffer.refCnt(); + } + + @Override + public Utf8String retain() { + this.buffer.retain(); + return this; + } + + @Override + public Utf8String retain(int increment) { + this.buffer.retain(increment); + return this; + } + + @Override + public Utf8String touch() { + this.buffer.touch(); + return this; + } + + @Override + public Utf8String touch(Object hint) { + this.buffer.touch(hint); + return this; + } + + /** + * Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at + * {@code 0}. + * + * @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated + */ + @Override + public boolean release() { + return this.buffer.release(); + } + + /** + * Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference + * count reaches at {@code 0}. + * + * @param decrement + * @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated + */ + @Override + public boolean release(int decrement) { + return false; + } + @Override public char charAt(final int index) { throw new UnsupportedOperationException(); @@ -296,7 +405,7 @@ public final class Utf8String implements CharSequence, Comparable { private final int length; private int index; - public CodePointIterable(final ByteBuf buffer, final int length) { + CodePointIterable(final ByteBuf buffer, final int length) { this.buffer = buffer; this.length = length; this.index = 0; diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java index b7d8cf1..882e14b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java @@ -6,7 +6,6 @@ package com.azure.data.cosmos.serialization.hybridrow; import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.core.Utf8String; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer.UniqueIndexItem; import com.azure.data.cosmos.serialization.hybridrow.codecs.DateTimeCodec; import com.azure.data.cosmos.serialization.hybridrow.codecs.DecimalCodec; import com.azure.data.cosmos.serialization.hybridrow.codecs.Float128Codec; @@ -55,6 +54,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutVarInt; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutVarUInt; import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; +import com.azure.data.cosmos.serialization.hybridrow.layouts.StringTokenizer; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList; import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions; @@ -66,11 +66,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; -import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.util.Iterator; import java.util.Optional; import java.util.UUID; +import java.util.function.Consumer; import java.util.function.Supplier; import static com.google.common.base.Preconditions.checkArgument; @@ -142,239 +142,17 @@ public final class RowBuffer { checkState(HybridRowHeader.SIZE + layout.size() <= this.length()); } - public ByteBuf readSparseBinary(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.BINARY); - ByteBuf value = this.readBinary(edit.valueOffset()); - edit.endOffset(this.buffer.readerIndex()); - return value; - } + public Utf8String ReadSparsePath(RowCursor edit) { - public boolean readSparseBoolean(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.BOOLEAN); - edit.endOffset(edit.valueOffset()); - return edit.cellType() == LayoutTypes.BOOLEAN; - } + StringTokenizer tokenizer = edit.layout().tokenizer(); + final Optional path = tokenizer.tryFindString(edit.longValue().pathToken); - public OffsetDateTime readSparseDateTime(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.DATE_TIME); - edit.endOffset(edit.valueOffset() + Long.SIZE); - return this.readDateTime(edit.valueOffset()); - } - - public BigDecimal readDecimal(int offset) { - Item item = this.read(() -> DecimalCodec.decode(this.buffer), offset); - return item.value(); - } - - public ByteBuf readFixedBinary(int offset, int length) { - Item item = this.read(() -> this.buffer.readSlice(length), offset); - return item.value(); - } - - public Utf8String readFixedString(int offset, int length) { - Item item = this.read(() -> Utf8String.fromUnsafe(this.buffer.readSlice(length)), offset); - return item.value(); - } - - public int ReadInt32(int offset) { - Item item = this.read(this.buffer::readIntLE, offset); - return item.value(); - } - - public Float128 readFloat128(int offset) { - Item item = this.read(() -> Float128Codec.decode(this.buffer), offset); - return item.value(); - } - - public float readFloat32(int offset) { - Item item = this.read(this.buffer::readFloatLE, offset); - return item.value(); - } - - public double readFloat64(int offset) { - Item item = this.read(this.buffer::readDoubleLE, offset); - return item.value(); - } - - // TODO: DANOBLE: resurrect MongoDbObjectId - // public MongoDbObjectId ReadMongoDbObjectId(int offset) { - // return MemoryMarshal.Read(this.buffer.Slice(offset)); - // } - - public SchemaId readSchemaId(int offset) { - Item item = this.read(() -> SchemaId.from(this.buffer.readIntLE()), offset); - return item.value(); - } - - public BigDecimal readSparseDecimal(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.DECIMAL); - BigDecimal value = this.readDecimal(edit.valueOffset()); - edit.endOffset(this.buffer.readerIndex()); - return value; - } - - public Float128 readSparseFloat128(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.FLOAT_128); - Float128 value = this.readFloat128(edit.valueOffset()); - edit.endOffset(this.buffer.readerIndex()); - return value; - } - - public float readSparseFloat32(RowCursor edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutTypes.FLOAT_32); - float value = this.readFloat32(edit.valueOffset()); - edit.endOffset(this.buffer.readerIndex()); - return value; - } - - // TODO: DANOBLE: resurrect MongoDbObjectId - // public MongoDbObjectId ReadSparseMongoDbObjectId(Reference edit) { - // this.readSparsePrimitiveTypeCode(edit, MongoDbObjectId); - // edit.get().endOffset = edit.get().valueOffset() + MongoDbObjectId.Size; - // return this.ReadMongoDbObjectId(edit.get().valueOffset()).clone(); - // } - - public Utf8Span ReadSparseString(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.Utf8); - int sizeLenInBytes; - Out tempOut_sizeLenInBytes = new Out(); - Utf8Span span = this.ReadString(edit.get().valueOffset(), tempOut_sizeLenInBytes); - sizeLenInBytes = tempOut_sizeLenInBytes.get(); - edit.get().endOffset = edit.get().valueOffset() + sizeLenInBytes + span.Length; - return span; - } - - public long ReadSparseVarInt(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.VarInt); - int sizeLenInBytes; - Out tempOut_sizeLenInBytes = new Out(); - long value = this.read7BitEncodedInt(edit.get().valueOffset(), tempOut_sizeLenInBytes); - sizeLenInBytes = tempOut_sizeLenInBytes.get(); - edit.get().endOffset = edit.get().valueOffset() + sizeLenInBytes; - return value; - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ushort ReadUInt16(int offset) - public short ReadUInt16(int offset) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return MemoryMarshal.Read(this.buffer.Slice(offset)); - return MemoryMarshal.Read(this.buffer.Slice(offset)); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal uint ReadUInt32(int offset) - public int ReadUInt32(int offset) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return MemoryMarshal.Read(this.buffer.Slice(offset)); - return MemoryMarshal.Read(this.buffer.Slice(offset)); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ushort ReadSparseUInt16(ref RowCursor edit) - public short ReadSparseUInt16(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt16); - edit.get().endOffset = edit.get().valueOffset() + (Short.SIZE / Byte.SIZE); - return this.ReadUInt16(edit.get().valueOffset()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal uint ReadSparseUInt32(ref RowCursor edit) - public int ReadSparseUInt32(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt32); - edit.get().endOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); - return this.ReadUInt32(edit.get().valueOffset()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ulong ReadSparseUInt64(ref RowCursor edit) - public long ReadSparseUInt64(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt64); - edit.get().endOffset = edit.get().valueOffset() + (Long.SIZE / Byte.SIZE); - return this.ReadUInt64(edit.get().valueOffset()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal byte ReadSparseUInt8(ref RowCursor edit) - public byte ReadSparseUInt8(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt8); - edit.get().endOffset = edit.get().valueOffset() + 1; - return this.ReadUInt8(edit.get().valueOffset()); - } - - public UnixDateTime ReadSparseUnixDateTime(Reference edit) { - this.readSparsePrimitiveTypeCode(edit, LayoutType.UnixDateTime); - edit.get().endOffset = edit.get().valueOffset() + 8; - return this.ReadUnixDateTime(edit.get().valueOffset()).clone(); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ulong ReadUInt64(int offset) - public long ReadUInt64(int offset) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return MemoryMarshal.Read(this.buffer.Slice(offset)); - return MemoryMarshal.Read(this.buffer.Slice(offset)); - } - - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal byte ReadUInt8(int offset) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal byte ReadUInt8(int offset) - public byte ReadUInt8(int offset) { - return this.buffer[offset]; - } - - public UnixDateTime ReadUnixDateTime(int offset) { - return MemoryMarshal.Read(this.buffer.Slice(offset)); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ReadOnlySpan ReadVariableBinary(int offset) - public ReadOnlySpan ReadVariableBinary(int offset) { - int _; - Out tempOut__ = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.ReadBinary(offset, out int _); - ReadOnlySpan tempVar = this.readBinary(offset); - _ = tempOut__.get(); - return tempVar; - } - - public long ReadVariableInt(int offset) { - int _; - Out tempOut__ = new Out(); - long tempVar = this.read7BitEncodedInt(offset, tempOut__); - _ = tempOut__.get(); - return tempVar; - } - - public Utf8Span ReadVariableString(int offset) { - int _; - Out tempOut__ = new Out(); - Utf8Span tempVar = this.ReadString(offset, tempOut__); - _ = tempOut__.get(); - return tempVar; - } - - public long ReadVariableUInt(int offset) { - int _; - Out tempOut__ = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.Read7BitEncodedUInt(offset, out int _); - long tempVar = this.read7BitEncodedUInt(); - _ = tempOut__.get(); - return tempVar; - } - - public void SetBit(int offset, LayoutBit bit) { - if (bit.getIsInvalid()) { - return; + if (path.isPresent()) { + return path.get(); } - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: - //ORIGINAL LINE: this.buffer[bit.GetOffset(offset)] |= unchecked((byte)(1 << bit.GetBit())); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - this.buffer[bit.offset(offset)] |= (byte) (1 << bit.bit()); + int numBytes = edit.pathToken() - edit.layout().tokenizer().count(); + return Utf8String.fromUnsafe(this.buffer.readSlice(edit.pathOffset(), numBytes)); } /** @@ -430,26 +208,6 @@ public final class RowBuffer { this.length(this.length() + shiftDelete); } - public void UnsetBit(int offset, LayoutBit bit) { - checkState(LayoutBit.opNotEquals(bit.clone(), LayoutBit.INVALID)); - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: - //ORIGINAL LINE: this.buffer[bit.GetOffset(offset)] &= unchecked((byte)~(1 << bit.GetBit())); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - this.buffer[bit.offset(offset)] &= (byte) ~(1 << bit.bit()); - } - - public void WriteDateTime(int offset, LocalDateTime value) { - Reference tempReference_value = new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - public void WriteDecimal(int offset, BigDecimal value) { - Reference tempReference_value = new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - /** * Rebuild the unique index for a set/map scope. * @@ -563,46 +321,6 @@ public final class RowBuffer { return Result.Success; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteFixedBinary(int offset, ReadOnlySpan value, int len) - public void WriteFixedBinary(int offset, ReadOnlySpan value, int len) { - value.CopyTo(this.buffer.Slice(offset, len)); - if (value.Length < len) { - this.buffer.Slice(offset + value.Length, len - value.Length).Fill(0); - } - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteFixedBinary(int offset, ReadOnlySequence value, int len) - public void WriteFixedBinary(int offset, ReadOnlySequence value, int len) { - value.CopyTo(this.buffer.Slice(offset, len)); - if (value.Length < len) { - this.buffer.Slice(offset + (int) value.Length, len - (int) value.Length).Fill(0); - } - } - - public void WriteFixedString(int offset, Utf8Span value) { - value.Span.CopyTo(this.buffer.Slice(offset)); - } - - public void WriteFloat32(int offset, float value) { - Reference tempReference_value = new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - public void WriteFloat64(int offset, double value) { - Reference tempReference_value = new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - public void WriteGuid(int offset, UUID value) { - Reference tempReference_value = new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - public void WriteNullable(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs, UpdateOptions options, boolean hasValue, Out newScope) { int numBytes = this.countDefaultValue(scopeType, typeArgs); @@ -643,10 +361,6 @@ public final class RowBuffer { this = tempReference_this.get(); } - public void WriteSchemaId(int offset, SchemaId value) { - this.writeInt32(offset, value.value()); - } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal void WriteSparseBinary(ref RowCursor edit, ReadOnlySpan value, UpdateOptions // options) @@ -720,7 +434,7 @@ public final class RowBuffer { this.length(this.length() + shift); } - public void WriteSparseDateTime(Reference edit, LocalDateTime value, UpdateOptions options) { + public void WriteSparseDateTime(RowCursor edit, OffsetDateTime value, UpdateOptions options) { int numBytes = 8; int metaBytes; Out tempOut_metaBytes = new Out(); @@ -734,7 +448,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.DateTime, TypeArgumentList.EMPTY, metaBytes); - this.WriteDateTime(edit.get().valueOffset(), value); + this.writeDateTime(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + 8); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -755,7 +469,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.Decimal, TypeArgumentList.EMPTY, metaBytes); - this.WriteDecimal(edit.get().valueOffset(), value); + this.writeDecimal(edit.get().valueOffset(), value); // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': checkState(spaceNeeded == metaBytes + sizeof(BigDecimal)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; @@ -796,7 +510,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.Float64, TypeArgumentList.EMPTY, metaBytes); - this.WriteFloat64(edit.get().valueOffset(), value); + this.writeFloat64(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + (Double.SIZE / Byte.SIZE)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -816,7 +530,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.Guid, TypeArgumentList.EMPTY, metaBytes); - this.WriteGuid(edit.get().valueOffset(), value); + this.writeGuid(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + 16); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -862,12 +576,9 @@ public final class RowBuffer { this.length(this.length() + shift); } - // TODO: DANOBLE: Support MongoDbObjectId values - // public void WriteMongoDbObjectId(int offset, MongoDbObjectId value) { - // Reference tempReference_value = - // new Reference(value); - // MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - // value = tempReference_value.get(); + // TODO: DANOBLE: resurrect MongoDbObjectId + // public MongoDbObjectId ReadMongoDbObjectId(int offset) { + // return MemoryMarshal.Read(this.buffer.Slice(offset)); // } public void WriteSparseInt64(Reference edit, long value, UpdateOptions options) { @@ -1004,6 +715,13 @@ public final class RowBuffer { this.length(this.length() + shift); } + // TODO: DANOBLE: resurrect MongoDbObjectId + // public MongoDbObjectId ReadSparseMongoDbObjectId(Reference edit) { + // this.readSparsePrimitiveTypeCode(edit, MongoDbObjectId); + // edit.get().endOffset = edit.get().valueOffset() + MongoDbObjectId.Size; + // return this.ReadMongoDbObjectId(edit.get().valueOffset()).clone(); + // } + public void WriteSparseTuple(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs , UpdateOptions options, Out newScope) { int numBytes = (LayoutCode.SIZE / Byte.SIZE) * (1 + typeArgs.count()); // nulls for each element. @@ -1090,7 +808,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.UInt16, TypeArgumentList.EMPTY, metaBytes); - this.WriteUInt16(edit.get().valueOffset(), value); + this.writeUInt16(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + (Short.SIZE / Byte.SIZE)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -1112,7 +830,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.UInt32, TypeArgumentList.EMPTY, metaBytes); - this.WriteUInt32(edit.get().valueOffset(), value); + this.writeUInt32(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + (Integer.SIZE / Byte.SIZE)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -1134,7 +852,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.UInt64, TypeArgumentList.EMPTY, metaBytes); - this.WriteUInt64(edit.get().valueOffset(), value); + this.writeUInt64(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + (Long.SIZE / Byte.SIZE)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -1156,7 +874,7 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.UInt8, TypeArgumentList.EMPTY, metaBytes); - this.WriteUInt8(edit.get().valueOffset(), value); + this.writeUInt8(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + 1); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -1177,7 +895,7 @@ public final class RowBuffer { metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.UnixDateTime, TypeArgumentList.EMPTY, metaBytes); - this.WriteUnixDateTime(edit.get().valueOffset(), value.clone()); + this.writeUnixDateTime(edit.get().valueOffset(), value.clone()); checkState(spaceNeeded == metaBytes + 8); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); @@ -1227,13 +945,6 @@ public final class RowBuffer { this.length(this.length() + shift); } - /** - * Copies the content of the buffer into the target stream. - */ - public void WriteTo(OutputStream stream) { - stream.Write(this.buffer.Slice(0, this.length())); - } - public void WriteTypedArray(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs, UpdateOptions options, Out newScope) { int numBytes = (Integer.SIZE / Byte.SIZE); @@ -1250,7 +961,7 @@ public final class RowBuffer { metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, scopeType, typeArgs.clone(), metaBytes); checkState(spaceNeeded == metaBytes + numBytes); - this.WriteUInt32(edit.get().valueOffset(), 0); + this.writeUInt32(edit.get().valueOffset(), 0); int valueOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); // Point after the Size newScope.setAndGet(new RowCursor()); newScope.get().scopeType(scopeType); @@ -1279,7 +990,7 @@ public final class RowBuffer { metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, scopeType, typeArgs.clone(), metaBytes); checkState(spaceNeeded == metaBytes + numBytes); - this.WriteUInt32(edit.get().valueOffset(), 0); + this.writeUInt32(edit.get().valueOffset(), 0); int valueOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); // Point after the Size newScope.setAndGet(new RowCursor()); newScope.get().scopeType(scopeType); @@ -1308,7 +1019,7 @@ public final class RowBuffer { metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, scopeType, typeArgs.clone(), metaBytes); checkState(spaceNeeded == metaBytes + numBytes); - this.WriteUInt32(edit.get().valueOffset(), 0); + this.writeUInt32(edit.get().valueOffset(), 0); int valueOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); // Point after the Size newScope.setAndGet(new RowCursor()); newScope.get().scopeType(scopeType); @@ -1355,42 +1066,69 @@ public final class RowBuffer { this = tempReference_this.get(); } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteUInt16(int offset, ushort value) - public void WriteUInt16(int offset, short value) { - Reference tempReference_value = new Reference(value); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: MemoryMarshal.Write(this.buffer.Slice(offset), ref value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); + private void writeUInt16(Short value) { + this.buffer.writeShortLE(value); + } + + private void writeUInt32(Integer value) { + this.buffer.writeIntLE(value); + } + + private void writeUInt64(Long value) { + this.buffer.writeLongLE(value); + } + + private void writeUInt8(Byte value) { + this.buffer.writeByte(value); + } + + public void writeUInt16(int offset, short value) { + Item item = this.write(this::writeUInt16, offset, value); + } + + public void writeUInt32(int offset, int value) { + Item item = this.write(this::writeUInt32, offset, value); + } + + public void writeUInt64(int offset, long value) { + Item item = this.write(this::writeUInt64, offset, value); + } + + public void writeUInt8(int offset, byte value) { + Item item = this.write(this::writeUInt8, offset, value); + } + + public void writeUnixDateTime(int offset, UnixDateTime value) { + Item item = this.write(this::writeUInt64, offset, value.milliseconds()); + } + + public void WriteVariableBinary(int offset, ReadOnlySpan value, boolean exists, + Out shift) { + int numBytes = value.Length; + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); + spaceNeeded = tempOut_spaceNeeded.get(); + + int sizeLenInBytes = this.WriteBinary(offset, value); + checkState(spaceNeeded == numBytes + sizeLenInBytes); + this.length(this.length() + shift.get()); } //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteUInt32(int offset, uint value) - public void WriteUInt32(int offset, int value) { - Reference tempReference_value = new Reference(value); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: MemoryMarshal.Write(this.buffer.Slice(offset), ref value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } + //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySequence value, bool exists, out int + // shift) + public void WriteVariableBinary(int offset, ReadOnlySequence value, boolean exists, + Out shift) { + int numBytes = (int) value.Length; + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); + spaceNeeded = tempOut_spaceNeeded.get(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteUInt64(int offset, ulong value) - public void WriteUInt64(int offset, long value) { - Reference tempReference_value = new Reference(value); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: MemoryMarshal.Write(this.buffer.Slice(offset), ref value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void WriteUInt8(int offset, byte value) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void WriteUInt8(int offset, byte value) - public void WriteUInt8(int offset, byte value) { - this.buffer[offset] = value; + int sizeLenInBytes = this.WriteBinary(offset, value); + checkState(spaceNeeded == numBytes + sizeLenInBytes); + this.length(this.length() + shift.get()); } public void WriteVariableInt(int offset, long value, boolean exists, Out shift) { @@ -1433,6 +1171,44 @@ public final class RowBuffer { this.length(this.length() + shift.get()); } + /** + * Compute the byte offset from the beginning of the row for a given variable column's value. + * + * @param layout The (optional) layout of the current scope. + * @param scopeOffset The 0-based offset to the beginning of the scope's value. + * @param varIndex The 0-based index of the variable column within the variable segment. + * @return The byte offset from the beginning of the row where the variable column's value should be + * located. + */ + public int ComputeVariableValueOffset(Layout layout, int scopeOffset, int varIndex) { + if (layout == null) { + return scopeOffset; + } + + int index = layout.numFixed() + varIndex; + ReadOnlySpan columns = layout.columns(); + checkState(index <= columns.Length); + int offset = scopeOffset + layout.size(); + for (int i = layout.numFixed(); i < index; i++) { + LayoutColumn col = columns[i]; + if (this.readBit(scopeOffset, col.getNullBit().clone())) { + int lengthSizeInBytes; + Out tempOut_lengthSizeInBytes = new Out(); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: ulong valueSizeInBytes = this.Read7BitEncodedUInt(offset, out int lengthSizeInBytes); + long valueSizeInBytes = this.read7BitEncodedUInt(offset); + lengthSizeInBytes = tempOut_lengthSizeInBytes.get(); + if (col.type().getIsVarint()) { + offset += lengthSizeInBytes; + } else { + offset += (int) valueSizeInBytes + lengthSizeInBytes; + } + } + } + + return offset; + } + /** * Compute the number of bytes necessary to store the unsigned 32-bit integer value using the varuint encoding * @@ -1455,50 +1231,12 @@ public final class RowBuffer { this.buffer.setIntLE(offset, (int) (value - decrement)); } - public void WriteUnixDateTime(int offset, UnixDateTime value) { - Reference tempReference_value = - new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySpan value, bool exists, out int shift) - public void WriteVariableBinary(int offset, ReadOnlySpan value, boolean exists, - Out shift) { - int numBytes = value.Length; - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); - spaceNeeded = tempOut_spaceNeeded.get(); - - int sizeLenInBytes = this.WriteBinary(offset, value); - checkState(spaceNeeded == numBytes + sizeLenInBytes); - this.length(this.length() + shift.get()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySequence value, bool exists, out int - // shift) - public void WriteVariableBinary(int offset, ReadOnlySequence value, boolean exists, - Out shift) { - int numBytes = (int)value.Length; - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); - spaceNeeded = tempOut_spaceNeeded.get(); - - int sizeLenInBytes = this.WriteBinary(offset, value); - checkState(spaceNeeded == numBytes + sizeLenInBytes); - this.length(this.length() + shift.get()); - } - /** * Delete the sparse field at the indicated path. * * @param edit The field to delete. */ - public void deleteSparse(RowCursor edit) { + public void DeleteSparse(RowCursor edit) { // If the field doesn't exist, then nothing to do. if (!edit.exists()) { return; @@ -1537,44 +1275,6 @@ public final class RowBuffer { return this.readHeader(); } - /** - * Compute the byte offset from the beginning of the row for a given variable column's value. - * - * @param layout The (optional) layout of the current scope. - * @param scopeOffset The 0-based offset to the beginning of the scope's value. - * @param varIndex The 0-based index of the variable column within the variable segment. - * @return The byte offset from the beginning of the row where the variable column's value should be - * located. - */ - public int computeVariableValueOffset(Layout layout, int scopeOffset, int varIndex) { - if (layout == null) { - return scopeOffset; - } - - int index = layout.numFixed() + varIndex; - ReadOnlySpan columns = layout.columns(); - checkState(index <= columns.Length); - int offset = scopeOffset + layout.size(); - for (int i = layout.numFixed(); i < index; i++) { - LayoutColumn col = columns[i]; - if (this.readBit(scopeOffset, col.getNullBit().clone())) { - int lengthSizeInBytes; - Out tempOut_lengthSizeInBytes = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong valueSizeInBytes = this.Read7BitEncodedUInt(offset, out int lengthSizeInBytes); - long valueSizeInBytes = this.read7BitEncodedUInt(offset, tempOut_lengthSizeInBytes); - lengthSizeInBytes = tempOut_lengthSizeInBytes.get(); - if (col.type().getIsVarint()) { - offset += lengthSizeInBytes; - } else { - offset += (int) valueSizeInBytes + lengthSizeInBytes; - } - } - } - - return offset; - } - public void incrementUInt32(final int offset, final long increment) { final long value = this.buffer.getUnsignedIntLE(offset); this.buffer.setIntLE(offset, (int) (value + increment)); @@ -1662,13 +1362,13 @@ public final class RowBuffer { return dstEdit; } - public long read7BitEncodedInt(int offset, Out lengthInBytes) { - return RowBuffer.rotateSignToMsb(this.read7BitEncodedUInt(offset, lengthInBytes)); + public long read7BitEncodedInt(int offset) { + Item item = this.read(this::read7BitEncodedInt, offset); + return item.value(); } - public long read7BitEncodedUInt(int offset, Out lengthInBytes) { + public long read7BitEncodedUInt(int offset) { Item item = this.read(this::read7BitEncodedUInt, offset); - lengthInBytes.set(item.length()); return item.value(); } @@ -1689,6 +1389,44 @@ public final class RowBuffer { return item.value(); } + public BigDecimal readDecimal(int offset) { + Item item = this.read(() -> DecimalCodec.decode(this.buffer), offset); + return item.value(); + } + + public ByteBuf readFixedBinary(int offset, int length) { + Item item = this.read(() -> this.buffer.readSlice(length), offset); + return item.value(); + } + + public Utf8String readFixedString(int offset, int length) { + Item item = this.read(() -> Utf8String.fromUnsafe(this.buffer.readSlice(length)), offset); + return item.value(); + } + + public Float128 readFloat128(int offset) { + Item item = this.read(this::readFloat128, offset); + return item.value(); + } + + // TODO: DANOBLE: Support MongoDbObjectId values + // public void WriteMongoDbObjectId(int offset, MongoDbObjectId value) { + // Reference tempReference_value = + // new Reference(value); + // MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); + // value = tempReference_value.get(); + // } + + public float readFloat32(int offset) { + Item item = this.read(this.buffer::readFloatLE, offset); + return item.value(); + } + + public double readFloat64(int offset) { + Item item = this.read(this.buffer::readDoubleLE, offset); + return item.value(); + } + /** * Reads in the contents of the current {@link RowBuffer} from an {@link InputStream} *

@@ -1767,49 +1505,97 @@ public final class RowBuffer { return this.read(this.buffer::readShortLE, offset).value(); } - public long readInt64(int offset) { - return this.read(this.buffer::readLongLE, offset).value(); + public int readInt32(int offset) { + Item item = this.read(this.buffer::readIntLE, offset); + return item.value(); } - public byte readInt8(int offset, @Nonnull Out lengthInBytes) { - return this.read(this.buffer::readByte, offset, lengthInBytes); + public long readInt64(int offset) { + Item item = this.read(this.buffer::readLongLE, offset); + return item.value(); + } + + public byte readInt8(int offset) { + Item item = this.read(this.buffer::readByte, offset); + return item.value(); + } + + public SchemaId readSchemaId(int offset) { + Item item = this.read(() -> SchemaId.from(this.buffer.readIntLE()), offset); + return item.value(); + } + + public ByteBuf readSparseBinary(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.BINARY); + Item item = this.read(this::readVariableBinary, edit); + return item.value(); + } + + public boolean readSparseBoolean(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.BOOLEAN); + edit.endOffset(edit.valueOffset()); + return edit.cellType() == LayoutTypes.BOOLEAN; + } + + public OffsetDateTime readSparseDateTime(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.DATE_TIME); + edit.endOffset(edit.valueOffset() + Long.SIZE); + return this.readDateTime(edit.valueOffset()); + } + + public BigDecimal readSparseDecimal(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.DECIMAL); + Item item = this.read(this::readDecimal, edit); + return item.value(); + } + + public Float128 readSparseFloat128(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.FLOAT_128); + Item item = this.read(this::readFloat128, edit); + return item.value(); + } + + public float readSparseFloat32(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.FLOAT_32); + Item item = this.read(this.buffer::readFloatLE, edit); + return item.value(); } public double readSparseFloat64(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.FLOAT_64); - edit.endOffset(edit.valueOffset() + (Double.SIZE / Byte.SIZE)); - return this.readFloat64(edit.valueOffset()); + Item item = this.read(this.buffer::readDoubleLE, edit); + return item.value(); } public UUID readSparseGuid(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.GUID); - edit.endOffset(edit.valueOffset() + 16); - return this.readGuid(edit.valueOffset()); + Item item = this.read(this::readGuid, edit); + return item.value(); } public short readSparseInt16(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.INT_16); - edit.endOffset(edit.valueOffset() + (Short.SIZE / Byte.SIZE)); - return this.readInt16(edit.valueOffset()); + Item item = this.read(this.buffer::readShortLE, edit); + return item.value(); } public int readSparseInt32(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.INT_32); - edit.endOffset(edit.valueOffset() + (Integer.SIZE / Byte.SIZE)); - return this.ReadInt32(edit.valueOffset()); + Item item = this.read(this.buffer::readIntLE, edit); + return item.value(); } public long readSparseInt64(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.INT_64); - edit.endOffset(edit.valueOffset() + (Long.SIZE / Byte.SIZE)); - return this.readInt64(edit.valueOffset()); + Item item = this.read(this.buffer::readLongLE, edit); + return item.value(); } public byte readSparseInt8(RowCursor edit) { - // TODO: Remove calls to ReadSparsePrimitiveTypeCode once moved to V2 read. + // TODO: Remove calls to readSparsePrimitiveTypeCode once moved to V2 read. this.readSparsePrimitiveTypeCode(edit, LayoutTypes.INT_8); - edit.endOffset(edit.valueOffset() + (Byte.SIZE / Byte.SIZE)); - return this.readInt8(edit.valueOffset()); + Item item = this.read(this.buffer::readByte, edit); + return item.value(); } public NullValue readSparseNull(@Nonnull RowCursor edit) { @@ -1845,31 +1631,101 @@ public final class RowBuffer { return token; } - public Utf8String readSparsePath(RowCursor edit) { - - final Optional path = edit.layout().tokenizer().tryFindString(edit.longValue().pathToken); - - if (path.isPresent()) { - return path.get(); - } - - int numBytes = edit.pathToken() - edit.layout().tokenizer().count(); - return Utf8String.unsafeFromUtf8BytesNoValidation(this.buffer.Slice(edit.pathOffset(), numBytes)); + public Utf8String readSparseString(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UTF_8); + Item item = this.read(this::readUtf8String, edit); + return item.value(); } - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal LayoutType ReadSparseTypeCode(int - // offset) public LayoutType readSparseTypeCode(int offset) { - return LayoutType.FromCode(LayoutCode.forValue(this.ReadUInt8(offset))); + return LayoutType.fromCode(LayoutCode.forValue(this.readInt8(offset))); + } + + public int readSparseUInt16(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UINT_16); + Item item = this.read(this.buffer::readUnsignedShortLE, edit); + return item.value(); + } + + public long readSparseUInt32(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UINT_32); + Item item = this.read(this.buffer::readUnsignedIntLE, edit); + return item.value(); + } + + public long readSparseUInt64(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UINT_64); + Item item = this.read(this.buffer::readLongLE, edit); + return item.value; + } + + public short readSparseUInt8(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UINT_8); + Item item = this.read(this.buffer::readUnsignedByte, edit); + return item.value; + } + + public UnixDateTime readSparseUnixDateTime(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.UNIX_DATE_TIME); + Item item = this.read(this::readUnixDateTime, edit); + return item.value(); + } + + public long readSparseVarInt(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.VAR_INT); + Item item = this.read(this::read7BitEncodedInt, edit); + return item.value(); } public long readSparseVarUInt(RowCursor edit) { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.VAR_UINT); - int start = this.buffer.readerIndex(); - long value = this.read7BitEncodedUInt(); - edit.endOffset(edit.valueOffset() + (this.buffer.readerIndex() - start)); - return value; + Item item = this.read(this::read7BitEncodedUInt, edit); + return item.value(); + } + + public int readUInt16(int offset) { + Item item = this.read(this.buffer::readUnsignedShortLE, offset); + return item.value(); + } + + public long readUInt32(int offset) { + Item item = this.read(this.buffer::readUnsignedIntLE, offset); + return item.value(); + } + + public long readUInt64(int offset) { + Item item = this.read(this.buffer::readLongLE, offset); + return item.value(); + } + + public short readUInt8(int offset) { + Item item = this.read(this.buffer::readUnsignedByte, offset); + return item.value(); + } + + public UnixDateTime readUnixDateTime(int offset) { + Item item = this.read(this::readUnixDateTime, offset); + return item.value(); + } + + public ByteBuf readVariableBinary(int offset) { + Item item = this.read(this::readVariableBinary, offset); + return item.value(); + } + + public long readVariableInt(int offset) { + Item item = this.read(this::read7BitEncodedInt, offset); + return item.value(); + } + + public Utf8String readVariableString(int offset) { + Item item = this.read(this::readUtf8String, offset); + return item.value(); + } + + public long readVariableUInt(int offset) { + Item item = this.read(this::read7BitEncodedUInt, offset); + return item.value(); } /** @@ -1922,6 +1778,15 @@ public final class RowBuffer { return isNegative ? (~(unsignedValue >>> 1) + 1) | 0x8000000000000000L : unsignedValue >>> 1; } + public void setBit(final int offset, @Nonnull final LayoutBit bit) { + checkNotNull(bit, "expected non-null bit"); + if (bit.isInvalid()) { + return; + } + final int index = bit.offset(offset); + this.buffer.setByte(index, this.buffer.getByte(bit.offset(offset)) | (byte) (1 << bit.bit())); + } + /** * Move a sparse iterator to the next field within the same sparse scope. * @@ -2020,7 +1885,7 @@ public final class RowBuffer { .metaOffset(valueOffset) .layout(edit.layout()) .immutable(immutable) - .count(this.ReadUInt32(edit.valueOffset())); + .count(this.readInt32(edit.valueOffset())); } if (scopeType instanceof LayoutTypedTuple || scopeType instanceof LayoutTuple || scopeType instanceof LayoutTagged || scopeType instanceof LayoutTagged2) { @@ -2078,7 +1943,7 @@ public final class RowBuffer { if (scopeType instanceof LayoutUDT) { final Layout udt = this.resolver.resolve(edit.cellTypeArgs().schemaId()); - final int valueOffset = this.computeVariableValueOffset(udt, edit.valueOffset(), udt.numVariable()); + final int valueOffset = this.ComputeVariableValueOffset(udt, edit.valueOffset(), udt.numVariable()); return new RowCursor() .scopeType(scopeType) @@ -2093,6 +1958,13 @@ public final class RowBuffer { throw new IllegalStateException(lenientFormat("Not a scope type: %s", scopeType)); } + public void unsetBit(final int offset, @Nonnull final LayoutBit bit) { + checkNotNull(bit, "expected non-null bit"); + checkArgument(!bit.isInvalid()); + final int index = bit.offset(offset); + this.buffer.setByte(index, this.buffer.getByte(index) & (byte) ~(1 << bit.bit())); + } + public int write7BitEncodedInt(int offset, long value) { return this.write7BitEncodedUInt(offset, RowBuffer.rotateSignToLsb(value)); } @@ -2120,11 +1992,70 @@ public final class RowBuffer { return i; } + public void writeDateTime(int offset, OffsetDateTime value) { + Item item = this.write(this::writeDateTime, offset, value); + } + + public void writeDecimal(int offset, BigDecimal value) { + Item item = this.write(this::writeDecimal, offset, value); + } + + public void writeFixedBinary(final int offset, @Nonnull final ByteBuf value, final int length) { + + checkNotNull(value, "expected non-null value"); + checkArgument(offset >= 0, "expected offset >= 0, not %s", offset); + checkArgument(length >= 0, "expected length >= 0, not %s", length); + + Item item = this.write(buffer -> { + int writableBytes = Math.min(length, buffer.readableBytes()); + this.buffer.writeBytes(buffer, writableBytes); + if (writableBytes < length) { + this.buffer.writeZero(length - writableBytes); + } + }, offset, value); + } + + public void writeFixedBinary(final int offset, @Nonnull final byte[] value, final int index, final int length) { + + checkNotNull(value, "expected non-null value"); + checkArgument(offset >= 0, "expected offset >= 0, not %s", offset); + checkArgument(length >= 0, "expected length >= 0, not %s", length); + checkArgument(0 <= index && index < value.length, "expected in range [0, %s), not index", index); + + Item item = this.write(buffer -> { + int writableBytes = Math.min(length, buffer.length - index); + this.buffer.writeBytes(buffer, index, writableBytes); + if (writableBytes < length) { + this.buffer.writeZero(length - writableBytes); + } + }, offset, value); + } + + @SuppressWarnings("ConstantConditions") + public void writeFixedString(final int offset, @Nonnull final Utf8String value) { + checkNotNull(value, "expected non-null value"); + checkArgument(!value.isNull(), "expected non-null value content"); + Item item = this.write(this.buffer::writeBytes, offset, value.content()); + } + public void writeFloat128(int offset, Float128 value) { this.buffer.writeLongLE(value.low()); this.buffer.writeLongLE(value.high()); } + public void writeFloat32(final int offset, final float value) { + Item item = this.write(this.buffer::writeFloatLE, offset, value); + } + + public void writeFloat64(final int offset, final double value) { + Item item = this.write(this.buffer::writeDoubleLE, offset, value); + } + + public void writeGuid(final int offset, @Nonnull final UUID value) { + checkNotNull(value, "expected non-null value"); + Item item = this.write(this::writeGuid, offset, value); + } + public void writeHeader(HybridRowHeader value) { this.buffer.writeByte(value.version().value()); this.buffer.writeIntLE(value.schemaId().value()); @@ -2146,6 +2077,11 @@ public final class RowBuffer { this.buffer.writeByte(value); } + public void writeSchemaId(final int offset, @Nonnull final SchemaId value) { + checkNotNull(value, "expected non-null value"); + this.writeInt32(offset, value.value()); + } + public void writeSparseArray( @Nonnull final RowCursor edit, @Nonnull final LayoutScope scopeType, @Nonnull final UpdateOptions options, @Nonnull final Out newScope) { @@ -2182,7 +2118,7 @@ public final class RowBuffer { .layout(edit.layout()); } - public void writeSparseFloat32(@Nonnull RowCursor edit, float value, @Nonnull UpdateOptions options) { + public void WriteSparseFloat32(@Nonnull RowCursor edit, float value, @Nonnull UpdateOptions options) { int numBytes = (Float.SIZE / Byte.SIZE); int metaBytes; @@ -2198,19 +2134,25 @@ public final class RowBuffer { spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); this.writeSparseMetadata(edit, LayoutType.Float32, TypeArgumentList.EMPTY, metaBytes); - this.WriteFloat32(edit.get().valueOffset(), value); + this.writeFloat32(edit.get().valueOffset(), value); checkState(spaceNeeded == metaBytes + (Float.SIZE / Byte.SIZE)); edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; this.length(this.length() + shift); } - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void WriteSparseTypeCode(int offset, - // LayoutCode code) public void writeSparseTypeCode(int offset, LayoutCode code) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: this.WriteUInt8(offset, (byte)code); - this.WriteUInt8(offset, code.value()); + this.writeUInt8(offset, code.value()); + } + + /** + * Writes the content of the buffer on to an {@link OutputStream} + * + * @param stream the target @{link OutputStream} + * @throws IOException if the specified {@code stream} throws an {@link IOException} during output + */ + public void writeTo(@Nonnull final OutputStream stream) throws IOException { + checkNotNull(stream, "expected non-null stream"); + this.buffer.getBytes(0, stream, this.length()); } /** @@ -2252,16 +2194,6 @@ public final class RowBuffer { return 1; } - /** - * Compute the number of bytes necessary to store the signed integer using the varint encoding. - * - * @param value The value to be encoded - * @return The number of bytes needed to store the varint encoding of {@code value} - */ - private static int Count7BitEncodedInt(long value) { - return RowBuffer.count7BitEncodedUInt(RowBuffer.rotateSignToLsb(value)); - } - /** * Compares the values of two encoded key-value pair fields using the hybrid row binary * collation. @@ -2328,14 +2260,14 @@ public final class RowBuffer { return this.CompareFieldValue(leftKey.clone(), leftKeyLen, rightKey.clone(), rightKeyLen); } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private int WriteBinary(int offset, ReadOnlySpan value) - private int WriteBinary(int offset, ReadOnlySpan value) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)value.Length); - int sizeLenInBytes = this.write7BitEncodedUInt(offset, (long) value.Length); - value.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); - return sizeLenInBytes; + /** + * Compute the number of bytes necessary to store the signed integer using the varint encoding. + * + * @param value The value to be encoded + * @return The number of bytes needed to store the varint encoding of {@code value} + */ + private static int Count7BitEncodedInt(long value) { + return RowBuffer.count7BitEncodedUInt(RowBuffer.rotateSignToLsb(value)); } private void EnsureVariable(int offset, boolean isVarint, int numBytes, boolean exists, @@ -2346,7 +2278,7 @@ public final class RowBuffer { long existingValueBytes = 0; if (exists) { Out tempOut_spaceAvailable = new Out(); - existingValueBytes = this.read7BitEncodedUInt(offset, tempOut_spaceAvailable); + existingValueBytes = this.read7BitEncodedUInt(offset); spaceAvailable = tempOut_spaceAvailable.get(); } @@ -2442,18 +2374,12 @@ public final class RowBuffer { return true; } - private ByteBuf readBinary(int offset) { - Item item = this.read(this::read7BitEncodedUInt, offset); - return this.buffer.readSlice(item.length); + private int WriteBinary(int offset, ReadOnlySpan value) { + int sizeLenInBytes = this.write7BitEncodedUInt(offset, (long) value.Length); + value.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); + return sizeLenInBytes; } - private Utf8Span ReadString(int offset, Out sizeLenInBytes) { - int numBytes = (int) this.read7BitEncodedUInt(offset, sizeLenInBytes); - return Utf8Span.UnsafeFromUtf8BytesNoValidation(this.buffer.Slice(offset + sizeLenInBytes.get(), numBytes)); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private int WriteBinary(int offset, ReadOnlySequence value) private int WriteBinary(int offset, ReadOnlySequence value) { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)value.Length); @@ -2462,32 +2388,6 @@ public final class RowBuffer { return sizeLenInBytes; } - private static int countSparsePath(@Nonnull final RowCursor edit) { - - if (!edit.writePathToken().isNull()) { - StringToken token = edit.writePathToken(); - ByteBuf varint = token.varint(); - return varint.readerIndex() + varint.readableBytes(); - } - - Optional optional = edit.layout().tokenizer().findToken(edit.writePath()); - - if (optional.isPresent()) { - StringToken token = optional.get(); - edit.writePathToken(token); - ByteBuf varint = token.varint(); - return varint.readerIndex() + varint.readableBytes(); - } - - Utf8String path = edit.writePath().toUtf8(); - assert path != null; - - int numBytes = path.length(); - int sizeLenInBytes = RowBuffer.count7BitEncodedUInt(edit.layout().tokenizer().count() + numBytes); - - return sizeLenInBytes + numBytes; - } - /** * Return the size (in bytes) of the default sparse value for the type. * @@ -2586,6 +2486,32 @@ public final class RowBuffer { throw new IllegalStateException(lenientFormat("Not Implemented: %s", code)); } + private static int countSparsePath(@Nonnull final RowCursor edit) { + + if (!edit.writePathToken().isNull()) { + StringToken token = edit.writePathToken(); + ByteBuf varint = token.varint(); + return varint.readerIndex() + varint.readableBytes(); + } + + Optional optional = edit.layout().tokenizer().findToken(edit.writePath()); + + if (optional.isPresent()) { + StringToken token = optional.get(); + edit.writePathToken(token); + ByteBuf varint = token.varint(); + return varint.readerIndex() + varint.readableBytes(); + } + + Utf8String path = edit.writePath().toUtf8(); + assert path != null; + + int numBytes = path.length(); + int sizeLenInBytes = RowBuffer.count7BitEncodedUInt(edit.layout().tokenizer().count() + numBytes); + + return sizeLenInBytes + numBytes; + } + private void ensure(int size) { this.buffer.ensureWritable(size); } @@ -2656,7 +2582,7 @@ public final class RowBuffer { edit.count(edit.count() + 1); } else if ((options == RowOptions.Delete) && edit.exists()) { // Subtract one from the current scope count. - checkState(this.ReadUInt32(edit.start()) > 0); + checkState(this.readUInt32(edit.start()) > 0); this.decrementUInt32(edit.start(), 1); edit.count(edit.count() - 1); } @@ -2695,6 +2621,14 @@ public final class RowBuffer { this.ensureSparse(edit, cellType, typeArgs, numBytes, rowOptions, metaBytes, spaceNeeded, shift); } + private Item read(@Nonnull final Supplier supplier, @Nonnull RowCursor cursor) { + checkNotNull(supplier, "expected non-null supplier"); + checkNotNull(cursor, "expected non-null cursor"); + Item item = this.read(supplier, cursor.valueOffset()); + cursor.endOffset(this.buffer.readerIndex()); + return item; + } + private Item read(@Nonnull final Supplier supplier, int offset) { checkNotNull(supplier); @@ -2716,6 +2650,10 @@ public final class RowBuffer { return item.value(); } + private long read7BitEncodedInt() { + return RowBuffer.rotateSignToMsb(this.read7BitEncodedUInt()); + } + private long read7BitEncodedUInt() { long b = this.buffer.readByte() & 0xFFL; @@ -2737,6 +2675,18 @@ public final class RowBuffer { return result; } + private BigDecimal readDecimal() { + return DecimalCodec.decode(this.buffer); + } + + private Float128 readFloat128() { + return Float128Codec.decode(this.buffer); + } + + private UUID readGuid() { + return GuidCodec.decode(this.buffer); + } + private HybridRowHeader readHeader() { HybridRowVersion version = HybridRowVersion.from(this.buffer.readByte()); SchemaId schemaId = SchemaId.from(this.buffer.readIntLE()); @@ -2839,6 +2789,22 @@ public final class RowBuffer { } } + private UnixDateTime readUnixDateTime() { + return new UnixDateTime(this.buffer.readLongLE()); + } + + private Utf8String readUtf8String() { + long length = this.read7BitEncodedUInt(); + checkState(length <= Integer.MAX_VALUE, "expected length <= %s, not %s", Integer.MAX_VALUE, length); + return Utf8String.fromUnsafe(this.buffer.readSlice((int)length)); + } + + private ByteBuf readVariableBinary() { + long length = this.read7BitEncodedUInt(); + checkState(length <= Integer.MAX_VALUE, "expected length <= %s, not %s", Integer.MAX_VALUE, length); + return this.buffer.readSlice((int)length); + } + /** * Skip over a nested scope * @@ -2936,7 +2902,7 @@ public final class RowBuffer { case BINARY: { int sizeLenInBytes; Out tempOut_sizeLenInBytes = new Out<>(); - int numBytes = (int) this.read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes); + int numBytes = (int) this.read7BitEncodedUInt(metaOffset + metaBytes); sizeLenInBytes = tempOut_sizeLenInBytes.get(); return metaBytes + sizeLenInBytes + numBytes; } @@ -2945,7 +2911,7 @@ public final class RowBuffer { case VAR_UINT: { int sizeLenInBytes; Out tempOut_sizeLenInBytes2 = new Out(); - this.read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes2); + this.read7BitEncodedUInt(metaOffset + metaBytes); sizeLenInBytes = tempOut_sizeLenInBytes2.get(); return metaBytes + sizeLenInBytes; } @@ -2990,9 +2956,27 @@ public final class RowBuffer { return header.version().equals(version) && (HybridRowHeader.SIZE + layout.size()) <= this.length(); } + private Item write(@Nonnull final Consumer consumer, final int offset, @Nonnull final T value) { + checkNotNull(consumer, "expected non-null consumer"); + checkNotNull(value, "expected non-null value"); + this.buffer.writerIndex(offset); + consumer.accept(value); + return new Item<>(value, offset, this.buffer.writerIndex() - offset); + } + + private void writeDateTime(OffsetDateTime value) { + DateTimeCodec.encode(value, this.buffer); + } + + private void writeDecimal(BigDecimal value) { + DecimalCodec.encode(value, this.buffer); + } + private int writeDefaultValue(int offset, LayoutType code, TypeArgumentList typeArgs) { - // JTHTODO: convert to a virtual? + // TODO: DANOBLE: Put default values in a central location (LayoutTypes?) and use them in this method + // ensure that there are no null default values (which this method currently uses) + // TODO: JTH: convert to a virtual? if (code == LayoutTypes.NULL) { this.writeSparseTypeCode(offset, code.layoutCode()); @@ -3025,32 +3009,32 @@ public final class RowBuffer { } if (code == LayoutTypes.UINT_8) { - this.WriteUInt8(offset, (byte) 0); + this.writeUInt8(offset, (byte) 0); return LayoutTypes.UINT_8.size(); } if (code == LayoutTypes.UINT_16) { - this.WriteUInt16(offset, (short) 0); + this.writeUInt16(offset, (short) 0); return LayoutTypes.UINT_16.size(); } if (code == LayoutTypes.UINT_32) { - this.WriteUInt32(offset, 0); + this.writeUInt32(offset, 0); return LayoutTypes.UINT_32.size(); } if (code == LayoutTypes.UINT_64) { - this.WriteUInt64(offset, 0); + this.writeUInt64(offset, 0); return LayoutTypes.UINT_64.size(); } if (code == LayoutTypes.FLOAT_32) { - this.WriteFloat32(offset, 0); + this.writeFloat32(offset, 0); return LayoutTypes.FLOAT_32.size(); } if (code == LayoutTypes.FLOAT_64) { - this.WriteFloat64(offset, 0); + this.writeFloat64(offset, 0); return LayoutTypes.FLOAT_64.size(); } @@ -3060,22 +3044,22 @@ public final class RowBuffer { } if (code == LayoutTypes.DECIMAL) { - this.WriteDecimal(offset, BigDecimal.ZERO); + this.writeDecimal(offset, BigDecimal.ZERO); return LayoutTypes.DECIMAL.size(); } if (code == LayoutTypes.DATE_TIME) { - this.WriteDateTime(offset, LocalDateTime.MIN); + this.writeDateTime(offset, OffsetDateTime.MIN); return LayoutTypes.DATE_TIME.size(); } if (code == LayoutTypes.UNIX_DATE_TIME) { - this.WriteUnixDateTime(offset, null); + this.writeUnixDateTime(offset, null); return LayoutTypes.UNIX_DATE_TIME.size(); } if (code == LayoutTypes.GUID) { - this.WriteGuid(offset, null); + this.writeGuid(offset, null); return LayoutTypes.GUID.size(); } @@ -3099,7 +3083,7 @@ public final class RowBuffer { if (code == LayoutTypes.TYPED_ARRAY || code == LayoutTypes.TypedSet || code == LayoutTypes.TypedMap) { // Variable length typed collection scopes preceded by their scope size take sizeof(uint) for a size of 0. - this.WriteUInt32(offset, 0); + this.writeUInt32(offset, 0); return (Integer.SIZE / Byte.SIZE); } @@ -3142,6 +3126,10 @@ public final class RowBuffer { throw new IllegalStateException(lenientFormat("Not Implemented: %s", code)); } + private void writeGuid(UUID value) { + GuidCodec.encode(value, this.buffer); + } + private void writeSparseMetadata( @Nonnull final RowCursor edit, @Nonnull final LayoutType cellType, @Nonnull final TypeArgumentList typeArgs, final int metaBytes) { diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java index 76f464a..6091bf7 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java @@ -52,7 +52,7 @@ public final class RowCursor implements Cloneable { final SchemaId schemaId = row.readSchemaId(1); final Layout layout = row.resolver().resolve(schemaId); - final int sparseSegmentOffset = row.computeVariableValueOffset(layout, HybridRowHeader.SIZE, layout.numVariable()); + final int sparseSegmentOffset = row.ComputeVariableValueOffset(layout, HybridRowHeader.SIZE, layout.numVariable()); return new RowCursor() .layout(layout) diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java index 64aa1f7..b4ed49e 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java @@ -23,7 +23,7 @@ public final class RowCursors { if (!(edit.cellType() instanceof LayoutEndScope)) { while (row.sparseIteratorMoveNext(edit)) { - if (path.equals(row.readSparsePath(edit))) { + if (path.equals(row.ReadSparsePath(edit))) { edit.exists(true); break; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/UnixDateTime.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/UnixDateTime.java index dea954a..432e223 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/UnixDateTime.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/UnixDateTime.java @@ -9,89 +9,68 @@ package com.azure.data.cosmos.serialization.hybridrow; * A {@link UnixDateTime} is a fixed length value-type providing millisecond * granularity as a signed offset from the Unix Epoch (midnight, January 1, 1970 UTC). */ -// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: -//ORIGINAL LINE: [DebuggerDisplay("{" + nameof(UnixDateTime.Milliseconds) + "}")][StructLayout(LayoutKind.Sequential, -// Pack = 1)] public readonly struct UnixDateTime : IEquatable -//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ -// from the original: -//ORIGINAL LINE: [DebuggerDisplay("{" + nameof(UnixDateTime.Milliseconds) + "}")][StructLayout(LayoutKind.Sequential, -// Pack = 1)] public readonly struct UnixDateTime : IEquatable -//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct: -public final class UnixDateTime implements IEquatable { +public final class UnixDateTime { /** - * The unix epoch. - * {@link UnixDateTime} values are signed values centered on {@link Epoch}. - * - * This is the same value as default({@link UnixDateTime}). + * Unix epoch + *

+ * {@link UnixDateTime} values are signed values centered on this value. */ - public static final UnixDateTime Epoch = new UnixDateTime(); + public static final UnixDateTime EPOCH = new UnixDateTime(); + /** - * The size (in bytes) of a UnixDateTime. + * Size in bytes of a {@link UnixDateTime} */ - public static final int Size = (Long.SIZE / Byte.SIZE); - /** - * The number of milliseconds since {@link Epoch}. - * This value may be negative. - */ - private long Milliseconds; + public static final int BYTES = Long.SIZE; + + private long milliseconds; /** * Initializes a new instance of the {@link UnixDateTime} struct. * - * @param milliseconds The number of milliseconds since {@link Epoch}. + * @param milliseconds The number of milliseconds since {@link EPOCH}. */ - public UnixDateTime() { + private UnixDateTime() { } public UnixDateTime(long milliseconds) { - this.Milliseconds = milliseconds; - } - - public long getMilliseconds() { - return Milliseconds; + this.milliseconds = milliseconds; } /** - * Returns true if this is the same value as {@link other}. + * {@code> true} if this value is the same as another value * - * @param other The value to compare against. - * @return True if the two values are the same. + * @param other value to compare + * @return {code true} if this value is the same as the {code other} */ public boolean equals(UnixDateTime other) { - return this.getMilliseconds() == other.getMilliseconds(); - } - - /** - * {@link object.Equals(object)} overload. - */ - @Override - public boolean equals(Object obj) { - if (null == obj) { + if (other == null) { return false; } - - return obj instanceof UnixDateTime && this.equals((UnixDateTime)obj); + return this.milliseconds() == other.milliseconds(); + } + + @Override + public boolean equals(Object other) { + if (null == other) { + return false; + } + if (this == other) { + return true; + } + return other instanceof UnixDateTime && this.equals((UnixDateTime)other); } - /** - * {@link object.GetHashCode} overload. - */ @Override public int hashCode() { - return (new Long(this.getMilliseconds())).hashCode(); + return Long.valueOf(this.milliseconds).hashCode(); } /** - * Operator == overload. + * The number of milliseconds since {@link #EPOCH} + *

+ * This value may be negative */ - public static boolean opEquals(UnixDateTime left, UnixDateTime right) { - return left.equals(right.clone()); - } - - /** - * Operator != overload. - */ - public static boolean opNotEquals(UnixDateTime left, UnixDateTime right) { - return !left.equals(right.clone()); + public long milliseconds() { + return this.milliseconds; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java index 8e684d4..1f4ecac 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java @@ -196,7 +196,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - Utf8Span span = this.row.readSparsePath(tempReference_cursor); + Utf8Span span = this.row.ReadSparsePath(tempReference_cursor); this.cursor = tempReference_cursor.get(); return Utf8String.CopyFrom(span); default: @@ -216,7 +216,7 @@ public final class RowReader { case Sparse: Reference tempReference_cursor = new Reference(this.cursor); - Utf8Span tempVar = this.row.readSparsePath(tempReference_cursor); + Utf8Span tempVar = this.row.ReadSparsePath(tempReference_cursor); this.cursor = tempReference_cursor.get(); return tempVar; default: @@ -839,7 +839,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseString(tempReference_cursor)); + value.setAndGet(this.row.readSparseString(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -868,7 +868,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseUInt16(tempReference_cursor)); + value.setAndGet(this.row.readSparseUInt16(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -897,7 +897,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseUInt32(tempReference_cursor)); + value.setAndGet(this.row.readSparseUInt32(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -926,7 +926,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseUInt64(tempReference_cursor)); + value.setAndGet(this.row.readSparseUInt64(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -955,7 +955,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseUInt8(tempReference_cursor)); + value.setAndGet(this.row.readSparseUInt8(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -982,7 +982,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseUnixDateTime(tempReference_cursor).clone()); + value.setAndGet(this.row.readSparseUnixDateTime(tempReference_cursor).clone()); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -1009,7 +1009,7 @@ public final class RowReader { Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseVarInt(tempReference_cursor)); + value.setAndGet(this.row.readSparseVarInt(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java index d52239b..419b165 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java @@ -117,9 +117,9 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa return Result.NotFound; } - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); - value.setAndGet(b.get().ReadVariableBinary(varOffset)); + value.setAndGet(b.get().readVariableBinary(varOffset)); return Result.Success; } @@ -148,7 +148,7 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa } b.get().WriteFixedBinary(scope.get().start() + col.getOffset(), value, col.getSize()); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } @@ -165,7 +165,7 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa } b.get().WriteFixedBinary(scope.get().start() + col.getOffset(), value, col.getSize()); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } @@ -255,13 +255,13 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa } boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); int shift; Out tempOut_shift = new Out(); b.get().WriteVariableBinary(varOffset, value, exists, tempOut_shift); shift = tempOut_shift.get(); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); scope.get().metaOffset(scope.get().metaOffset() + shift); scope.get().valueOffset(scope.get().valueOffset() + shift); return Result.Success; @@ -283,13 +283,13 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa } boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); int shift; Out tempOut_shift = new Out(); b.get().WriteVariableBinary(varOffset, value, exists, tempOut_shift); shift = tempOut_shift.get(); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); scope.get().metaOffset(scope.get().metaOffset() + shift); scope.get().valueOffset(scope.get().valueOffset() + shift); return Result.Success; diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBit.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBit.java index 807de2d..ec93665 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBit.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBit.java @@ -42,7 +42,7 @@ public final class LayoutBit { * @return The bit of the byte within the bitmask. */ public int bit() { - return this.index() % LayoutTypes.BitsPerByte; + return this.index() % Byte.SIZE; } /** @@ -65,7 +65,7 @@ public final class LayoutBit { * @return The byte offset containing this bit. */ public int offset(int offset) { - return offset + (this.index() / LayoutTypes.BitsPerByte); + return offset + (this.index() / Byte.SIZE); } @Override @@ -102,7 +102,7 @@ public final class LayoutBit { * The number of bytes needed to hold all bits so far allocated. */ public final int getNumBytes() { - return LayoutBit.divCeiling(this.next, LayoutTypes.BitsPerByte); + return LayoutBit.divCeiling(this.next, Byte.SIZE); } /** diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBoolean.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBoolean.java index fed0fac..9ec2573 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBoolean.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBoolean.java @@ -63,12 +63,12 @@ public final class LayoutBoolean extends LayoutType { } if (value) { - b.get().SetBit(scope.get().start(), col.getBooleanBit().clone()); + b.get().setBit(scope.get().start(), col.getBooleanBit().clone()); } else { - b.get().UnsetBit(scope.get().start(), col.getBooleanBit().clone()); + b.get().unsetBit(scope.get().start(), col.getBooleanBit().clone()); } - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java index c40a12e..eed664a 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java @@ -60,8 +60,8 @@ public final class LayoutDateTime extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteDateTime(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeDateTime(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java index 3959e67..ab94bc2 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java @@ -58,8 +58,8 @@ public final class LayoutFloat32 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteFloat32(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeFloat32(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } @@ -74,7 +74,7 @@ public final class LayoutFloat32 extends LayoutType { return result; } - b.get().writeSparseFloat32(edit, value, options); + b.get().WriteSparseFloat32(edit, value, options); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java index 48e827f..f3734d1 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java @@ -58,8 +58,8 @@ public final class LayoutFloat64 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteFloat64(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeFloat64(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java index b40e669..dafe1a9 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java @@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType { } b.get().writeInt16(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java index 1b128ed..f0dff7d 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java @@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType { } b.get().writeInt32(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java index 02c8c4e..511d05a 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java @@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType { } b.get().writeInt64(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java index 2281c5f..66a5cb1 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java @@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType { } b.get().writeInt8(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java index f9f1a3d..ab295f5 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java @@ -4,7 +4,6 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; @@ -80,7 +79,7 @@ public abstract class LayoutScope extends LayoutType { return result; } - b.deleteSparse(edit); + b.DeleteSparse(edit); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java index 3d28c6e..87f5973 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java @@ -107,7 +107,7 @@ public abstract class LayoutType implements ILayoutType { return Result.TypeMismatch; } - b.UnsetBit(scope.start(), column.nullBit()); + b.unsetBit(scope.start(), column.nullBit()); return Result.Success; } @@ -127,7 +127,7 @@ public abstract class LayoutType implements ILayoutType { return result; } - b.deleteSparse(edit); + b.DeleteSparse(edit); return Result.Success; } @@ -148,9 +148,9 @@ public abstract class LayoutType implements ILayoutType { boolean exists = b.readBit(scope.start(), column.nullBit()); if (exists) { - int varOffset = b.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); + int varOffset = b.ComputeVariableValueOffset(scope.layout(), scope.start(), column.offset()); b.deleteVariable(varOffset, this.isVarint()); - b.UnsetBit(scope.start(), column.nullBit()); + b.unsetBit(scope.start(), column.nullBit()); } return Result.Success; @@ -245,19 +245,19 @@ public abstract class LayoutType implements ILayoutType { } if (destinationScope.immutable()) { - b.deleteSparse(srcEdit); + b.DeleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.InsufficientPermissions; } if (!srcEdit.cellTypeArgs().equals(elementType.typeArgs())) { - b.deleteSparse(srcEdit); + b.DeleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.TypeConstraint; } if (options == UpdateOptions.InsertAt) { - b.deleteSparse(srcEdit); + b.DeleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.TypeConstraint; } @@ -265,13 +265,13 @@ public abstract class LayoutType implements ILayoutType { // Prepare the insertion at the destination. dstEdit.setAndGet(b.prepareSparseMove(destinationScope, srcEdit)); if ((options == UpdateOptions.Update) && (!dstEdit.get().exists())) { - b.deleteSparse(srcEdit); + b.DeleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.NotFound; } if ((options == UpdateOptions.Insert) && dstEdit.get().exists()) { - b.deleteSparse(srcEdit); + b.DeleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.Exists; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypes.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypes.java index 22e4063..7bed2e8 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypes.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypes.java @@ -9,7 +9,6 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; public abstract class LayoutTypes { public static final LayoutArray ARRAY = new LayoutArray(false); public static final LayoutBinary BINARY = new LayoutBinary(); - public static final int BitsPerByte = 8; public static final LayoutBoolean BOOLEAN = new LayoutBoolean(true); public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false); public static final LayoutDateTime DATE_TIME = new LayoutDateTime(); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java index e425a59..5a98074 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java @@ -58,7 +58,7 @@ public final class LayoutUDT extends LayoutPropertyScope { @Override public int writeTypeArgument(Reference row, int offset, TypeArgumentList value) { row.get().writeSparseTypeCode(offset, this.LayoutCode); - row.get().WriteSchemaId(offset + (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), value.schemaId().clone()); + row.get().writeSchemaId(offset + (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), value.schemaId().clone()); return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.SIZE; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java index 1ae224b..0122625 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java @@ -68,8 +68,8 @@ public final class LayoutUInt16 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteUInt16(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeUInt16(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java index bfc0658..370821c 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java @@ -68,8 +68,8 @@ public final class LayoutUInt32 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteUInt32(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeUInt32(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java index a649886..f2cffc2 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java @@ -68,8 +68,8 @@ public final class LayoutUInt64 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteUInt64(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeUInt64(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java index 9812f80..625aaa6 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java @@ -68,8 +68,8 @@ public final class LayoutUInt8 extends LayoutType { return Result.InsufficientPermissions; } - b.get().WriteUInt8(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeUInt8(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java index 6ab0b64..32caf10 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java @@ -43,7 +43,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope { } // Check if the search found the result. - b.get().deleteSparse(patternScope); + b.get().DeleteSparse(patternScope); return Result.Success; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java index ad015bd..f747d93 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java @@ -14,7 +14,7 @@ import static com.google.common.base.Preconditions.checkArgument; public final class LayoutUnixDateTime extends LayoutType { public LayoutUnixDateTime() { super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UNIX_DATE_TIME, - com.azure.data.cosmos.serialization.hybridrow.UnixDateTime.Size); + com.azure.data.cosmos.serialization.hybridrow.UnixDateTime.BYTES); } public boolean isFixed() { diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java index 8e1a321..edcf8e9 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java @@ -68,7 +68,7 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S return result; } - value.setAndGet(b.get().ReadSparseString(edit)); + value.setAndGet(b.get().readSparseString(edit)); return Result.Success; } @@ -92,9 +92,9 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S return Result.NotFound; } - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); - value.setAndGet(b.get().ReadVariableString(varOffset)); + value.setAndGet(b.get().readVariableString(varOffset)); return Result.Success; } @@ -114,8 +114,8 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S return Result.InsufficientPermissions; } - b.get().WriteFixedString(scope.get().start() + col.getOffset(), value); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().writeFixedString(scope.get().start() + col.getOffset(), value); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); return Result.Success; } @@ -173,13 +173,13 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S } boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); int shift; Out tempOut_shift = new Out(); b.get().WriteVariableString(varOffset, value, exists, tempOut_shift); shift = tempOut_shift.get(); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); scope.get().metaOffset(scope.get().metaOffset() + shift); scope.get().valueOffset(scope.get().valueOffset() + shift); return Result.Success; diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java index ca8ef89..b694dc7 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java @@ -98,13 +98,13 @@ public final class LayoutVarInt extends LayoutType { } boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); int shift; Out tempOut_shift = new Out(); b.get().WriteVariableInt(varOffset, value, exists, tempOut_shift); shift = tempOut_shift.get(); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); scope.get().metaOffset(scope.get().metaOffset() + shift); scope.get().valueOffset(scope.get().valueOffset() + shift); return Result.Success; diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java index 54d77fe..c5d812c 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java @@ -115,13 +115,13 @@ public final class LayoutVarUInt extends LayoutType { } boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); - int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), + int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); int shift; Out tempOut_shift = new Out(); b.get().WriteVariableUInt(varOffset, value, exists, tempOut_shift); shift = tempOut_shift.get(); - b.get().SetBit(scope.get().start(), col.getNullBit().clone()); + b.get().setBit(scope.get().start(), col.getNullBit().clone()); scope.get().metaOffset(scope.get().metaOffset() + shift); scope.get().valueOffset(scope.get().valueOffset() + shift); return Result.Success; diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java index f0dfd79..811463f 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java @@ -101,7 +101,7 @@ public final class JsonModelRowGenerator { // TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or // output: public void WriteTo(OutputStream stream) { - this.row.WriteTo(stream); + this.row.writeTo(stream); } public JsonModelRowGenerator clone() { diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java index 8838e53..e8fd058 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java @@ -417,7 +417,7 @@ public final class RowOperationDispatcher { public String RowToHex() { try (MemoryStream stm = new MemoryStream()) { - this.Row.WriteTo(stm); + this.Row.writeTo(stm); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: ReadOnlyMemory bytes = stm.GetBuffer().AsMemory(0, (int)stm.Position); ReadOnlyMemory bytes = stm.GetBuffer().AsMemory(0, (int)stm.Position);