memoriesadrift / tuw-cryptocurrencies-blockchain

Blockchain created for the Cryptocurrencies course at TU Wien
0 stars 0 forks source link

T1: JSON Encoding & Decoding #3

Closed memoriesadrift closed 11 months ago

memoriesadrift commented 11 months ago

Description

Implement canonical JSON encoding for messages as per the format specified in the protocol. Implement message parsing, defragmentation, and canonical JSON encoding and decod- ing. On receiving data from a connected node, decode and parse it as a JSON string. If the received message is not a valid JSON or doesn’t parse into one of the valid mes- sage types, send an "error" message with error name INVALID_FORMAT to the node. Note that a single message may get split across different packets, e.g. you may re- ceive "type":"ge and tpeers" in separate messages. So you should defragment such JSON strings. Alternatively, a single packet could contain multiple messages (separated by "\n") and your node should be able to separate them. Note that JSON strings you receive may not be in canonical form, but they are valid messages nevertheless.

Scope

  1. Decide on internal data structures
  2. Implement encoding to canonical JSON from internal data structure
  3. Implement decoding to canonical JSON from internal data structure

Note

Try leverage TS support in JSON.parse()

This seems like a larger task, maybe we can divide it, but I feel like making two different people work on the same problem from two different angles may lead to confusion