CurtHagenlocher commented on code in PR #275: URL: https://github.com/apache/arrow-dotnet/pull/275#discussion_r2935763411
########## src/Apache.Arrow.Variant/VariantReader.cs: ########## @@ -0,0 +1,686 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Data.SqlTypes; +using System.Runtime.CompilerServices; +using System.Text; + +namespace Apache.Arrow.Variant +{ + /// <summary> + /// Zero-copy reader for a single variant value. Provides type inspection + /// and typed accessors for primitives, short strings, objects, and arrays. + /// </summary> + public ref struct VariantReader + { + private readonly ReadOnlySpan<byte> _metadata; + private readonly ReadOnlySpan<byte> _value; + + /// <summary> + /// Creates a reader over a variant value. + /// </summary> + /// <param name="metadata">The variant metadata buffer (shared across all values in a column).</param> + /// <param name="value">The variant value buffer for this specific value.</param> + public VariantReader(ReadOnlySpan<byte> metadata, ReadOnlySpan<byte> value) + { + _metadata = metadata; + _value = value; + } + + /// <summary>Gets the full metadata span.</summary> + public ReadOnlySpan<byte> Metadata => _metadata; + + /// <summary>Gets the full value span.</summary> + public ReadOnlySpan<byte> Value => _value; + + // --------------------------------------------------------------- + // Type inspection + // --------------------------------------------------------------- + + /// <summary>Gets the header byte of this value.</summary> + public byte Header => _value[0]; + + /// <summary>Gets the basic type of this value.</summary> + public VariantBasicType BasicType => VariantEncodingHelper.GetBasicType(Header); + + /// <summary> + /// Gets the primitive type when <see cref="BasicType"/> is <see cref="VariantBasicType.Primitive"/>. + /// </summary> + public VariantPrimitiveType PrimitiveType => VariantEncodingHelper.GetPrimitiveType(Header); Review Comment: I changed this to return a `Nullable<VariantPrimitiveType>` and produce a null when it's not a primitive. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
