Skip to content

Commit

Permalink
fix(#40): ensure RepeatedField<T>.AsArray() produces an array of exac…
Browse files Browse the repository at this point in the history
…t length

- Re-allocate to a new exactly-sized T[] if the underlying buffer length of RepeatedField<T> does not match the count
- Bump up the submodule commit (no functional changes)
- Update TODO
  • Loading branch information
neon-sunset committed Jul 27, 2023
1 parent 2004add commit 5aef8bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

## Nice to have

- [ ] It appears the behavior of the gRPC stack has changed and inner `RepeatedField<T>` buffer is no longer created to the exact length of data received in the response. Analyze the implementation changes and consider options to reduce copying and allocations.
- [ ] Add an extension to create an index and then wait for it to be ready to use, maybe add guards before sending requests?
- [ ] Restructure the solution and add Pinecone.SemanticKernel project for long-term memory integration? Or is it better to directly contribute it to SK?
- [ ] Consider putting the handling of "MetadataValue as DU" into a dedicated place instead of switches in multiple places. First-class DUs in C# when?
8 changes: 7 additions & 1 deletion src/Grpc/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ public static RepeatedField<T> AsRepeatedField<T>(this T[] source) where T : unm

public static T[] AsArray<T>(this RepeatedField<T> source) where T : unmanaged
{
return (T[])FieldAccessors<T>.ArrayField.GetValue(source)!;
var buffer = (T[])FieldAccessors<T>.ArrayField.GetValue(source)!;
if (buffer.Length != source.Count)
{
buffer = buffer[..source.Count];
}

return buffer;
}

public static void OverwriteWith<T>(this RepeatedField<T> target, T[]? source) where T : unmanaged
Expand Down

0 comments on commit 5aef8bb

Please sign in to comment.