c# - ProtoBuf ParseDelimitedFrom is misaligning to the NetworkStream? -


what trying do

i author of this project grabs playing song spotify's local instance via local api , sets discord's 'now playing' message reflect it.

pretty simple stuff, various reasons want switch c#, , doesn't have same level of support spotify.

to cut long story shorter, cross-platform + working useful api + spotify playlist = clementine. decided create similar discord integration clementine.

but there's problem

i can create socket connects 127.0.0.1:5500.
can send connectrequest message through socket.
can receive these message types no problems whatsoever:

  • keep_alive,
  • play,
  • pause,
  • stop,
  • repeat,
  • shuffle,
  • volume_update,
  • track_position_update

but if try play song stopped state, 20 exceptions thrown , "play" message parsed.
believe should current_metainfo message.
similar exceptions thrown if try add new song playlist.

the mechanism using retrieve messages

message.parser.parsedelimitedfrom(client.getstream()); 

where:
message = class defined in .proto file repo
parser = protobuf built-in object parser
parsedelimitedfrom = protobuf built-in method takes [length:payloadoflength'length'] message stream , parses payload object of provided type (message).
client = system.net.sockets.tcpclient
getstream = system.net.sockets.networkstream

aside detecting 3 'unknown' messages every keepalive (the networkstream seems send 0's every quarter of second without data?) when clementine idle, method works fine messages not complex (ie: ones without songmetadata class in response object, , ones without response object @ all).

my suspicions

due proto3 not being backwards-compatible proto2, had modify provided .proto file remove 'optional' keywords, , default values things, , re-set enums start 0.
may have introduced subtle bug in parser tries read value doesn't exist, , moves on next instead of realising there's default, or that.

some of exceptions seem indicate parser not handling length of data properly.
mean parser reading stream end, before message written completely, , not waiting rest before stopping , trying parse it. not being able read first part of incomplete message, removing stream anyway, rendering following chunks illegible.
mean due way clementine nests messages, parser detecting size of outer message , not catering optional nested object (or actual clementine message not setting length appropriately).
problem album art being sequence of bytes of indeterminate length.

the walls have hit

i have re-written socket logic @ least 3 times. first 2 bare socket's , using byte[] buffers read messages.
seemed promising never return recursive function intended retrieve remainder of bytes particular message, there more bytes read. didn't occur me until writing try build buffer front instead , tryparse each iteration until understood message, remove message buffer.

i have attempted implement byte[] buffer tcpclient in similar manner above current implementation. again, trouble socket writing 0's instead of remaining idle cause problem leading 0's being treated invalid tag , throwing exceptions.

i have attempted use bufferedstream wrap networkstream, unsure of how go implementing re-read of read, exception-causing data, once more data arrived.

saucy

the actual code whole. should drop-in ready vscode installation c# plugin , dotnet core installed , configured.

https://bitbucket.org/roberestarkk/discordclementineremotedotnet

a cry help

i immensely grateful literally assistance can offer! @ wit's end project.
i've tried short of messaging developers (which intend shortly anwyays, need install irc client), , no-closer getting bottom of things.
if knew why exceptions being thrown...


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -