RangerMauve / dat-gateway

Visit https://github.com/garbados/dat-gateway/ instead
19 stars 4 forks source link

Replacing websocket-stream with RPC/Protocol Buffers? #3

Open chrisekelley opened 6 years ago

chrisekelley commented 6 years ago

I looked at grpc this weekend - they have some links to Protocol buffers. Have you worked w/ it? Could it be a replacement for websocket-stream?

Bunsen doesn't really need super-efficient communications between the browser and the local dat-gateway, but if someone offers a public gateway, going the RPC/Protocol Buffers route may be the right path.

RangerMauve commented 6 years ago

GRPC uses HTTP2 for the communication and doesn't work on a single stream.

I suggest looking into how hypercore-protocol works.

Basically, you compile your protobuff schema to JS, then use that to parse incoming messages from a stream, and have functions that take JS objects and compile them to protobuff before writing to the stream.

Check out length-prefix-stream to make it easy to parse individual messages without having to worry about detecting how big they are.

protons is an easy to use library for working with protocol buffers.