Kronos – Creating a base request

Any Kronos client will be available to use three basic commands

  1. Insert
  2. Get
  3. Delete

In future I want to add few more, like Count and GetKeys.

Each of requests to the server serialized to binary form is preceded by few bytes of meta-data, including RequestType. In code its represented as a Request class, which in addition to type has two generic methods. At the beginning they might look difficult, but they are quite simple. First of them is responsible for sending any request to the server via special connection interface. It’s generic, because some of them might return another type. For example Get will always return a byte array, but Insert and Delete – void.

The second, protected method, takes care the logic for processing the response. At the beginning I thought that the processing bytes from server will always be the same. Unfortunately, due to one thing I had to change my idea. How to send null by socket? It is impossible to serialize null without any special-magic-combo-values like chain of specific numbers. How to send empty byte array between sockets? Again, it is impossible. Similar to HTTP, I’ve created a special codes.

Back to the PrepareResponse method, it is protected, because some Request processes a response in different way. For example, GetRequest checks if bytes from server contain information about StatusCodes.

You may notice that I have used a Proto attributes from Protobuf library. In next post I’m going to describe the way of working with Protocol Buffers and .NET Core.

Kronos is already available on the github. Feel free to ask, comment and give feedback!