tursodatabase / tursodatabase/libsql
How to generate stubs for Hrana messages in C#/.NET
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 17.2k
- Forks
- 531
- Avg merge
- 1h 12m
- Merged PRs (30d)
- 1
Description
I'm experimenting with a .NET client for libsql using hrana3-protobuf but I'm not sure whether I'm using the correct .proto definitions for my generated messages.
I know there is an existing .NET community driver but that one is too early in its development.
I copied the definitions from the HRANA_3_SPEC (websocket as hrana.ws.proto and shared as hrana.proto) and I'm using protoc to generate C# code. I had to add import "hrana.proto"; at the top of hrana.ws.proto to get it to work.
Trying to fulfill the HelloMsg authentication handshake fails due to a decoding error: Could not decode client message from Protobuf: failed to decode Protobuf message: invalid wire type value: 7.
The simplified code:
using var socket = new ClientWebSocket();
socket.Options.AddSubProtocol("hrana3-protobuf");
var token = "<actual-token>";
var url = "wss://<actual-url>";
await socket.ConnectAsync(new Uri(url), CancellationToken.None); // Connecting works
var hello = new HelloMsg // Generated through protoc
{
Jwt = token,
};
await socket.SendAsync(new ArraySegment<byte>(hello.ToByteArray()), WebSocketMessageType.Binary, endOfMessage: true, CancellationToken.None);
var buffer = WebSocket.CreateClientBuffer(4096, 4096);
var result = await socket.ReceiveAsync(buffer, CancellationToken.None);
// result.MessageType is Close here, with error description mentioned above
The most obvious cause to me is that something is wrong with my .proto definitions. Either the definitions in the docs aren't up to date, or the way I'm passing them through protoc is incorrect.
I tried looking for actual .proto files but the best I could find was either the definitions in the docs or messages defined in Rust.
I also tried protoc --decode_raw < hellomsg.bin and it contained the correct original token at index 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with docs/HRANA_3_SPEC.md and the hrana.ws.proto and hrana.proto definitions copied from it, then inspect the generated HelloMsg bytes using protoc --decode_raw. Compare the generated message and WebSocket handshake with the protocol expectations; done means the C# client completes authentication without the invalid wire type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100