Mystic Tm
Mystic Tm

Reputation: 17

using Construct library for parsing text-based protocol

this probably sounds as a silly question, but I wonder if the Construct library can be used to declaratively implement a parser of a text-based protocol ?

my protocol works with well defined text-based construction with ASCII encoding and made of well known, constant message identifier (such as command IDs), followed by literal values expanded as text but than could be later interpreted as String, boolean, integer or floats in an upper layer of the applicative system

for instance a following message of my protocol could be : "/CHECK:eq:command,exit" where :

the message hence created is a command to make a request test : "CHECK that command == exit"

I made 2 unsuccessful atempts :

  1. using CString('ascii') as basic buiding bloc => fails because any bloc would be expected to be terminated by '\0' character, that is not the case.

  2. using GreedyString fails also because the parser do not stop on "Const" structure indentifying the constant delimiters of my protocol, instead it always try to greedily consume until end of stream but i would expect that Const("/CHECK") consume only the"/CHECK" even using greedy constant

Then I am stuck at implementing my own parser code,that is boilerplate and not applicative from my point of view

Upvotes: 0

Views: 36

Answers (0)

Related Questions