コード例 #1
0
            /// <inheritdoc />
            public override Utf8String GetUtf8StringValue()
            {
                if (this.TryGetBufferedStringValue(out Utf8Memory memory))
                {
                    return(Utf8String.UnsafeFromUtf8BytesNoValidation(memory.Memory));
                }

                return(Utf8String.TranscodeUtf16(this.GetStringValue()));
            }
コード例 #2
0
        public void TestWriteOperationWithBinaryIdByteArray()
        {
            ISpanResizer <byte> resizer = new MemorySpanResizer <byte>(100);
            RowBuffer           row     = new RowBuffer(capacity: 100, resizer: resizer);

            row.InitLayout(HybridRowVersion.V1, BatchSchemaProvider.BatchOperationLayout, BatchSchemaProvider.BatchLayoutResolver);

            byte[]             testBinaryId   = new byte[] { 1, 2, 3, 4, };
            ItemRequestOptions requestOptions = new();

            requestOptions.Properties = new Dictionary <string, object>()
            {
                { WFConstants.BackendHeaders.BinaryId, testBinaryId },
            };
            TransactionalBatchItemRequestOptions transactionalBatchItemRequestOptions =
                TransactionalBatchItemRequestOptions.FromItemRequestOptions(requestOptions);
            ItemBatchOperation operation = new ItemBatchOperation(
                operationType: OperationType.Patch,
                operationIndex: 0,
                partitionKey: Cosmos.PartitionKey.Null,
                requestOptions: transactionalBatchItemRequestOptions);

            int length = operation.GetApproximateSerializedLength();

            Assert.AreEqual(testBinaryId.Length, length);

            Result r = RowWriter.WriteBuffer(ref row, operation, ItemBatchOperation.WriteOperation);

            if (r != Result.Success)
            {
                Assert.Fail(r.ToString());
            }

            bool      foundBinaryId = false;
            RowReader reader        = new RowReader(ref row);

            while (reader.Read())
            {
                if (reader.PathSpan == Utf8String.TranscodeUtf16("binaryId"))
                {
                    foundBinaryId = true;
                    reader.ReadBinary(out byte[] binaryId);
                    CollectionAssert.AreEqual(testBinaryId, binaryId);
                }
            }

            Assert.IsTrue(foundBinaryId);
        }
コード例 #3
0
 public override Utf8String GetUtf8StringValue()
 {
     return(Utf8String.TranscodeUtf16(this.GetStringValue()));
 }