Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return of Decode methods to returning the actual destination length. #543

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 4 additions & 35 deletions src/Parquet/Encodings/ParquetPlainEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Parquet.Data;
using Parquet.Extensions;
Expand Down Expand Up @@ -594,54 +593,30 @@ public static void Encode(ReadOnlySpan<int> data, Stream destination) {
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<int> data) {
Span<byte> dataBytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(dataBytes);
return data.Length;
}

public static void Encode(ReadOnlySpan<uint> data, Stream destination) {
ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(data);
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<uint> data) {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / sizeof(uint);
}

public static void Encode(ReadOnlySpan<long> data, Stream destination) {
ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(data);
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<long> data) {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / sizeof(long);
}

public static void Encode(ReadOnlySpan<ulong> data, Stream destination) {
ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(data);
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<ulong> data) {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / sizeof(ulong);
}

public static void Encode(ReadOnlySpan<BigInteger> data, Stream destination) {
ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(data);
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<BigInteger> data) {
public static int Decode<T>(Span<byte> source, Span<T> data) where T : struct {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / 12;
return Math.Min(data.Length, source.Length / Unsafe.SizeOf<T>());
}

public static void Encode(ReadOnlySpan<decimal> data, Stream destination, SchemaElement tse) {
Expand Down Expand Up @@ -753,12 +728,6 @@ public static void Encode(ReadOnlySpan<double> data, Stream destination) {
Write(destination, bytes);
}

public static int Decode(Span<byte> source, Span<double> data) {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / sizeof(double);
}

public static void Encode(ReadOnlySpan<float> data, Stream destination) {
ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(data);
Write(destination, bytes);
Expand All @@ -767,7 +736,7 @@ public static void Encode(ReadOnlySpan<float> data, Stream destination) {
public static int Decode(Span<byte> source, Span<float> data) {
Span<byte> bytes = MemoryMarshal.AsBytes(data);
source.CopyWithLimitTo(bytes);
return source.Length / sizeof(float);
return data.Length;
}

public static void Encode(ReadOnlySpan<byte[]> data, Stream destination) {
Expand Down