1

On websocket connection between .net and spring boot rsocket I am trying to encode the routing header to the quotes endpoint like this:

int routeSize = 6;
string hexValue = routeSize.ToString("X");
metaData = hexValue + "quotes";

I don't think this is correct. The entire net client code is

var client = new RSocketClient(new WebSocketTransport("ws://127.0.0.1:7000/"));
await client.ConnectAsync(new RSocketOptions()
{
    InitialRequestSize = 3,
    DataMimeType = "application/json",
    MetadataMimeType = "message/x.rsocket.routing.v0"
});

String json = {\"myQuote\":\"1234\"}
int routeSize = 6;
string hexValue = routeSize.ToString("X");
metaData = hexValue + "quotes";

var stringclient = new RSocketClient.ForStrings(client);
await stringclient.RequestStream(json, metaData)
    .ForEachAsync((result) =>
    {
        Console.WriteLine($"Result ===> {result}");
    });

and this produces the error

0001 Error {000}: [00000201] readerIndex(1) + length(54) exceeds writerIndex(7): UnpooledSlicedByteBuf(ridx: 1, widx: 7, cap: 7/7, unwrapped: PooledUnsafeDirectByteBuf(ridx: 0, widx: 281, cap: 281))

As related to RSocket Net client request stream routing metadata to spring boot @MessageMapping routes what's required is the C# equivalent of JavaScript String.fromCharCode(route.length) + route;

rupweb
  • 3,052
  • 1
  • 30
  • 57

1 Answers1

1

The answer was to use a default encoding to get a byte[] of the route name size as integer 6 and then add the length of the route name in bytes followed by the route, passing the string as metaData according to https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md

byte[] intBytes = BitConverter.GetBytes(6);
string stringBytes = Encoding.Default.GetString(intBytes, 0, 1);
metaData = stringBytes + "quotes";
rupweb
  • 3,052
  • 1
  • 30
  • 57