diff --git a/java/exclusions/ISpanResizer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/ISpanResizer.java similarity index 100% rename from java/exclusions/ISpanResizer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/ISpanResizer.java diff --git a/java/exclusions/MemorySpanResizer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/MemorySpanResizer.java similarity index 100% rename from java/exclusions/MemorySpanResizer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/MemorySpanResizer.java diff --git a/java/exclusions/SamplingStringComparer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingStringComparer.java similarity index 100% rename from java/exclusions/SamplingStringComparer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingStringComparer.java diff --git a/java/exclusions/SamplingUtf8StringComparer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingUtf8StringComparer.java similarity index 100% rename from java/exclusions/SamplingUtf8StringComparer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingUtf8StringComparer.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java similarity index 95% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java index c62c544..490d34e 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Record.java @@ -1,37 +1,37 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -public final class Record { - - public static Record empty() { - return new Record(0, 0); - } - - private int crc32; - private int length; - - public Record(int length, int crc32) { - this.length = length; - this.crc32 = crc32; - } - - public int crc32() { - return this.crc32; - } - - public Record crc32(int value) { - this.crc32 = value; - return this; - } - - public int length() { - return this.length; - } - - public Record length(int value) { - this.length = value; - return this; - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +public final class Record { + + public static Record empty() { + return new Record(0, 0); + } + + private int crc32; + private int length; + + public Record(int length, int crc32) { + this.length = length; + this.crc32 = crc32; + } + + public int crc32() { + return this.crc32; + } + + public Record crc32(int value) { + this.crc32 = value; + return this; + } + + public int length() { + return this.length; + } + + public Record length(int value) { + this.length = value; + return this; + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java similarity index 98% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java index fc46f05..689825b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java @@ -1,78 +1,78 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader; -import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; -import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; -import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; - -public final class RecordIOFormatter { - - public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID); - public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID); - - public static Result FormatRecord(ReadOnlyMemory body, Out row) { - return FormatRecord(body, row, null); - } - - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public static Result FormatRecord(ReadOnlyMemory body, out RowBuffer row, - // ISpanResizer resizer = default) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public static Result FormatRecord(ReadOnlyMemory body, Out row, - ISpanResizer resizer) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer.Default; - resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; - int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span); - int crc32 = Crc32.Update(0, body.Span); - Record record = new Record(body.Length, crc32); - return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(), - RecordSerializer.Write, row.clone()); - } - - public static Result FormatSegment(Segment segment, Out row) { - return FormatSegment(segment, row, null); - } - - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer - // resizer = default) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public static Result FormatSegment(Segment segment, Out row, ISpanResizer resizer) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer.Default; - resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; - int estimatedSize = - HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null : - segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null : - segment.sdl().length() != null ? segment.sdl().length() : 0 + 20; - - return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT, - segment.clone(), SegmentSerializer.Write, row.clone()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private static Result FormatObject(ISpanResizer resizer, int initialCapacity, Layout - // layout, T obj, RowWriter.WriterFunc writer, out RowBuffer row) - private static Result FormatObject(ISpanResizer resizer, int initialCapacity, Layout layout, T obj, - RowWriter.WriterFunc writer, Out row) { - row.setAndGet(new RowBuffer(initialCapacity, resizer)); - row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver); - Result r = RowWriter.WriteBuffer(row.clone(), obj, writer); - if (r != Result.SUCCESS) { - row.setAndGet(null); - return r; - } - - return Result.SUCCESS; - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader; +import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; +import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; +import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; + +public final class RecordIOFormatter { + + public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID); + public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID); + + public static Result FormatRecord(ReadOnlyMemory body, Out row) { + return FormatRecord(body, row, null); + } + + //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: + //ORIGINAL LINE: public static Result FormatRecord(ReadOnlyMemory body, out RowBuffer row, + // ISpanResizer resizer = default) + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + public static Result FormatRecord(ReadOnlyMemory body, Out row, + ISpanResizer resizer) { + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer.Default; + resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; + int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length; + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span); + int crc32 = Crc32.Update(0, body.Span); + Record record = new Record(body.Length, crc32); + return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(), + RecordSerializer.Write, row.clone()); + } + + public static Result FormatSegment(Segment segment, Out row) { + return FormatSegment(segment, row, null); + } + + //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: + //ORIGINAL LINE: public static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer + // resizer = default) + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + public static Result FormatSegment(Segment segment, Out row, ISpanResizer resizer) { + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer.Default; + resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; + int estimatedSize = + HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null : + segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null : + segment.sdl().length() != null ? segment.sdl().length() : 0 + 20; + + return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT, + segment.clone(), SegmentSerializer.Write, row.clone()); + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: private static Result FormatObject(ISpanResizer resizer, int initialCapacity, Layout + // layout, T obj, RowWriter.WriterFunc writer, out RowBuffer row) + private static Result FormatObject(ISpanResizer resizer, int initialCapacity, Layout layout, T obj, + RowWriter.WriterFunc writer, Out row) { + row.setAndGet(new RowBuffer(initialCapacity, resizer)); + row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver); + Result r = RowWriter.WriteBuffer(row.clone(), obj, writer); + if (r != Result.SUCCESS) { + row.setAndGet(null); + return r; + } + + return Result.SUCCESS; + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java similarity index 97% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java index 996f410..d6547b5 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java @@ -1,353 +1,354 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader; -import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.SchemaId; -import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; -import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; -import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import javax.annotation.Nonnull; - -import static com.google.common.base.Preconditions.checkState; - -public final class RecordIOParser { - - private Record record; - private Segment segment; - private State state = State.values()[0]; - - /** - * Processes one buffers worth of data possibly advancing the parser state - * - * @param buffer1 The buffer to consume - * @param type Indicates the type of Hybrid Row produced in {@code record} - * @param record If non-empty, then the body of the next record in the sequence - * @param need The smallest number of bytes needed to advanced the parser state further - *

- * It is recommended that this method not be called again until at least this number of bytes are - * available. - * @param consumed The number of bytes consumed from the input buffer - *

- * This number may be less than the total buffer size if the parser moved to a new state. - * @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error - * encountered during parsing. - *

- * > - */ - @Nonnull - public Result process( - @Nonnull final ByteBuf buffer, - @Nonnull final Out type, - @Nonnull final Out record, - @Nonnull final Out need, - @Nonnull final Out consumed) { - - Result result = Result.FAILURE; - type.set(ProductionType.NONE); - record.set(null); - - final int start = buffer.readerIndex(); - - switch (this.state) { - - case STATE: - this.state = State.NEED_SEGMENT_LENGTH; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case State.NeedSegmentLength; - - case NEED_SEGMENT_LENGTH: { - - final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size(); - - if (buffer.readableBytes() < minimalSegmentRowSize) { - consumed.set(buffer.readerIndex() - start); - need.set(minimalSegmentRowSize); - return Result.INSUFFICIENT_BUFFER; - } - - ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize); - RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); - Reference tempReference_row = - new Reference(row); - RowReader reader = new RowReader(tempReference_row); - row = tempReference_row.get(); - Reference tempReference_reader = - new Reference(reader); - Out tempOut_segment = - new Out(); - result = SegmentSerializer.read(tempReference_reader, tempOut_segment); - this.segment = tempOut_segment.get(); - reader = tempReference_reader.get(); - if (result != Result.SUCCESS) { - break; - } - - this.state = State.NEED_SEGMENT; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - goto case State.NEED_SEGMENT - } - - case NEED_SEGMENT: { - if (buffer.Length < this.segment.length()) { - need.set(this.segment.length()); - consumed.set(buffer.Length - buffer.Length); - return Result.INSUFFICIENT_BUFFER; - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Span span = b.Span.Slice(0, this.segment.Length); - Span span = buffer.Span.Slice(0, this.segment.length()); - RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); - Reference tempReference_row2 = - new Reference(row); - RowReader reader = new RowReader(tempReference_row2); - row = tempReference_row2.get(); - Reference tempReference_reader2 = - new Reference(reader); - Out tempOut_segment2 - = new Out(); - result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2); - this.segment = tempOut_segment2.get(); - reader = tempReference_reader2.get(); - if (result != Result.SUCCESS) { - break; - } - - record.set(buffer.Slice(0, span.Length)); - buffer = buffer.Slice(span.Length); - need.set(0); - this.state = State.NEED_HEADER; - consumed.set(buffer.Length - buffer.Length); - type.set(ProductionType.SEGMENT); - return Result.SUCCESS; - } - - case NEED_HEADER: { - if (buffer.Length < HybridRowHeader.BYTES) { - need.set(HybridRowHeader.BYTES); - consumed.set(buffer.Length - buffer.Length); - return Result.INSUFFICIENT_BUFFER; - } - - HybridRowHeader header; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - - // these cannot be converted using the 'Out' helper class unless the method is within the code - // being modified: - MemoryMarshal.TryRead(buffer.Span, out header); - if (header.Version != HybridRowVersion.V1) { - result = Result.INVALID_ROW; - break; - } - - if (SchemaId.opEquals(header.SchemaId, - SystemSchema.SEGMENT_SCHEMA_ID)) { - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - goto case State.NEED_SEGMENT - } - - if (SchemaId.opEquals(header.SchemaId, - SystemSchema.RECORD_SCHEMA_ID)) { - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - goto case State.NEED_RECORD - } - - result = Result.INVALID_ROW; - break; - } - - case NEED_RECORD: { - int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size(); - if (buffer.Length < minimalRecordRowSize) { - need.set(minimalRecordRowSize); - consumed.set(buffer.Length - buffer.Length); - return Result.INSUFFICIENT_BUFFER; - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Span span = b.Span.Slice(0, minimalRecordRowSize); - Span span = buffer.Span.Slice(0, minimalRecordRowSize); - RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); - Reference tempReference_row3 = - new Reference(row); - RowReader reader = new RowReader(tempReference_row3); - row = tempReference_row3.get(); - Reference tempReference_reader3 = new Reference(reader); - Out tempOut_record = new Out(); - result = RecordSerializer.read(tempReference_reader3, tempOut_record); - this.record = tempOut_record.get(); - reader = tempReference_reader3.get(); - if (result != Result.SUCCESS) { - break; - } - - buffer = buffer.Slice(span.Length); - this.state = State.NEED_ROW; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - goto case State.NEED_ROW - } - - case NEED_ROW: { - if (buffer.Length < this.record.length()) { - need.set(this.record.length()); - consumed.set(buffer.Length - buffer.Length); - return Result.INSUFFICIENT_BUFFER; - } - - record.set(buffer.Slice(0, this.record.length())); - - // Validate that the record has not been corrupted. - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span); - int crc32 = Crc32.Update(0, record.get().Span); - if (crc32 != this.record.crc32()) { - result = Result.INVALID_ROW; - break; - } - - buffer = buffer.Slice(this.record.length()); - need.set(0); - this.state = State.NEED_HEADER; - consumed.set(buffer.Length - buffer.Length); - type.set(ProductionType.RECORD); - return Result.SUCCESS; - } - } - - this.state = State.ERROR; - need.set(0); - consumed.set(buffer.Length - buffer.Length); - return result; - } - - /** - * True if a valid segment has been parsed. - */ - public boolean haveSegment() { - return this.state.value() >= State.NEED_HEADER.value(); - } - - /** - * If a valid segment has been parsed then current active segment, otherwise undefined. - */ - public Segment segment() { - checkState(this.haveSegment()); - return this.segment; - } - - /** - * Describes the type of Hybrid Rows produced by the parser. - */ - public enum ProductionType { - /** - * No hybrid row was produced. The parser needs more data. - */ - NONE(0), - - /** - * A new segment row was produced. - */ - SEGMENT(1), - - /** - * A record in the current segment was produced. - */ - RECORD(2); - - public static final int BYTES = Integer.BYTES; - - private static Int2ObjectMap mappings; - private int value; - - ProductionType(int value) { - this.value = value; - mappings().put(value, this); - } - - public int value() { - return this.value; - } - - public static ProductionType from(int value) { - return mappings().get(value); - } - - private static Int2ObjectMap mappings() { - if (mappings == null) { - synchronized (ProductionType.class) { - if (mappings == null) { - mappings = new Int2ObjectOpenHashMap<>(); - } - } - } - return mappings; - } - } - - /** - * The states for the internal state machine. - * Note: numerical ordering of these states matters. - */ - private enum State { - STATE( - (byte) 0, "Start: no buffers have yet been provided to the parser"), - ERROR( - (byte) 1, "Unrecoverable parse error encountered"), - NEED_SEGMENT_LENGTH( - (byte) 2, "Parsing segment header length"), - NEED_SEGMENT( - (byte) 3, "Parsing segment header"), - NEED_HEADER( - (byte) 4, "Parsing HybridRow header"), - NEED_RECORD( - (byte) 5, "Parsing record header"), - NEED_ROW( - (byte) 6, "Parsing row body"); - - public static final int BYTES = Byte.SIZE; - - private static Byte2ObjectMap mappings; - private final String description; - private final byte value; - - State(byte value, String description) { - this.description = description; - this.value = value; - mappings().put(value, this); - } - - public String description() { - return this.description; - } - - public byte value() { - return this.value; - } - - public static State from(byte value) { - return mappings().get(value); - } - - private static Byte2ObjectMap mappings() { - if (mappings == null) { - synchronized (State.class) { - if (mappings == null) { - mappings = new Byte2ObjectOpenHashMap<>(); - } - } - } - return mappings; - } - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.core.Reference; +import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader; +import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.SchemaId; +import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; +import com.azure.data.cosmos.serialization.hybridrow.io.Segment; +import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkState; + +public final class RecordIOParser { + + private Record record; + private Segment segment; + private State state = State.values()[0]; + + /** + * Processes one buffers worth of data possibly advancing the parser state + * + * @param buffer1 The buffer to consume + * @param type Indicates the type of Hybrid Row produced in {@code record} + * @param record If non-empty, then the body of the next record in the sequence + * @param need The smallest number of bytes needed to advanced the parser state further + *

+ * It is recommended that this method not be called again until at least this number of bytes are + * available. + * @param consumed The number of bytes consumed from the input buffer + *

+ * This number may be less than the total buffer size if the parser moved to a new state. + * @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error + * encountered during parsing. + *

+ * > + */ + @Nonnull + public Result process( + @Nonnull final ByteBuf buffer, + @Nonnull final Out type, + @Nonnull final Out record, + @Nonnull final Out need, + @Nonnull final Out consumed) { + + Result result = Result.FAILURE; + type.set(ProductionType.NONE); + record.set(null); + + final int start = buffer.readerIndex(); + + switch (this.state) { + + case STATE: + this.state = State.NEED_SEGMENT_LENGTH; + // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: + // goto case State.NeedSegmentLength; + + case NEED_SEGMENT_LENGTH: { + + final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size(); + + if (buffer.readableBytes() < minimalSegmentRowSize) { + consumed.set(buffer.readerIndex() - start); + need.set(minimalSegmentRowSize); + return Result.INSUFFICIENT_BUFFER; + } + + ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize); + RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); + Reference tempReference_row = + new Reference(row); + RowReader reader = new RowReader(tempReference_row); + row = tempReference_row.get(); + Reference tempReference_reader = + new Reference(reader); + Out tempOut_segment = + new Out(); + result = SegmentSerializer.read(tempReference_reader, tempOut_segment); + this.segment = tempOut_segment.get(); + reader = tempReference_reader.get(); + if (result != Result.SUCCESS) { + break; + } + + this.state = State.NEED_SEGMENT; + // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: + goto case State.NEED_SEGMENT + } + + case NEED_SEGMENT: { + if (buffer.Length < this.segment.length()) { + need.set(this.segment.length()); + consumed.set(buffer.Length - buffer.Length); + return Result.INSUFFICIENT_BUFFER; + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Span span = b.Span.Slice(0, this.segment.Length); + Span span = buffer.Span.Slice(0, this.segment.length()); + RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); + Reference tempReference_row2 = + new Reference(row); + RowReader reader = new RowReader(tempReference_row2); + row = tempReference_row2.get(); + Reference tempReference_reader2 = + new Reference(reader); + Out tempOut_segment2 + = new Out(); + result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2); + this.segment = tempOut_segment2.get(); + reader = tempReference_reader2.get(); + if (result != Result.SUCCESS) { + break; + } + + record.set(buffer.Slice(0, span.Length)); + buffer = buffer.Slice(span.Length); + need.set(0); + this.state = State.NEED_HEADER; + consumed.set(buffer.Length - buffer.Length); + type.set(ProductionType.SEGMENT); + return Result.SUCCESS; + } + + case NEED_HEADER: { + if (buffer.Length < HybridRowHeader.BYTES) { + need.set(HybridRowHeader.BYTES); + consumed.set(buffer.Length - buffer.Length); + return Result.INSUFFICIENT_BUFFER; + } + + HybridRowHeader header; + // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - + // these cannot be converted using the 'Out' helper class unless the method is within the code + // being modified: + MemoryMarshal.TryRead(buffer.Span, out header); + if (header.Version != HybridRowVersion.V1) { + result = Result.INVALID_ROW; + break; + } + + if (SchemaId.opEquals(header.SchemaId, + SystemSchema.SEGMENT_SCHEMA_ID)) { + // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: + goto case State.NEED_SEGMENT + } + + if (SchemaId.opEquals(header.SchemaId, + SystemSchema.RECORD_SCHEMA_ID)) { + // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: + goto case State.NEED_RECORD + } + + result = Result.INVALID_ROW; + break; + } + + case NEED_RECORD: { + int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size(); + if (buffer.Length < minimalRecordRowSize) { + need.set(minimalRecordRowSize); + consumed.set(buffer.Length - buffer.Length); + return Result.INSUFFICIENT_BUFFER; + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Span span = b.Span.Slice(0, minimalRecordRowSize); + Span span = buffer.Span.Slice(0, minimalRecordRowSize); + RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); + Reference tempReference_row3 = + new Reference(row); + RowReader reader = new RowReader(tempReference_row3); + row = tempReference_row3.get(); + Reference tempReference_reader3 = new Reference(reader); + Out tempOut_record = new Out(); + result = RecordSerializer.read(tempReference_reader3, tempOut_record); + this.record = tempOut_record.get(); + reader = tempReference_reader3.get(); + if (result != Result.SUCCESS) { + break; + } + + buffer = buffer.Slice(span.Length); + this.state = State.NEED_ROW; + // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: + goto case State.NEED_ROW + } + + case NEED_ROW: { + if (buffer.Length < this.record.length()) { + need.set(this.record.length()); + consumed.set(buffer.Length - buffer.Length); + return Result.INSUFFICIENT_BUFFER; + } + + record.set(buffer.Slice(0, this.record.length())); + + // Validate that the record has not been corrupted. + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span); + int crc32 = Crc32.Update(0, record.get().Span); + if (crc32 != this.record.crc32()) { + result = Result.INVALID_ROW; + break; + } + + buffer = buffer.Slice(this.record.length()); + need.set(0); + this.state = State.NEED_HEADER; + consumed.set(buffer.Length - buffer.Length); + type.set(ProductionType.RECORD); + return Result.SUCCESS; + } + } + + this.state = State.ERROR; + need.set(0); + consumed.set(buffer.Length - buffer.Length); + return result; + } + + /** + * True if a valid segment has been parsed. + */ + public boolean haveSegment() { + return this.state.value() >= State.NEED_HEADER.value(); + } + + /** + * If a valid segment has been parsed then current active segment, otherwise undefined. + */ + public Segment segment() { + checkState(this.haveSegment()); + return this.segment; + } + + /** + * Describes the type of Hybrid Rows produced by the parser. + */ + public enum ProductionType { + /** + * No hybrid row was produced. The parser needs more data. + */ + NONE(0), + + /** + * A new segment row was produced. + */ + SEGMENT(1), + + /** + * A record in the current segment was produced. + */ + RECORD(2); + + public static final int BYTES = Integer.BYTES; + + private static Int2ObjectMap mappings; + private int value; + + ProductionType(int value) { + this.value = value; + mappings().put(value, this); + } + + public int value() { + return this.value; + } + + public static ProductionType from(int value) { + return mappings().get(value); + } + + private static Int2ObjectMap mappings() { + if (mappings == null) { + synchronized (ProductionType.class) { + if (mappings == null) { + mappings = new Int2ObjectOpenHashMap<>(); + } + } + } + return mappings; + } + } + + /** + * The states for the internal state machine. + * Note: numerical ordering of these states matters. + */ + private enum State { + STATE( + (byte) 0, "Start: no buffers have yet been provided to the parser"), + ERROR( + (byte) 1, "Unrecoverable parse error encountered"), + NEED_SEGMENT_LENGTH( + (byte) 2, "Parsing segment header length"), + NEED_SEGMENT( + (byte) 3, "Parsing segment header"), + NEED_HEADER( + (byte) 4, "Parsing HybridRow header"), + NEED_RECORD( + (byte) 5, "Parsing record header"), + NEED_ROW( + (byte) 6, "Parsing row body"); + + public static final int BYTES = Byte.SIZE; + + private static Byte2ObjectMap mappings; + private final String description; + private final byte value; + + State(byte value, String description) { + this.description = description; + this.value = value; + mappings().put(value, this); + } + + public String description() { + return this.description; + } + + public byte value() { + return this.value; + } + + public static State from(byte value) { + return mappings().get(value); + } + + private static Byte2ObjectMap mappings() { + if (mappings == null) { + synchronized (State.class) { + if (mappings == null) { + mappings = new Byte2ObjectOpenHashMap<>(); + } + } + } + return mappings; + } + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java similarity index 98% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java index 2b17d14..43f2868 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOStream.java @@ -1,368 +1,368 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; - -import java.io.InputStream; -import java.io.OutputStream; - -public final class RecordIOStream { -/** - * A function that produces RecordIO record bodies. - *

- * Record bodies are returned as memory blocks. It is expected that each block is a - * HybridRow, but any binary data is allowed. - * - * @param index The 0-based index of the record within the segment to be produced. - * @return A tuple with: Success if the body was produced without error, the error code otherwise. - * And, the byte sequence of the record body's row buffer. - */ - public delegate ValueTask - - ProduceFuncAsync(long index);<(Result,ReadOnlyMemory)> - - /** - * Reads an entire RecordIO stream. - * - * @param stm The stream to read from. - * @param visitRecord A (required) delegate that is called once for each record. - *

- * is passed a {@link Memory{T}} of the byte sequence - * of the - * record body's row buffer. - *

- *

If returns an error then the sequence is aborted.

- * @param visitSegment An (optional) delegate that is called once for each segment header. - *

- * If is not provided then segment headers are parsed but - * skipped - * over. - *

- *

- * is passed a {@link Memory{T}} of the byte sequence of - * the segment header's row buffer. - *

- *

If returns an error then the sequence is aborted.

- * @param resizer Optional memory resizer. - * @return Success if the stream is parsed without error, the error code otherwise. - */ - - public static Task ReadRecordIOAsync(Stream stm, Func, Result> visitRecord, - Func, Result> visitSegment) { - return ReadRecordIOAsync(stm, visitRecord, visitSegment, null); - } - - public static Task ReadRecordIOAsync(Stream stm, Func, Result> visitRecord) { - return ReadRecordIOAsync(stm, visitRecord, null, null); - } - - // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: - //ORIGINAL LINE: public static async Task ReadRecordIOAsync(this Stream stm, Func, Result> - // visitRecord, Func, Result> visitSegment = default, MemorySpanResizer resizer = default) - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public static Task ReadRecordIOAsync(InputStream stm, - tangible.Func1Param, Result> visitRecord, - tangible.Func1Param, Result> visitSegment, - MemorySpanResizer resizer) { - checkArgument(stm != null); - checkArgument(visitRecord != null); - - // Create a reusable, resizable buffer if the caller didn't provide one. - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer(); - resizer = resizer != null ? resizer : new MemorySpanResizer(); - - RecordIOParser parser = null; - int need = 0; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Memory active = resizer.Memory; - Memory active = resizer.getMemory(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Memory avail = default; - Memory avail = null; - while (true) { - checkState(avail.Length < active.Length); - checkState(active.Length > 0); - checkState(active.Length >= need); - - // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: - int read = await stm.ReadAsync(active.Slice(avail.Length)); - if (read == 0) { - break; - } - - avail = active.Slice(0, avail.Length + read); - - // If there isn't enough data to move the parser forward then just read again. - if (avail.Length < need) { - continue; - } - - // Process the available data until no more forward progress is possible. - while (avail.Length > 0) { - // Loop around processing available data until we don't have anymore - RecordIOParser.ProductionType prodType; - Out tempOut_prodType = new Out(); - Memory record; - Out> tempOut_record = new Out>(); - Out tempOut_need = new Out(); - int consumed; - Out tempOut_consumed = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out - // Memory record, out need, out int consumed); - Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed); - consumed = tempOut_consumed.get(); - need = tempOut_need.get(); - record = tempOut_record.get(); - prodType = tempOut_prodType.get(); - - if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) { - return r; - } - - active = active.Slice(consumed); - avail = avail.Slice(consumed); - if (avail.IsEmpty) { - active = resizer.getMemory(); - } - - // If there wasn't enough data to move the parser forward then get more data. - if (r == Result.INSUFFICIENT_BUFFER) { - if (need > active.Length) { - resizer.Resize(need, avail.Span); - active = resizer.getMemory(); - avail = resizer.getMemory().Slice(0, avail.Length); - } - - break; - } - - // Validate the Segment - if (prodType == RecordIOParser.ProductionType.SEGMENT) { - checkState(!record.IsEmpty); - r = visitSegment == null ? null : visitSegment.invoke(record) != null ? - visitSegment.invoke(record) : Result.SUCCESS; - if (r != Result.SUCCESS) { - return r; - } - } - - // Consume the record. - if (prodType == RecordIOParser.ProductionType.RECORD) { - checkState(!record.IsEmpty); - - r = visitRecord.invoke(record); - if (r != Result.SUCCESS) { - return r; - } - } - } - } - - // Make sure we processed all of the available data. - checkState(avail.Length == 0); - return Result.SUCCESS; - } - - /** - * Writes a RecordIO segment into a stream. - * - * @param stm The stream to write to. - * @param segment The segment header to write. - * @param produce A function to produces the record bodies for the segment. - *

- * The function is called until either an error is encountered or it - * produces an empty body. An empty body terminates the segment. - *

- *

If returns an error then the sequence is aborted.

- * @param resizer Optional memory resizer for RecordIO metadata row buffers. - *

- * Note: This should NOT be the same resizer used to process any rows as both - * blocks of memory are used concurrently. - *

- * @return Success if the stream is written without error, the error code otherwise. - */ - - public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) { - return WriteRecordIOAsync(stm, segment, produce, null); - } - - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public static Task WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc - // produce, MemorySpanResizer resizer = default) - // TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or - // output: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce, - MemorySpanResizer resizer) { - return RecordIOStream.WriteRecordIOAsync(stm, - segment.clone(), index -> - { - ReadOnlyMemory buffer; - Out> tempOut_buffer = new Out>(); - buffer = tempOut_buffer.get(); - return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer)) - }, resizer); - } - - /** - * Writes a RecordIO segment into a stream. - * - * @param stm The stream to write to. - * @param segment The segment header to write. - * @param produce A function to produces the record bodies for the segment. - *

- * The function is called until either an error is encountered or it - * produces an empty body. An empty body terminates the segment. - *

- *

If returns an error then the sequence is aborted.

- * @param resizer Optional memory resizer for RecordIO metadata row buffers. - *

- * Note: This should NOT be the same resizer used to process any rows as both - * blocks of memory are used concurrently. - *

- * @return Success if the stream is written without error, the error code otherwise. - */ - - public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) { - return WriteRecordIOAsync(stm, segment, produce, null); - } - - // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: - //ORIGINAL LINE: public static async Task WriteRecordIOAsync(this Stream stm, Segment segment, - // ProduceFuncAsync produce, MemorySpanResizer resizer = default) - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public static Task WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce, - MemorySpanResizer resizer) { - // Create a reusable, resizable buffer if the caller didn't provide one. - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer(); - resizer = resizer != null ? resizer : new MemorySpanResizer(); - - // Write a RecordIO stream. - Memory metadata; - Out> tempOut_metadata = new Out>(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Result r = RecordIOStream.FormatSegment(segment, resizer, out Memory metadata); - Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata); - metadata = tempOut_metadata.get(); - if (r != Result.SUCCESS) { - return r; - } - - // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: - await stm.WriteAsync(metadata); - - long index = 0; - while (true) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ReadOnlyMemory body; - ReadOnlyMemory body; - // TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments: - (r, body) =await produce (index++); - if (r != Result.SUCCESS) { - return r; - } - - if (body.IsEmpty) { - break; - } - - Out> tempOut_metadata2 = new Out>(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata); - r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2); - metadata = tempOut_metadata2.get(); - if (r != Result.SUCCESS) { - return r; - } - - // Metadata and Body memory blocks should not overlap since they are both in - // play at the same time. If they do this usually means that the same resizer - // was incorrectly used for both. Check the resizer parameter passed to - // WriteRecordIOAsync for metadata. - checkState(!metadata.Span.Overlaps(body.Span)); - - // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: - await stm.WriteAsync(metadata); - // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: - await stm.WriteAsync(body); - } - - return Result.SUCCESS; - } - - /** - * Compute and format a record header for the given record body. - * - * @param body The body whose record header should be formatted. - * @param resizer The resizer to use in allocating a buffer for the record header. - * @param block The byte sequence of the written row buffer. - * @return Success if the write completes without error, the error code otherwise. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private static Result FormatRow(ReadOnlyMemory body, MemorySpanResizer resizer, out Memory block) - private static Result FormatRow(ReadOnlyMemory body, MemorySpanResizer resizer, Out> block) { - RowBuffer row; - Out tempOut_row = new Out(); - Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer); - row = tempOut_row.get(); - if (r != Result.SUCCESS) { - block.setAndGet(null); - return r; - } - - block.setAndGet(resizer.getMemory().Slice(0, row.Length)); - return Result.SUCCESS; - } - - /** - * Format a segment. - * - * @param segment The segment to format. - * @param resizer The resizer to use in allocating a buffer for the segment. - * @param block The byte sequence of the written row buffer. - * @return Success if the write completes without error, the error code otherwise. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer resizer, out - // Memory block) - private static Result FormatSegment(Segment segment, MemorySpanResizer resizer, - Out> block) { - RowBuffer row; - Out tempOut_row = - new Out(); - Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer); - row = tempOut_row.get(); - if (r != Result.SUCCESS) { - block.setAndGet(null); - return r; - } - - block.setAndGet(resizer.getMemory().Slice(0, row.Length)); - return Result.SUCCESS; - } - - /** - * A function that produces RecordIO record bodies. - *

- * Record bodies are returned as memory blocks. It is expected that each block is a - * HybridRow, but any binary data is allowed. - * - * @param index The 0-based index of the record within the segment to be produced. - * @param buffer The byte sequence of the record body's row buffer. - * @return Success if the body was produced without error, the error code otherwise. - */ - @FunctionalInterface - public interface ProduceFunc { - Result invoke(long index, Out> buffer); - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; + +import java.io.InputStream; +import java.io.OutputStream; + +public final class RecordIOStream { +/** + * A function that produces RecordIO record bodies. + *

+ * Record bodies are returned as memory blocks. It is expected that each block is a + * HybridRow, but any binary data is allowed. + * + * @param index The 0-based index of the record within the segment to be produced. + * @return A tuple with: Success if the body was produced without error, the error code otherwise. + * And, the byte sequence of the record body's row buffer. + */ + public delegate ValueTask + + ProduceFuncAsync(long index);<(Result,ReadOnlyMemory)> + + /** + * Reads an entire RecordIO stream. + * + * @param stm The stream to read from. + * @param visitRecord A (required) delegate that is called once for each record. + *

+ * is passed a {@link Memory{T}} of the byte sequence + * of the + * record body's row buffer. + *

+ *

If returns an error then the sequence is aborted.

+ * @param visitSegment An (optional) delegate that is called once for each segment header. + *

+ * If is not provided then segment headers are parsed but + * skipped + * over. + *

+ *

+ * is passed a {@link Memory{T}} of the byte sequence of + * the segment header's row buffer. + *

+ *

If returns an error then the sequence is aborted.

+ * @param resizer Optional memory resizer. + * @return Success if the stream is parsed without error, the error code otherwise. + */ + + public static Task ReadRecordIOAsync(Stream stm, Func, Result> visitRecord, + Func, Result> visitSegment) { + return ReadRecordIOAsync(stm, visitRecord, visitSegment, null); + } + + public static Task ReadRecordIOAsync(Stream stm, Func, Result> visitRecord) { + return ReadRecordIOAsync(stm, visitRecord, null, null); + } + + // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: + //ORIGINAL LINE: public static async Task ReadRecordIOAsync(this Stream stm, Func, Result> + // visitRecord, Func, Result> visitSegment = default, MemorySpanResizer resizer = default) + //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + public static Task ReadRecordIOAsync(InputStream stm, + tangible.Func1Param, Result> visitRecord, + tangible.Func1Param, Result> visitSegment, + MemorySpanResizer resizer) { + checkArgument(stm != null); + checkArgument(visitRecord != null); + + // Create a reusable, resizable buffer if the caller didn't provide one. + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer(); + resizer = resizer != null ? resizer : new MemorySpanResizer(); + + RecordIOParser parser = null; + int need = 0; + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Memory active = resizer.Memory; + Memory active = resizer.getMemory(); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Memory avail = default; + Memory avail = null; + while (true) { + checkState(avail.Length < active.Length); + checkState(active.Length > 0); + checkState(active.Length >= need); + + // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: + int read = await stm.ReadAsync(active.Slice(avail.Length)); + if (read == 0) { + break; + } + + avail = active.Slice(0, avail.Length + read); + + // If there isn't enough data to move the parser forward then just read again. + if (avail.Length < need) { + continue; + } + + // Process the available data until no more forward progress is possible. + while (avail.Length > 0) { + // Loop around processing available data until we don't have anymore + RecordIOParser.ProductionType prodType; + Out tempOut_prodType = new Out(); + Memory record; + Out> tempOut_record = new Out>(); + Out tempOut_need = new Out(); + int consumed; + Out tempOut_consumed = new Out(); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out + // Memory record, out need, out int consumed); + Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed); + consumed = tempOut_consumed.get(); + need = tempOut_need.get(); + record = tempOut_record.get(); + prodType = tempOut_prodType.get(); + + if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) { + return r; + } + + active = active.Slice(consumed); + avail = avail.Slice(consumed); + if (avail.IsEmpty) { + active = resizer.getMemory(); + } + + // If there wasn't enough data to move the parser forward then get more data. + if (r == Result.INSUFFICIENT_BUFFER) { + if (need > active.Length) { + resizer.Resize(need, avail.Span); + active = resizer.getMemory(); + avail = resizer.getMemory().Slice(0, avail.Length); + } + + break; + } + + // Validate the Segment + if (prodType == RecordIOParser.ProductionType.SEGMENT) { + checkState(!record.IsEmpty); + r = visitSegment == null ? null : visitSegment.invoke(record) != null ? + visitSegment.invoke(record) : Result.SUCCESS; + if (r != Result.SUCCESS) { + return r; + } + } + + // Consume the record. + if (prodType == RecordIOParser.ProductionType.RECORD) { + checkState(!record.IsEmpty); + + r = visitRecord.invoke(record); + if (r != Result.SUCCESS) { + return r; + } + } + } + } + + // Make sure we processed all of the available data. + checkState(avail.Length == 0); + return Result.SUCCESS; + } + + /** + * Writes a RecordIO segment into a stream. + * + * @param stm The stream to write to. + * @param segment The segment header to write. + * @param produce A function to produces the record bodies for the segment. + *

+ * The function is called until either an error is encountered or it + * produces an empty body. An empty body terminates the segment. + *

+ *

If returns an error then the sequence is aborted.

+ * @param resizer Optional memory resizer for RecordIO metadata row buffers. + *

+ * Note: This should NOT be the same resizer used to process any rows as both + * blocks of memory are used concurrently. + *

+ * @return Success if the stream is written without error, the error code otherwise. + */ + + public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) { + return WriteRecordIOAsync(stm, segment, produce, null); + } + + //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: + //ORIGINAL LINE: public static Task WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc + // produce, MemorySpanResizer resizer = default) + // TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or + // output: + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce, + MemorySpanResizer resizer) { + return RecordIOStream.WriteRecordIOAsync(stm, + segment.clone(), index -> + { + ReadOnlyMemory buffer; + Out> tempOut_buffer = new Out>(); + buffer = tempOut_buffer.get(); + return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer)) + }, resizer); + } + + /** + * Writes a RecordIO segment into a stream. + * + * @param stm The stream to write to. + * @param segment The segment header to write. + * @param produce A function to produces the record bodies for the segment. + *

+ * The function is called until either an error is encountered or it + * produces an empty body. An empty body terminates the segment. + *

+ *

If returns an error then the sequence is aborted.

+ * @param resizer Optional memory resizer for RecordIO metadata row buffers. + *

+ * Note: This should NOT be the same resizer used to process any rows as both + * blocks of memory are used concurrently. + *

+ * @return Success if the stream is written without error, the error code otherwise. + */ + + public static Task WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) { + return WriteRecordIOAsync(stm, segment, produce, null); + } + + // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: + //ORIGINAL LINE: public static async Task WriteRecordIOAsync(this Stream stm, Segment segment, + // ProduceFuncAsync produce, MemorySpanResizer resizer = default) + //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + public static Task WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce, + MemorySpanResizer resizer) { + // Create a reusable, resizable buffer if the caller didn't provide one. + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer(); + resizer = resizer != null ? resizer : new MemorySpanResizer(); + + // Write a RecordIO stream. + Memory metadata; + Out> tempOut_metadata = new Out>(); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: Result r = RecordIOStream.FormatSegment(segment, resizer, out Memory metadata); + Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata); + metadata = tempOut_metadata.get(); + if (r != Result.SUCCESS) { + return r; + } + + // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: + await stm.WriteAsync(metadata); + + long index = 0; + while (true) { + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: ReadOnlyMemory body; + ReadOnlyMemory body; + // TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments: + (r, body) =await produce (index++); + if (r != Result.SUCCESS) { + return r; + } + + if (body.IsEmpty) { + break; + } + + Out> tempOut_metadata2 = new Out>(); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata); + r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2); + metadata = tempOut_metadata2.get(); + if (r != Result.SUCCESS) { + return r; + } + + // Metadata and Body memory blocks should not overlap since they are both in + // play at the same time. If they do this usually means that the same resizer + // was incorrectly used for both. Check the resizer parameter passed to + // WriteRecordIOAsync for metadata. + checkState(!metadata.Span.Overlaps(body.Span)); + + // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: + await stm.WriteAsync(metadata); + // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: + await stm.WriteAsync(body); + } + + return Result.SUCCESS; + } + + /** + * Compute and format a record header for the given record body. + * + * @param body The body whose record header should be formatted. + * @param resizer The resizer to use in allocating a buffer for the record header. + * @param block The byte sequence of the written row buffer. + * @return Success if the write completes without error, the error code otherwise. + */ + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: private static Result FormatRow(ReadOnlyMemory body, MemorySpanResizer resizer, out Memory block) + private static Result FormatRow(ReadOnlyMemory body, MemorySpanResizer resizer, Out> block) { + RowBuffer row; + Out tempOut_row = new Out(); + Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer); + row = tempOut_row.get(); + if (r != Result.SUCCESS) { + block.setAndGet(null); + return r; + } + + block.setAndGet(resizer.getMemory().Slice(0, row.Length)); + return Result.SUCCESS; + } + + /** + * Format a segment. + * + * @param segment The segment to format. + * @param resizer The resizer to use in allocating a buffer for the segment. + * @param block The byte sequence of the written row buffer. + * @return Success if the write completes without error, the error code otherwise. + */ + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer resizer, out + // Memory block) + private static Result FormatSegment(Segment segment, MemorySpanResizer resizer, + Out> block) { + RowBuffer row; + Out tempOut_row = + new Out(); + Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer); + row = tempOut_row.get(); + if (r != Result.SUCCESS) { + block.setAndGet(null); + return r; + } + + block.setAndGet(resizer.getMemory().Slice(0, row.Length)); + return Result.SUCCESS; + } + + /** + * A function that produces RecordIO record bodies. + *

+ * Record bodies are returned as memory blocks. It is expected that each block is a + * HybridRow, but any binary data is allowed. + * + * @param index The 0-based index of the record within the segment to be produced. + * @param buffer The byte sequence of the record body's row buffer. + * @return Success if the body was produced without error, the error code otherwise. + */ + @FunctionalInterface + public interface ProduceFunc { + Result invoke(long index, Out> buffer); + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java similarity index 96% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java index 485fb66..bdb05d4 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordSerializer.java @@ -1,68 +1,68 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.UtfAnyString; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; -import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; -import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; - -import javax.annotation.Nonnull; - -import static com.google.common.base.Preconditions.checkState; - -public final class RecordSerializer { - - @Nonnull - public static Result read(RowReader reader, Out record) { - - Out value = new Out<>(); - record.set(Record.empty()); - - while (reader.read()) { - - String path = reader.path().toUtf16(); - checkState(path != null); - Result result; - - // TODO: use Path tokens here - - switch (path) { - - case "length": - - result = reader.readInt32(value); - record.get().length(value.get()); - - if (result != Result.SUCCESS) { - return result; - } - break; - - case "crc32": - - result = reader.readInt32(value); - record.get().crc32(value.get()); - - if (result != Result.SUCCESS) { - return result; - } - break; - } - } - - return Result.SUCCESS; - } - - @Nonnull - public static Result write(RowWriter writer, TypeArgument typeArg, Record record) { - Result result = writer.writeInt32(new UtfAnyString("length"), record.length()); - if (result != Result.SUCCESS) { - return result; - } - return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32()); - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.core.UtfAnyString; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; +import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; +import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; + +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkState; + +public final class RecordSerializer { + + @Nonnull + public static Result read(RowReader reader, Out record) { + + Out value = new Out<>(); + record.set(Record.empty()); + + while (reader.read()) { + + String path = reader.path().toUtf16(); + checkState(path != null); + Result result; + + // TODO: use Path tokens here + + switch (path) { + + case "length": + + result = reader.readInt32(value); + record.get().length(value.get()); + + if (result != Result.SUCCESS) { + return result; + } + break; + + case "crc32": + + result = reader.readInt32(value); + record.get().crc32(value.get()); + + if (result != Result.SUCCESS) { + return result; + } + break; + } + } + + return Result.SUCCESS; + } + + @Nonnull + public static Result write(RowWriter writer, TypeArgument typeArg, Record record) { + Result result = writer.writeInt32(new UtfAnyString("length"), record.length()); + if (result != Result.SUCCESS) { + return result; + } + return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32()); + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java similarity index 90% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java index 63ccb68..78db48b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java +++ b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java @@ -1,120 +1,123 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.Utf8String; -import com.azure.data.cosmos.core.UtfAnyString; -import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; -import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; -import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; -import io.netty.buffer.ByteBuf; - -import static com.google.common.base.Preconditions.checkState; - -public final class SegmentSerializer { - - private static final UtfAnyString COMMENT = new UtfAnyString("comment"); - private static final UtfAnyString LENGTH = new UtfAnyString("length"); - private static final UtfAnyString SDL = new UtfAnyString("sdl"); - - public static Result read(ByteBuf buffer, LayoutResolver resolver, Out segment) { - RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver)); - return SegmentSerializer.read(reader, segment); - } - - public static Result read(RowReader reader, Out segment) { - - segment.set(new Segment(null, null)); - - final Out comment = new Out<>(); - final Out length = new Out<>(); - final Out sdl = new Out<>(); - - while (reader.read()) { - - // TODO: Use Path tokens here. - - switch (reader.path().toString()) { - - case "length": { - - Result result = reader.readInt32(length); - segment.get().length(length.get()); - - if (result != Result.SUCCESS) { - return result; - } - - if (reader.length() < segment.get().length()) { - // RowBuffer isn't big enough to contain the rest of the header so just return the length - return Result.SUCCESS; - } - - break; - } - case "comment": { - - Result result = reader.readString(comment); - segment.get().comment(comment.get().toUtf16()); - - if (result != Result.SUCCESS) { - return result; - } - - break; - } - case "sdl": { - - Result result = reader.readString(sdl); - segment.get().sdl(sdl.get().toUtf16()); - - if (result != Result.SUCCESS) { - return result; - } - - break; - } - } - } - - return Result.SUCCESS; - } - - public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) { - - Result result; - - if (segment.comment() != null) { - result = writer.writeString(COMMENT, segment.comment()); - if (result != Result.SUCCESS) { - return result; - } - } - - if (segment.sdl() != null) { - result = writer.writeString(SDL, segment.sdl()); - if (result != Result.SUCCESS) { - return result; - } - } - - // Defer writing the length until all other fields of the segment header are written. - // The length is then computed based on the current size of the underlying RowBuffer. - // Because the length field is itself fixed, writing the length can never change the length. - - int length = writer.length(); - result = writer.writeInt32(LENGTH, length); - if (result != Result.SUCCESS) { - return result; - } - - checkState(length == writer.length()); - return Result.SUCCESS; - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.recordio; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.core.Utf8String; +import com.azure.data.cosmos.core.UtfAnyString; +import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; +import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; +import com.azure.data.cosmos.serialization.hybridrow.io.Segment; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; +import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; +import io.netty.buffer.ByteBuf; + +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkState; + +public final class SegmentSerializer { + + private static final UtfAnyString COMMENT = new UtfAnyString("comment"); + private static final UtfAnyString LENGTH = new UtfAnyString("length"); + private static final UtfAnyString SDL = new UtfAnyString("sdl"); + + public static Result read(ByteBuf buffer, LayoutResolver resolver, Out segment) { + RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver)); + return SegmentSerializer.read(reader, segment); + } + + public static Result read(RowReader reader, Out segment) { + + segment.set(new Segment(null, null)); + + final Out comment = new Out<>(); + final Out length = new Out<>(); + final Out sdl = new Out<>(); + + while (reader.read()) { + + // TODO: Use Path tokens here. + + switch (Objects.requireNonNull(reader.path().toUtf16())) { + + case "length": { + + Result result = reader.readInt32(length); + segment.get().length(length.get()); + + if (result != Result.SUCCESS) { + return result; + } + + if (reader.length() < segment.get().length()) { + // RowBuffer isn't big enough to contain the rest of the header so just return the length + return Result.SUCCESS; + } + + break; + } + case "comment": { + + Result result = reader.readString(comment); + segment.get().comment(comment.get()); + + if (result != Result.SUCCESS) { + return result; + } + + break; + } + case "sdl": { + + Result result = reader.readString(sdl); + segment.get().sdl(sdl.get()); + + if (result != Result.SUCCESS) { + return result; + } + + break; + } + } + } + + return Result.SUCCESS; + } + + public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) { + + Result result; + + if (segment.comment() != null) { + result = writer.writeString(COMMENT, segment.comment()); + if (result != Result.SUCCESS) { + return result; + } + } + + if (segment.sdl() != null) { + result = writer.writeString(SDL, segment.sdl()); + if (result != Result.SUCCESS) { + return result; + } + } + + // Defer writing the length until all other fields of the segment header are written. + // The length is then computed based on the current size of the underlying RowBuffer. + // Because the length field is itself fixed, writing the length can never change the length. + + int length = writer.length(); + result = writer.writeInt32(LENGTH, length); + if (result != Result.SUCCESS) { + return result; + } + + checkState(length == writer.length()); + return Result.SUCCESS; + } } \ No newline at end of file diff --git a/java/exclusions/PropertySchemaConverter.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/PropertySchemaConverter.java similarity index 100% rename from java/exclusions/PropertySchemaConverter.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/PropertySchemaConverter.java diff --git a/java/exclusions/StrictBooleanConverter.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictBooleanConverter.java similarity index 100% rename from java/exclusions/StrictBooleanConverter.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictBooleanConverter.java diff --git a/java/exclusions/StrictIntegerConverter.java b/java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictIntegerConverter.java similarity index 100% rename from java/exclusions/StrictIntegerConverter.java rename to java/exclusions/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictIntegerConverter.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/NullValue.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/NullValue.java index 1109e33..f2b9294 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/NullValue.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/NullValue.java @@ -6,15 +6,15 @@ package com.azure.data.cosmos.serialization.hybridrow; /** * The literal null value. *

- * May be stored hybrid row to indicate the literal null value. Typically this value should - * not be used and the corresponding column should be absent from the row. + * May be stored hybrid row to indicate the literal null value. Typically this value should not be used and the + * corresponding column should be absent from the row. */ public final class NullValue { /** * The default null literal. * This is the same value as default({@link NullValue}). */ - public static final NullValue Default = new NullValue(); + public static final NullValue DEFAULT = new NullValue(); /** * Returns true if this is the same value as {@code other}. 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 72f0dc3..035b0ae 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 @@ -625,7 +625,7 @@ public final class RowBuffer { this.readSparsePrimitiveTypeCode(edit, LayoutTypes.NULL); edit.endOffset(edit.valueOffset()); - return NullValue.Default; + return NullValue.DEFAULT; } public Utf8String readSparsePath(@Nonnull final RowCursor edit) { @@ -843,22 +843,22 @@ public final class RowBuffer { * * @param edit The iterator to advance. * - * + * {@code edit.Path} * On success, the path of the field at the given offset, otherwise * undefined. - * - * + * + * {@code edit.MetaOffset} * If found, the offset to the metadata of the field, otherwise a * location to insert the field. - * - * + * + * {@code edit.cellType} * If found, the layout code of the matching field found, otherwise * undefined. - * - * + * + * {@code edit.ValueOffset} * If found, the offset to the value of the field, otherwise * undefined. - * . + *. * * @return {@code true} if there is another field; {@code false} if there is not. */ @@ -2814,26 +2814,26 @@ public final class RowBuffer { * * @param edit The edit structure to fill in. * - * + * {@code edit.Path} * On success, the path of the field at the given offset, otherwise * undefined. - * - * + * + * {@code edit.MetaOffset} * On success, the offset to the metadata of the field, otherwise a * location to insert the field. - * - * + * + * {@code edit.cellType} * On success, the layout code of the existing field, otherwise * undefined. - * - * + * + * {@code edit.TypeArgs} * On success, the type args of the existing field, otherwise * undefined. - * - * + * + * {@code edit.ValueOffset} * On success, the offset to the value of the field, otherwise * undefined. - * . + *. */ private void readSparseMetadata(@Nonnull final RowCursor edit) { 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 83c849c..5699102 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 @@ -13,8 +13,6 @@ import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8Readable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; @@ -30,7 +28,9 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt64; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt8; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutListReadable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypePrimitive; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt16; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt32; @@ -126,7 +126,7 @@ public final class RowReader { * Read the current field as a fixed length {@code MongoDbObjectId} value * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result ReadMongoDbObjectId(Out value) { // TODO: DANOBLE: Resurrect this method @@ -150,22 +150,6 @@ public final class RowReader { throw new UnsupportedOperationException(); } - /** - * Read the current field as a variable length, UTF-8 encoded string value - * - * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise - */ - public Result ReadString(Out value) { - - Out string = new Out<>(); - Result result = this.readString(string); - value.set((result == Result.SUCCESS) ? string.get().toUtf16() : null); - string.get().release(); - - return result; - } - /** * {@code true} if field has a value--if positioned on a field--undefined otherwise *

@@ -264,64 +248,54 @@ public final class RowReader { */ public boolean read() { - switch (this.state) { + for (; ; ) { - case NONE: { - if (this.cursor.scopeType() instanceof LayoutUDT) { - this.state = States.SCHEMATIZED; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case States.Schematized; - } else { - this.state = States.SPARSE; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case States.Sparse; + switch (this.state) { + + case NONE: { + this.state = this.cursor.scopeType() instanceof LayoutUDT ? States.SCHEMATIZED : States.SPARSE; + break; } - } - case SCHEMATIZED: { + case SCHEMATIZED: { - this.columnIndex++; + this.columnIndex++; - if (this.columnIndex >= this.schematizedCount) { - this.state = States.SPARSE; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case States.Sparse; + if (this.columnIndex >= this.schematizedCount) { + + this.state = States.SPARSE; + + } else { + + checkState(this.cursor.scopeType() instanceof LayoutUDT); + LayoutColumn column = this.columns.get(this.columnIndex); + + if (!this.row.readBit(this.cursor.start(), column.nullBit())) { + break; // to skip schematized values if they aren't present + } + + return true; + } } + case SPARSE: { - checkState(this.cursor.scopeType() instanceof LayoutUDT); - LayoutColumn column = this.columns.get(this.columnIndex); - - if (!this.row.readBit(this.cursor.start(), column.nullBit())) { - // Skip schematized values if they aren't present - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case States.Schematized; + if (!RowCursors.moveNext(this.cursor, this.row)) { + this.state = States.DONE; + break; + } + return true; } - - return true; - } - - case SPARSE: { - - if (!RowCursors.moveNext(this.cursor, this.row)) { - this.state = States.DONE; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case States.Done; + case DONE: { + return false; } - return true; - } - - case DONE: { - return false; } } - - return false; } /** * Read the current field as a variable length, sequence of bytes * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readBinary(Out value) { @@ -336,6 +310,7 @@ public final class RowReader { value.set(null); return Result.TYPE_MISMATCH; } + value.set(this.row.readSparseBinary(this.cursor)); return Result.SUCCESS; @@ -349,7 +324,7 @@ public final class RowReader { * Read the current field as a variable length, sequence of bytes * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readBinaryArray(Out value) { @@ -369,7 +344,7 @@ public final class RowReader { * Read the current field as a {@link Boolean} * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readBoolean(Out value) { @@ -397,7 +372,7 @@ public final class RowReader { * Read the current field as a fixed length {@code DateTime} value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readDateTime(Out value) { @@ -425,7 +400,7 @@ public final class RowReader { * Read the current field as a fixed length decimal value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readDecimal(Out value) { @@ -452,7 +427,7 @@ public final class RowReader { * Read the current field as a fixed length, 128-bit, IEEE-encoded floating point value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readFloat128(Out value) { @@ -479,7 +454,7 @@ public final class RowReader { * Read the current field as a fixed length, 32-bit, IEEE-encoded floating point value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readFloat32(Out value) { @@ -506,7 +481,7 @@ public final class RowReader { * Read the current field as a fixed length, 64-bit, IEEE-encoded floating point value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readFloat64(Out value) { @@ -533,7 +508,7 @@ public final class RowReader { * Read the current field as a fixed length GUID value * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readGuid(Out value) { @@ -561,7 +536,7 @@ public final class RowReader { * Read the current field as a fixed length, 16-bit, signed integer * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readInt16(Out value) { @@ -588,7 +563,7 @@ public final class RowReader { * Read the current field as a fixed length, 32-bit, signed integer * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readInt32(Out value) { @@ -615,7 +590,7 @@ public final class RowReader { * Read the current field as a fixed length, 64-bit, signed integer * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readInt64(Out value) { @@ -642,7 +617,7 @@ public final class RowReader { * Read the current field as a fixed length, 8-bit, signed integer * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readInt8(Out value) { @@ -669,7 +644,7 @@ public final class RowReader { * Read the current field as a null * * @param value On success, receives the value, undefined otherwise. - * @return Success if the read is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readNull(Out value) { @@ -693,7 +668,7 @@ public final class RowReader { } /** - * Read the current field as a nested, structured, sparse scope + * Read the current field as a nested, structured, sparse scope. *

* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples, * set, and maps. @@ -717,9 +692,7 @@ public final class RowReader { * Read the current field as a nested, structured, sparse scope *

* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples, - * set, and maps. - *

- * Nested child readers are independent of their parent. + * set, and maps. Nested child readers are independent of their parent. */ public @Nonnull RowReader readScope() { RowCursor newScope = this.row.sparseIteratorReadScope(this.cursor, true); @@ -727,12 +700,28 @@ public final class RowReader { } /** - * Read the current field as a variable length, UTF-8 encoded, string value + * Read the current field as a variable length, UTF-8 encoded string value * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ - public Result readString(Out value) { + public Result readString(Out value) { + + Out string = new Out<>(); + Result result = this.readUtf8String(string); + value.set((result == Result.SUCCESS) ? string.get().toUtf16() : null); + string.get().release(); + + return result; + } + + /** + * Read the current field as a variable length, UTF-8 encoded, string value. + * + * @param value On success, receives the value, undefined otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. + */ + public Result readUtf8String(Out value) { switch (this.state) { @@ -754,10 +743,10 @@ public final class RowReader { } /** - * Read the current field as a fixed length, 16-bit, unsigned integer + * Read the current field as a fixed length, 16-bit, unsigned integer. * - * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @param value On success, receives the value, undefined otherwise. + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readUInt16(Out value) { @@ -784,7 +773,7 @@ public final class RowReader { * Read the current field as a fixed length, 32-bit, unsigned integer * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readUInt32(Out value) { @@ -812,7 +801,7 @@ public final class RowReader { * Read the current field as a fixed length, 64-bit, unsigned integer * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readUInt64(Out value) { @@ -839,7 +828,7 @@ public final class RowReader { * Read the current field as a fixed length, 8-bit, unsigned integer * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readUInt8(Out value) { @@ -866,7 +855,7 @@ public final class RowReader { * Read the current field as a fixed length {@link UnixDateTime} value * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readUnixDateTime(Out value) { @@ -893,7 +882,7 @@ public final class RowReader { * Read the current field as a variable length, 7-bit encoded, signed integer * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readVarInt(Out value) { @@ -920,7 +909,7 @@ public final class RowReader { * Read the current field as a variable length, 7-bit encoded, unsigned integer * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ public Result readVarUInt(Out value) { @@ -1012,14 +1001,14 @@ public final class RowReader { * Reads a generic schematized field value via the scope's layout * * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ private Result readPrimitiveValue(Out value) { final LayoutColumn column = this.columns.get(this.columnIndex); final LayoutType type = this.columns.get(this.columnIndex).type(); - if (!(type instanceof LayoutType)) { + if (!(type instanceof LayoutTypePrimitive)) { value.set(null); return Result.TYPE_MISMATCH; } @@ -1028,42 +1017,9 @@ public final class RowReader { switch (storage) { case FIXED: - return type.>typeAs().readFixed(this.row, this.cursor, column, value); + return type.>typeAs().readFixed(this.row, this.cursor, column, value); case VARIABLE: - return type.>typeAs().readVariable(this.row, this.cursor, column, value); - default: - assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); - value.set(null); - return Result.FAILURE; - } - } - - /** - * Reads a generic schematized field value via the scope's layout - * - * @param value On success, receives the value, undefined otherwise - * @return {@link Result#SUCCESS} if the read is successful; an error {@link Result} otherwise - */ - private Result readPrimitiveValue(Out value) { - - LayoutColumn column = this.columns.get(this.columnIndex); - LayoutType type = this.columns.get(this.columnIndex).type(); - - if (!(type instanceof LayoutUtf8Readable)) { - value.set(null); - return Result.TYPE_MISMATCH; - } - - StorageKind storage = column == null ? StorageKind.NONE : column.storage(); - - switch (storage) { - - case FIXED: - return type.typeAs().readFixed(this.row, this.cursor, column, value); - - case VARIABLE: - return type.typeAs().readVariable(this.row, this.cursor, column, value); - + return type.>typeAs().readVariable(this.row, this.cursor, column, value); default: assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); value.set(null); @@ -1071,19 +1027,52 @@ public final class RowReader { } } +// /** +// * Reads a generic schematized field value via the scope's layout +// * +// * @param value On success, receives the value, undefined otherwise +// * @return {@link Result#SUCCESS} if the read is successful; an error {@link Result} otherwise +// */ +// private Result readPrimitiveValue(Out value) { +// +// LayoutColumn column = this.columns.get(this.columnIndex); +// LayoutType type = this.columns.get(this.columnIndex).type(); +// +// if (!(type instanceof LayoutUtf8Readable)) { +// value.set(null); +// return Result.TYPE_MISMATCH; +// } +// +// StorageKind storage = column == null ? StorageKind.NONE : column.storage(); +// +// switch (storage) { +// +// case FIXED: +// return type.typeAs().readFixed(this.row, this.cursor, column, value); +// +// case VARIABLE: +// return type.typeAs().readVariable(this.row, this.cursor, column, value); +// +// default: +// assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); +// value.set(null); +// return Result.FAILURE; +// } +// } +// /** * Reads a generic schematized field value via the scope's layout * * @param The sub-element type of the field * @param value On success, receives the value, undefined otherwise - * @return Success if the read is successful, an error code otherwise + * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise. */ - private Result readPrimitiveValue(Out> value) { + private Result readPrimitiveValueList(Out> value) { LayoutColumn column = this.columns.get(this.columnIndex); LayoutType type = this.columns.get(this.columnIndex).type(); - if (!(type instanceof LayoutSpanReadable)) { + if (!(type instanceof LayoutListReadable)) { value.set(null); return Result.TYPE_MISMATCH; } @@ -1093,10 +1082,10 @@ public final class RowReader { switch (storage) { case FIXED: - return type.>typeAs().readFixed(this.row, this.cursor, column, value); + return type.>typeAs().readFixedList(this.row, this.cursor, column, value); case VARIABLE: - return type.>typeAs().readVariable(this.row, this.cursor, column, value); + return type.>typeAs().readVariableList(this.row, this.cursor, column, value); default: assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReaderExtensions.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReaderExtensions.java index 01ea6dc..395fe76 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReaderExtensions.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReaderExtensions.java @@ -14,7 +14,7 @@ public final class RowReaderExtensions { /** * Read the current field as a nested, structured, sparse scope containing a linear collection of zero or more * items. - * The type of the items within the collection. + * @param The type of the items within the collection. * * @param reader A forward-only cursor for reading the collection. * @param deserializer A function that reads one item from the collection. diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java index c2197a8..3a511d9 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java @@ -16,10 +16,11 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutListWritable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanWritable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypePrimitive; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedMap; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT; @@ -30,10 +31,12 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList; import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions; import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import java.math.BigDecimal; -import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.util.UUID; +import java.util.function.Consumer; public final class RowWriter { @@ -80,11 +83,10 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result WriteBinary(UtfAnyString path, byte[] value) { - return this.writePrimitive(path, value, LayoutTypes.BINARY, - (ref RowWriter w, byte[] v) -> w.row.writeSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.WriteBinary(path, Unpooled.wrappedBuffer(value)); } /** @@ -92,24 +94,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result WriteBinary(UtfAnyString path, ByteBuf value) { - return this.writePrimitive(path, value, LayoutTypes.BINARY, - (ref RowWriter w, ByteBuf v) -> w.row.writeSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); - } - - /** - * Write a field as a variable length, sequence of bytes. - * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. - */ - public Result WriteBinary(UtfAnyString path, ReadOnlySequence value) { - return this.writePrimitive(path, value, LayoutTypes.BINARY, - (ref RowWriter w, ReadOnlySequence v) -> w.row.writeSparseBinary(ref w.cursor, v, - UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.BINARY, (ByteBuf v) -> + this.row.writeSparseBinary(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -117,21 +106,21 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result WriteBoolean(UtfAnyString path, boolean value) { - return this.writePrimitive(path, value, LayoutTypes.BOOLEAN, - (ref RowWriter w, boolean v) -> w.row.writeSparseBool(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.BOOLEAN, (Boolean v) -> + this.row.writeSparseBoolean(this.cursor, value, UpdateOptions.UPSERT)); } /** * Write an entire row in a streaming left-to-right way. - * The type of the context value to pass to . * - * @param row The row to write. - * @param context A context value to pass to . - * @param func A function to write the entire row. - * @return Success if the write is successful, an error code otherwise. + * @param The type of the context value to pass to {@code func}. + * @param row The row to write. + * @param context A context value to pass to {@code func}. + * @param func A function to write the entire row. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public static Result WriteBuffer( Reference row, TContext context, WriterFunc func) { @@ -152,35 +141,27 @@ public final class RowWriter { } /** - * Write a field as a fixed length {@link DateTime} value. + * Write a field as a fixed length {@code DateTime} value. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteDateTime(UtfAnyString path, LocalDateTime value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.DATE_TIME, - (ref RowWriter w, LocalDateTime v) -> w.row.writeSparseDateTime(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeDateTime(UtfAnyString path, OffsetDateTime value) { + return this.writePrimitive(path, value, LayoutTypes.DATE_TIME, (OffsetDateTime v) -> + this.row.writeSparseDateTime(this.cursor, v, UpdateOptions.UPSERT)); } /** - * Write a field as a fixed length {@link decimal} value. + * Write a field as a fixed length {@code Decimal} value. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteDecimal(UtfAnyString path, BigDecimal value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.DECIMAL, - (ref RowWriter w, BigDecimal v) -> w.row.writeSparseDecimal(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeDecimal(UtfAnyString path, BigDecimal value) { + return this.writePrimitive(path, value, LayoutTypes.DECIMAL, (BigDecimal v) -> + this.row.writeSparseDecimal(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -188,15 +169,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteFloat128(UtfAnyString path, Float128 value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.FLOAT_128, - (ref RowWriter w, Float128 v) -> w.row.writeSparseFloat128(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeFloat128(UtfAnyString path, Float128 value) { + return this.writePrimitive(path, value, LayoutTypes.FLOAT_128, (Float128 v) -> + this.row.writeSparseFloat128(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -204,15 +181,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteFloat32(UtfAnyString path, float value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.FLOAT_32, - (ref RowWriter w, float v) -> w.row.writeSparseFloat32(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeFloat32(UtfAnyString path, float value) { + return this.writePrimitive(path, value, LayoutTypes.FLOAT_32, (Float v) -> + this.row.writeSparseFloat32(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -220,31 +193,23 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteFloat64(UtfAnyString path, double value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.FLOAT_64, - (ref RowWriter w, double v) -> w.row.writeSparseFloat64(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeFloat64(UtfAnyString path, double value) { + return this.writePrimitive(path, value, LayoutTypes.FLOAT_64, (Double v) -> + this.row.writeSparseFloat64(this.cursor, v, UpdateOptions.UPSERT)); } /** - * Write a field as a fixed length {@link Guid} value. + * Write a field as a fixed length {@code Guid} value. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteGuid(UtfAnyString path, UUID value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.GUID, - (ref RowWriter w, UUID v) -> w.row.writeSparseGuid(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeGuid(UtfAnyString path, UUID value) { + return this.writePrimitive(path, value, LayoutTypes.GUID, (UUID v) -> + this.row.writeSparseGuid(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -252,31 +217,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteInt16(UtfAnyString path, short value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.INT_16, - (ref RowWriter w, short v) -> w.row.writeSparseInt16(ref w.cursor, v, UpdateOptions.UPSERT)); - } - - /** - * Write a field as a fixed length, 32-bit, signed integer. - * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. - */ - public Result writeInt32(UtfAnyString path, int value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.INT_32, - (ref RowWriter w, int v) -> w.row.writeSparseInt32(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeInt16(UtfAnyString path, short value) { + return this.writePrimitive(path, value, LayoutTypes.INT_16, (Short v) -> + this.row.writeSparseInt16(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -284,15 +229,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteInt64(UtfAnyString path, long value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.INT_64, - (ref RowWriter w, long v) -> w.row.writeSparseInt64(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeInt64(UtfAnyString path, long value) { + return this.writePrimitive(path, value, LayoutTypes.INT_64, (Long v) -> + this.row.writeSparseInt64(this.cursor, v, UpdateOptions.UPSERT)); } /** @@ -300,15 +241,22 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result WriteInt8(UtfAnyString path, byte value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.INT_8, - (ref RowWriter w, byte v) -> w.row.writeSparseInt8(ref w.cursor, v, UpdateOptions.UPSERT)); + public Result writeInt8(UtfAnyString path, byte value) { + return this.writePrimitive(path, value, LayoutTypes.INT_8, (Byte v) -> + this.row.writeSparseInt8(this.cursor, v, UpdateOptions.UPSERT)); + } + + /** + * Write a field as a {@code null}. + * + * @param path The scope-relative path of the field to write. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. + */ + public Result writeNull(UtfAnyString path) { + return this.writePrimitive(path, NullValue.DEFAULT, LayoutTypes.NULL, (NullValue v) -> + this.row.writeSparseNull(this.cursor, v, UpdateOptions.UPSERT)); } // TODO: DANOBLE: Resurrect this method @@ -317,27 +265,18 @@ public final class RowWriter { // * // * @param path The scope-relative path of the field to write. // * @param value The value to write. - // * @return Success if the write is successful, an error code otherwise. + // * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. // */ // public Result WriteMongoDbObjectId(UtfAnyString path, MongoDbObjectId value) { // throw new UnsupportedOperationException(); // // return this.writePrimitive(path, value, LayoutTypes.MongoDbObjectId, (ref RowWriter w, MongoDbObjectId v) -> w.row.writeSparseMongoDbObjectId(ref w.cursor, v, UpdateOptions.UPSERT)); // } - /** - * Write a field as a {@link t:null}. - * - * @param path The scope-relative path of the field to write. - * @return Success if the write is successful, an error code otherwise. - */ - public Result WriteNull(UtfAnyString path) { - return this.writePrimitive(path, NullValue.Default, LayoutTypes.NULL, - (ref RowWriter w, NullValue v) -> w.row.writeSparseNull(ref w.cursor, v, UpdateOptions.UPSERT)); - } + public Result WriteScope( + UtfAnyString path, TypeArgument typeArg, TContext context, WriterFunc func) { - public Result WriteScope(UtfAnyString path, TypeArgument typeArg, TContext context, - WriterFunc func) { LayoutType type = typeArg.type(); + Result result = this.prepareSparseWrite(path, typeArg); if (result != Result.SUCCESS) { return result; @@ -543,16 +482,15 @@ public final class RowWriter { } /** - * Write a field as a variable length, UTF8 encoded, string value. + * Write a field as a fixed length, 32-bit, signed integer. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - public Result writeString(UtfAnyString path, String value) { - return this.writePrimitive(path, value, LayoutTypes.UTF_8, - (ref RowWriter w, String v) -> w.row.writeSparseString(ref w.cursor, Utf8Span.TranscodeUtf16(v), - UpdateOptions.UPSERT)); + public Result writeInt32(UtfAnyString path, int value) { + return this.writePrimitive(path, value, LayoutTypes.INT_32, (RowWriter writer, int v) -> + writer.row.writeSparseInt32(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -560,15 +498,30 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. + */ + public Result writeString(UtfAnyString path, String value) { + // TODO: DANOBLE: RowBuffer should support writing String values directly (without conversion to Utf8String) + Utf8String string = Utf8String.transcodeUtf16(value); + assert string != null; + try { + return this.writePrimitive(path, value, LayoutTypes.UTF_8, (RowWriter writer, String v) -> + writer.row.writeSparseString(writer.cursor, string, UpdateOptions.UPSERT)); + } finally { + string.release(); + } + } + + /** + * Write a field as a variable length, UTF8 encoded, string value. + * + * @param path The scope-relative path of the field to write. + * @param value The value to write. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result writeString(UtfAnyString path, Utf8String value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.UTF_8, - (ref RowWriter w, Utf8Span v) -> w.row.writeSparseString(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UTF_8, (RowWriter writer, Utf8String v) -> + writer.row.writeSparseString(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -576,20 +529,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteUInt16(UtfAnyString path, ushort value) public Result writeUInt16(UtfAnyString path, short value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt16, (ref RowWriter w, ushort v) => w - // .row.writeSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert)); - return this.writePrimitive(path, value, LayoutTypes.UINT_16, - (ref RowWriter w, short v) -> w.row.writeSparseUInt16(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UINT_16, (RowWriter writer, short v) -> + writer.row.writeSparseUInt16(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -597,20 +541,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteUInt32(UtfAnyString path, uint value) public Result writeUInt32(UtfAnyString path, int value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt32, (ref RowWriter w, uint v) => w - // .row.writeSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert)); - return this.writePrimitive(path, value, LayoutTypes.UINT_32, - (ref RowWriter w, int v) -> w.row.writeSparseUInt32(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UINT_32, (RowWriter writer, int v) -> + writer.row.writeSparseUInt32(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -618,20 +553,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteUInt64(UtfAnyString path, ulong value) public Result writeUInt64(UtfAnyString path, long value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt64, (ref RowWriter w, ulong v) => w - // .row.writeSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert)); - return this.writePrimitive(path, value, LayoutTypes.UINT_64, - (ref RowWriter w, long v) -> w.row.writeSparseUInt64(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UINT_64, (RowWriter writer, long v) -> + writer.row.writeSparseUInt64(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -639,20 +565,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteUInt8(UtfAnyString path, byte value) public Result writeUInt8(UtfAnyString path, byte value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt8, (ref RowWriter w, byte v) => w.row - // .writeSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert)); - return this.writePrimitive(path, value, LayoutTypes.UINT_8, - (ref RowWriter w, byte v) -> w.row.writeSparseUInt8(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UINT_8, (RowWriter writer, byte v) -> + writer.row.writeSparseUInt8(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -660,16 +577,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result writeUnixDateTime(UtfAnyString path, UnixDateTime value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.UNIX_DATE_TIME, - (ref RowWriter w, UnixDateTime v) -> w.row.writeSparseUnixDateTime(ref w.cursor, v, - UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.UNIX_DATE_TIME, (RowWriter writer, UnixDateTime v) -> + writer.row.writeSparseUnixDateTime(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -677,15 +589,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ public Result writeVarInt(UtfAnyString path, long value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.writePrimitive(path, value, LayoutTypes.VAR_INT, - (ref RowWriter w, long v) -> w.row.writeSparseVarInt(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.VAR_INT, (RowWriter writer, long v) -> + writer.row.writeSparseVarInt(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -693,20 +601,11 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteVarUInt(UtfAnyString path, ulong value) public Result writeVarUInt(UtfAnyString path, long value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.VarUInt, (ref RowWriter w, ulong v) => w - // .row.writeSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert)); - return this.writePrimitive(path, value, LayoutTypes.VAR_UINT, - (ref RowWriter w, long v) -> w.row.writeSparseVarUInt(ref w.cursor, v, UpdateOptions.UPSERT)); + return this.writePrimitive(path, value, LayoutTypes.VAR_UINT, (RowWriter writer, long v) -> + writer.row.writeSparseVarUInt(writer.cursor, v, UpdateOptions.UPSERT)); } /** @@ -740,15 +639,57 @@ public final class RowWriter { /** * Helper for writing a primitive value. - * The type of layout type. * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @param type The layout type. - * @param sparse The {@link RowBuffer} access method for . - * @return Success if the write is successful, an error code otherwise. + * @param The type of layout type. + * @param path The scope-relative path of the field to write. + * @param value The value to write. + * @param type The layout type. + * @param sparse The {@link RowBuffer} access method for {@code type}. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - private & LayoutUtf8Writable> Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) { + private & LayoutUtf8Writable> + Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) { + + Result result = Result.NOT_FOUND; + + if (this.cursor.scopeType() instanceof LayoutUDT) { + result = this.writeSchematizedValue(path, value); + } + + if (result == Result.NOT_FOUND) { + // Write sparse value. + result = this.prepareSparseWrite(path, type.typeArg()); + if (result != Result.SUCCESS) { + return result; + } + + Reference tempReference_this = + new Reference(this); + // TODO: C# TO JAVA CONVERTER: The following line could not be converted: + sparse(ref this, value) + this = tempReference_this.get(); + Reference tempReference_row = + new Reference(this.row); + RowCursors.moveNext(this.cursor, + tempReference_row); + this.row = tempReference_row.get(); + } + + return result; + } + + /** + * Helper for writing a primitive value. + * + * @param The type of layout type. + * @param The sub-element type of the field. + * @param path The scope-relative path of the field to write. + * @param value The value to write. + * @param type The layout type. + * @param sparse The {@link RowBuffer} access method for {@code type}. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. + */ + private & LayoutListWritable, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySpan value, TLayoutType type, AccessReadOnlySpanMethod sparse) { Result result = Result.NOT_FOUND; if (this.cursor.scopeType() instanceof LayoutUDT) { result = this.writeSchematizedValue(path, value); @@ -778,117 +719,33 @@ public final class RowWriter { /** * Helper for writing a primitive value. - * The type of layout type. - * The sub-element type of the field. * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @param type The layout type. - * @param sparse The {@link RowBuffer} access method for . - * @return Success if the write is successful, an error code otherwise. + * @param The type of the primitive value. + * @param path The scope-relative path of the field to write. + * @param value The value to write. + * @param type The layout type. + * @param sparse The {@link RowBuffer} access method for {@code type}. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ - private & LayoutSpanWritable, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySpan value, TLayoutType type, AccessReadOnlySpanMethod sparse) { + private Result writePrimitive( + UtfAnyString path, TValue value, LayoutTypePrimitive type, Consumer sparse) { + Result result = Result.NOT_FOUND; + if (this.cursor.scopeType() instanceof LayoutUDT) { result = this.writeSchematizedValue(path, value); } if (result == Result.NOT_FOUND) { - // Write sparse value. + result = this.prepareSparseWrite(path, type.typeArg()); + if (result != Result.SUCCESS) { return result; } - Reference tempReference_this = - new Reference(this); - // TODO: C# TO JAVA CONVERTER: The following line could not be converted: - sparse(ref this, value) - this = tempReference_this.get(); - Reference tempReference_row = - new Reference(this.row); - RowCursors.moveNext(this.cursor, - tempReference_row); - this.row = tempReference_row.get(); - } - - return result; - } - - /** - * Helper for writing a primitive value. - * The type of layout type. - * The sub-element type of the field. - * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @param type The layout type. - * @param sparse The {@link RowBuffer} access method for . - * @return Success if the write is successful, an error code otherwise. - */ - private & ILayoutSequenceWritable, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySequence value, TLayoutType type, AccessMethod> sparse) { - Result result = Result.NOT_FOUND; - if (this.cursor.scopeType() instanceof LayoutUDT) { - result = this.writeSchematizedValue(path, value); - } - - if (result == Result.NOT_FOUND) { - // Write sparse value. - result = this.prepareSparseWrite(path, type.typeArg()); - if (result != Result.SUCCESS) { - return result; - } - - Reference tempReference_this = - new Reference(this); - // TODO: C# TO JAVA CONVERTER: The following line could not be converted: - sparse(ref this, value) - this = tempReference_this.get(); - Reference tempReference_row = - new Reference(this.row); - RowCursors.moveNext(this.cursor, - tempReference_row); - this.row = tempReference_row.get(); - } - - return result; - } - - /** - * Helper for writing a primitive value. - * The type of the primitive value. - * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @param type The layout type. - * @param sparse The {@link RowBuffer} access method for . - * @return Success if the write is successful, an error code otherwise. - */ - private Result writePrimitive(UtfAnyString path, TValue value, LayoutType type, - AccessMethod sparse) { - Result result = Result.NOT_FOUND; - if (this.cursor.scopeType() instanceof LayoutUDT) { - result = this.writeSchematizedValue(path, value); - } - - if (result == Result.NOT_FOUND) { - // Write sparse value. - - result = this.prepareSparseWrite(path, type.typeArg()); - if (result != Result.SUCCESS) { - return result; - } - - Reference tempReference_this = - new Reference(this); - // TODO: C# TO JAVA CONVERTER: The following line could not be converted: - sparse(ref this, value) - this = tempReference_this.get(); - Reference tempReference_row = - new Reference(this.row); - RowCursors.moveNext(this.cursor, - tempReference_row); - this.row = tempReference_row.get(); + sparse.accept(this, value); + RowCursors.moveNext(this.cursor, this.row); } return result; @@ -896,11 +753,11 @@ public final class RowWriter { /** * Write a generic schematized field value via the scope's layout. - * The expected type of the field. * - * @param path The scope-relative path of the field to write. - * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @param The expected type of the field. + * @param path The scope-relative path of the field to write. + * @param value The value to write. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ private Result writeSchematizedValue(UtfAnyString path, TValue value) { LayoutColumn col; @@ -943,7 +800,7 @@ public final class RowWriter { * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ private Result writeSchematizedValue(UtfAnyString path, Utf8String value) { LayoutColumn col; @@ -987,11 +844,11 @@ public final class RowWriter { /** * Write a generic schematized field value via the scope's layout. - * The sub-element type of the field. + * @param The sub-element type of the field. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ private Result writeSchematizedValue(UtfAnyString path, ReadOnlySpan value) { LayoutColumn col; @@ -1027,11 +884,11 @@ public final class RowWriter { /** * Write a generic schematized field value via the scope's layout. - * The sub-element type of the field. + * @param The sub-element type of the field. * * @param path The scope-relative path of the field to write. * @param value The value to write. - * @return Success if the write is successful, an error code otherwise. + * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise. */ private Result writeSchematizedValue(UtfAnyString path, ReadOnlySequence value) { LayoutColumn col; @@ -1066,23 +923,22 @@ public final class RowWriter { } @FunctionalInterface - private interface AccessMethod { - void invoke(Reference writer, TValue value); + private interface AccessMethod extends Consumer { } @FunctionalInterface private interface AccessReadOnlySpanMethod { - void invoke(Reference writer, ReadOnlySpan value); + void invoke(RowWriter writer, ReadOnlySpan value); } @FunctionalInterface private interface AccessUtf8SpanMethod { - void invoke(Reference writer, Utf8String value); + void invoke(RowWriter writer, Utf8String value); } /** * A function to write content into a {@link RowBuffer}. - * The type of the context value passed by the caller. + * @param The type of the context value passed by the caller. * * @param writer A forward-only cursor for writing content. * @param typeArg The type of the current scope. @@ -1091,6 +947,6 @@ public final class RowWriter { */ @FunctionalInterface public interface WriterFunc { - Result invoke(Reference writer, TypeArgument typeArg, TContext context); + Result invoke(RowWriter writer, TypeArgument typeArg, TContext context); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Segment.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/Segment.java similarity index 88% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Segment.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/Segment.java index 299da82..106c54f 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/Segment.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/Segment.java @@ -1,43 +1,43 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.recordio; - -public final class Segment { - - private String comment; - private int length; - private String sdl; - - public Segment(String comment, String sdl) { - this.comment = comment; - this.sdl = sdl; - this.length = 0; - } - - public String comment() { - return this.comment; - } - - public Segment comment(String value) { - this.comment = value; - return this; - } - - public int length() { - return this.length; - } - - public Segment length(int value) { - this.length = value; - return this; - } - public String sdl() { - return this.sdl; - } - - public Segment sdl(String value) { - this.sdl = value; - return this; - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.io; + +public final class Segment { + + private String comment; + private int length; + private String sdl; + + public Segment(String comment, String sdl) { + this.comment = comment; + this.sdl = sdl; + this.length = 0; + } + + public String comment() { + return this.comment; + } + + public Segment comment(String value) { + this.comment = value; + return this; + } + + public int length() { + return this.length; + } + + public Segment length(int value) { + this.length = value; + return this; + } + public String sdl() { + return this.sdl; + } + + public Segment sdl(String value) { + this.sdl = value; + return this; + } } \ No newline at end of file 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 e499a13..298672d 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 @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; public final class LayoutBinary extends LayoutTypePrimitive { // implements - // LayoutSpanWritable, - // LayoutSpanReadable, + // LayoutListWritable, + // LayoutListReadable, // ILayoutSequenceWritable { public LayoutBinary() { 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 1eb44e8..4d692f0 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 @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -public final class LayoutBoolean extends LayoutType { +public final class LayoutBoolean extends LayoutTypePrimitive implements ILayoutType { public LayoutBoolean(boolean value) { super(value ? LayoutCode.BOOLEAN : LayoutCode.BOOLEAN_FALSE, 0); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListReadable.java similarity index 61% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListReadable.java index d2f8173..bff1521 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListReadable.java @@ -15,11 +15,11 @@ import java.util.List; * * @param The sub-element type to be written */ -public interface LayoutSpanReadable extends ILayoutType { +public interface LayoutListReadable extends ILayoutType { - Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); + Result readFixedList(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); - Result readSparse(RowBuffer buffer, RowCursor scope, Out> value); + Result readSparseList(RowBuffer buffer, RowCursor scope, Out> value); - Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); + Result readVariableList(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListWritable.java similarity index 54% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListWritable.java index 4595634..e95fead 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutListWritable.java @@ -14,13 +14,13 @@ import java.util.List; * * @param The sub-element type to be written */ -public interface LayoutSpanWritable extends ILayoutType { +public interface LayoutListWritable extends ILayoutType { - Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); + Result writeFixedList(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); - Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value); + Result writeSparseList(RowBuffer buffer, RowCursor edit, TElement value); - Result writeSparse(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options); + Result writeSparseList(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options); - Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); + Result writeVariableList(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java index 5b39df1..cd20afa 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutNull extends LayoutType { +public final class LayoutNull extends LayoutTypePrimitive implements ILayoutType { public LayoutNull() { super(LayoutCode.NULL, 0); @@ -36,7 +36,7 @@ public final class LayoutNull extends LayoutType { @Nonnull public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); - value.set(NullValue.Default); + value.set(NullValue.DEFAULT); if (!buffer.readBit(scope.start(), column.nullBit())) { return Result.NOT_FOUND; } 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 3f1eb47..620008e 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 @@ -343,7 +343,7 @@ public abstract class LayoutType /*implements ILayoutType*/ { * The physical layout type of the field cast to the specified type. */ @SuppressWarnings("unchecked") - public final T typeAs() { + public final T typeAs() { return (T)this; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java index 4d16647..b7a6797 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -public abstract class LayoutTypePrimitive extends LayoutType { +public abstract class LayoutTypePrimitive extends LayoutType implements ILayoutType { /** * Initializes a new instance of the {@link LayoutType} class. * 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 ec27780..2c0e9bb 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 @@ -37,9 +37,15 @@ public final class LayoutUtf8 extends LayoutTypePrimitive implements Lay @Nonnull final LayoutColumn column, @Nonnull final Out value) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkNotNull(value, "expected non-null value"); + Out span = new Out<>(); Result result = this.readFixedSpan(buffer, scope, column, span); value.set(result == Result.SUCCESS ? span.get().toUtf16() : null); + return result; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8Readable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8Readable.java index 9c44447..0d8943b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8Readable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8Readable.java @@ -12,7 +12,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; /** - * An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}. + * An optional interface that indicates a {@link LayoutType{T}} can also be read as a {@link Utf8String}. */ public interface LayoutUtf8Readable extends ILayoutType { diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BenchmarkSuiteBase.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BenchmarkSuiteBase.java index 9afcf03..da47283 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BenchmarkSuiteBase.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BenchmarkSuiteBase.java @@ -15,7 +15,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolverNamespace; import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream; -import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; +import com.azure.data.cosmos.serialization.hybridrow.io.Segment; import java.util.ArrayList; import java.util.HashMap; 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 eb7eea7..8fcf0d5 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 @@ -80,7 +80,7 @@ public final class JsonModelRowGenerator { new Reference(this.row); // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not // converted by C# to Java Converter: - Result tempVar = RowWriter.WriteBuffer(tempReference_row, value, (ref RowWriter writer, TypeArgument typeArg, + Result tempVar = RowWriter.WriteBuffer(tempReference_row, value, (RowWriter RowWriter writer, TypeArgument typeArg, HashMap dict) -> { for ((Utf8String propPath,Object propValue) :dict) @@ -113,7 +113,7 @@ public final class JsonModelRowGenerator { private static Result JsonModelSwitch(Reference writer, Utf8String path, Object value) { switch (value) { case null: - return writer.get().WriteNull(path); + return writer.get().writeNull(path); // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: //ORIGINAL LINE: case bool x: case @@ -123,12 +123,12 @@ public final class JsonModelRowGenerator { //ORIGINAL LINE: case long x: case long x: - return writer.get().WriteInt64(path, x); + return writer.get().writeInt64(path, x); // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: //ORIGINAL LINE: case double x: case double x: - return writer.get().WriteFloat64(path, x); + return writer.get().writeFloat64(path, x); // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: //ORIGINAL LINE: case string x: case String @@ -156,7 +156,7 @@ public final class JsonModelRowGenerator { // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these // are not converted by C# to Java Converter: return writer.get().WriteScope(path, new TypeArgument(LayoutType.Object), x, - (ref RowWriter writer2, TypeArgument typeArg, HashMap dict) -> + (RowWriter RowWriter writer2, TypeArgument typeArg, HashMap dict) -> { for ((Utf8String propPath,Object propValue) :dict) { @@ -172,7 +172,7 @@ public final class JsonModelRowGenerator { //ORIGINAL LINE: case List x: case ArrayList < Object > x: // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter: - return writer.get().WriteScope(path, new TypeArgument(LayoutType.Array), x, (ref RowWriter writer2, TypeArgument typeArg, ArrayList list) -> + return writer.get().WriteScope(path, new TypeArgument(LayoutType.Array), x, (RowWriter RowWriter writer2, TypeArgument typeArg, ArrayList list) -> { for (Object elm : list) { Reference tempReference_writer2 = new Reference(writer2); diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/ReaderBenchmark.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/ReaderBenchmark.java index de12f84..e54a33e 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/ReaderBenchmark.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/ReaderBenchmark.java @@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream; -import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; +import com.azure.data.cosmos.serialization.hybridrow.io.Segment; import java.io.Closeable; import java.io.File; diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CrossVersioningUnitTests.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CrossVersioningUnitTests.java index 223ed69..f9dd634 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CrossVersioningUnitTests.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CrossVersioningUnitTests.java @@ -5,7 +5,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit; import Newtonsoft.Json.*; import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.Float128; import com.azure.data.cosmos.serialization.hybridrow.NullValue; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; @@ -80,7 +79,7 @@ public final class CrossVersioningUnitTests { d.LayoutCodeSwitch("array_t", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("tuple", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple>", value: - Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) + Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86))) d.LayoutCodeSwitch("tuple", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("set_t", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t>", value:new byte[][] @@ -276,7 +275,7 @@ public final class CrossVersioningUnitTests { d.LayoutCodeSwitch("array_t", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("tuple", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple>", value: - Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) + Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86))) d.LayoutCodeSwitch("tuple", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("set_t", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t>", value:new byte[][] @@ -443,7 +442,7 @@ public final class CrossVersioningUnitTests { d.LayoutCodeSwitch("array_t", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("tuple", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple>", value: - Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) + Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86))) d.LayoutCodeSwitch("tuple", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("set_t", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t>", value:new byte[][] diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/LayoutCompilerUnitTests.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/LayoutCompilerUnitTests.java index b701435..b3affa9 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/LayoutCompilerUnitTests.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/LayoutCompilerUnitTests.java @@ -71,7 +71,7 @@ public class LayoutCompilerUnitTests { RoundTripFixed.Expected tempVar = new RoundTripFixed.Expected(); tempVar.TypeName = "null"; tempVar.Default = new NullValue(); - tempVar.Value = NullValue.Default; + tempVar.Value = NullValue.DEFAULT; RoundTripFixed.Expected tempVar2 = new RoundTripFixed.Expected(); tempVar2.TypeName = "bool"; tempVar2.Default = false; @@ -1858,7 +1858,7 @@ private final static class RoundTripSparseArray extends TestActionDispatcher tempReference_field3 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field3, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field3, NullValue.DEFAULT); field = tempReference_field3.get(); ResultAssert.IsSuccess(r, tag); Reference tempReference_field4 = @@ -2049,7 +2049,7 @@ private final static class RoundTripSparseObject extends TestActionDispatcher tempReference_field4 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field4, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field4, NullValue.DEFAULT); field = tempReference_field4.get(); ResultAssert.IsSuccess(r, "Json: {0}", expected.Json); Reference tempReference_field5 = @@ -2187,7 +2187,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch } else { Reference tempReference_nestedField2 = new Reference(nestedField); - r = LayoutType.Null.writeSparse(row, tempReference_nestedField2, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_nestedField2, NullValue.DEFAULT); nestedField = tempReference_nestedField2.get(); ResultAssert.IsSuccess(r, tag); } @@ -2260,7 +2260,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch // Overwrite the nested field. Reference tempReference_nestedField4 = new Reference(nestedField); - r = LayoutType.Null.writeSparse(row, tempReference_nestedField4, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_nestedField4, NullValue.DEFAULT); nestedField = tempReference_nestedField4.get(); ResultAssert.IsSuccess(r, tag); @@ -2381,7 +2381,7 @@ private final static class RoundTripSparseObjectNested extends TestActionDispatc } else { Reference tempReference_field2 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT); field = tempReference_field2.get(); ResultAssert.IsSuccess(r, tag); } @@ -2517,7 +2517,7 @@ private final static class RoundTripSparseOrdering extends TestActionDispatcher< } else { Reference tempReference_field2 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT); field = tempReference_field2.get(); ResultAssert.IsSuccess(r, "Json: {0}", json); Out tempOut_value3 = new Out(); @@ -2835,7 +2835,7 @@ private final static class RoundTripSparseSet extends TestActionDispatcher tempReference_field9 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field9, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field9, NullValue.DEFAULT); field = tempReference_field9.get(); ResultAssert.IsSuccess(r, tag); Reference tempReference_field10 = new Reference(field); @@ -2982,7 +2982,7 @@ private final static class RoundTripSparseSimple extends TestActionDispatcher tempReference_field2 = new Reference(field); - r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); + r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT); field = tempReference_field2.get(); ResultAssert.IsSuccess(r, "Json: {0}", expected.Json); // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java index 185f6e9..82102c5 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java @@ -11,7 +11,7 @@ import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream; -import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; +import com.azure.data.cosmos.serialization.hybridrow.io.Segment; import com.azure.data.cosmos.serialization.hybridrow.unit.customerschema.Address; import java.nio.file.Files; 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 cfce084..bbfa0fb 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 @@ -174,7 +174,7 @@ public final class RowOperationDispatcher { switch (type.LayoutCode) { case Null: Reference tempReference_this = new Reference(this); - this.dispatcher.Dispatch(tempReference_this, scope, col, type, NullValue.Default); + this.dispatcher.Dispatch(tempReference_this, scope, col, type, NullValue.DEFAULT); this = tempReference_this.get(); break; case Boolean: diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java index 0f791ba..fab3b8e 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java @@ -136,7 +136,7 @@ public final class RowReaderUnitTests { d.LayoutCodeSwitch("array_t", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("tuple", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple>", value: - Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) + Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86))) d.LayoutCodeSwitch("tuple", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("nullable", value:Tuple.Create(null, (Long)123L)) //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java index 8407f7b..89c3ea9 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java @@ -57,7 +57,7 @@ public final class RowWriterUnitTests { new Reference(row); // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not // converted by C# to Java Converter: - ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, null, (ref RowWriter writer, + ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, null, (RowWriter RowWriter writer, TypeArgument rootTypeArg, Object ignored) -> { ResultAssert.IsSuccess(writer.WriteNull("null")); @@ -198,7 +198,7 @@ public final class RowWriterUnitTests { assert layout.TryFind("tuple>", tempOut_col5); col = tempOut_col5.get(); ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), - Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86)), (ref RowWriter writer2, + Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)), (ref RowWriter writer2, TypeArgument typeArg, Tuple> values) -> @@ -240,20 +240,20 @@ public final class RowWriterUnitTests { ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(null, (Long)123L), (ref RowWriter writer2, TypeArgument typeArg, Tuple values) -> { - RowWriter.WriterFunc f0 = (Reference writer, TypeArgument typeArg, + RowWriter.WriterFunc f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg, Integer context) -> null.invoke(writer, typeArg.clone(), context); if (values.Item1 != null) { - f0 = (ref RowWriter writer3, TypeArgument typeArg2, Integer value) -> writer3.WriteInt32(null, + f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Integer value) -> writer3.WriteInt32(null, value.intValue()); } ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), values.Item1, f0)); - RowWriter.WriterFunc f1 = (Reference writer, TypeArgument typeArg, + RowWriter.WriterFunc f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg, Long context) -> null.invoke(writer, typeArg.clone(), context); if (values.Item2 != null) { - f1 = (ref RowWriter writer3, TypeArgument typeArg2, Long value) -> writer3.WriteInt64(null, + f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Long value) -> writer3.WriteInt64(null, value.longValue()); } diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java index eed49ce..1da97d3 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java @@ -175,7 +175,7 @@ public final class SerializerUnitTest { break; case "resourcePath": Out tempOut_ResourcePath = new Out(); - r = reader.get().readString(tempOut_ResourcePath); + r = reader.get().readUtf8String(tempOut_ResourcePath); retval.ResourcePath = tempOut_ResourcePath.get(); if (r != Result.SUCCESS) { return r; diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/AddressSerializer.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/AddressSerializer.java index df3da49..0c99320 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/AddressSerializer.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/AddressSerializer.java @@ -17,7 +17,7 @@ public final class AddressSerializer { switch (reader.get().path()) { case "street": Out tempOut_Street = new Out(); - r = reader.get().readString(tempOut_Street); + r = reader.get().readUtf8String(tempOut_Street); obj.get().argValue.Street = tempOut_Street.get(); if (r != Result.SUCCESS) { return r; @@ -26,7 +26,7 @@ public final class AddressSerializer { break; case "city": Out tempOut_City = new Out(); - r = reader.get().readString(tempOut_City); + r = reader.get().readUtf8String(tempOut_City); obj.get().argValue.City = tempOut_City.get(); if (r != Result.SUCCESS) { return r; @@ -35,7 +35,7 @@ public final class AddressSerializer { break; case "state": Out tempOut_State = new Out(); - r = reader.get().readString(tempOut_State); + r = reader.get().readUtf8String(tempOut_State); obj.get().argValue.State = tempOut_State.get(); if (r != Result.SUCCESS) { return r; diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/PostalCodeSerializer.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/PostalCodeSerializer.java index fdc6796..8ce8579 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/PostalCodeSerializer.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/customerschema/PostalCodeSerializer.java @@ -60,7 +60,7 @@ public final class PostalCodeSerializer { } if (obj.Plus4.HasValue) { - r = writer.get().WriteInt16("plus4", obj.Plus4.Value); + r = writer.get().writeInt16("plus4", obj.Plus4.Value); return r; }