clj-commons / clj-commons/gloss

Type depending on more fields.

Open
#38 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Clojure
Stars
486
Forks
53
PR merge metrics
No merged PRs in 30d

Description

I implementing protocol, which has multiple byte codes for one type. For example **digital message** may have codes in range of 0x90 - 0x9F. Naive function for generating that type can looks like this:

``` clojure
(defn digital-message
[port]
(bit-or 0x90 port))
```

I would like to create encoders and decoders which looks like that:
**decoder:**

``` clojure
(decode-all decoder (to-byte-buffer [0x91 0x05 0x98 0x06])) ; [{:type :digital-message :port 1 :some-data 5}
; {:type :digital-message :port 8 :some-data 6}]
```

**encoder:**

``` clojure
(encode encoder {:type :digital-message :port 2 :some-data 5}) ; [0x92 0x05]
```

Unfortunaly, I don't know how to implement it and combine with `gloss/header`.

Thanks for any response.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the examples using digital-message, decode-all, encode, to-byte-buffer, and gloss/header. Determine how a type can depend on multiple byte-code fields and how the requested encoder and decoder should compose with gloss/header. Done would be a defined implementation that supports the shown digital-message encoding and decoding behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.