open-coap / java-coap

CoAP Java library
Apache License 2.0
18 stars 5 forks source link

Introduce a CoapMessage class/interface ? #83

Open sbernard31 opened 2 months ago

sbernard31 commented 2 months ago

I don't know if this is a good idea but I face some situation where I need to handle a coap request OR a coap (separated) response in a same way. This is not too surprising as from a CoAP RFC point of view all request and response are conceptually a CoAP Message.

In my case, I need the remote peer address and the transport context of the message. See :

szysas commented 2 months ago

Easy one would be to add helper method, would that be enough?

sbernard31 commented 2 months ago

I'm not sure to see how it will looks like ?

szysas commented 2 months ago

Something like:

static InetSocketAddress getPeerAddress(Object coap) {
...

static TransportContext getTransportContext(Object coap) {
...
sbernard31 commented 2 months ago

OK I get it but my question was more about having a kind of Parent class (e.g. CoapMessage) for CoapRequest, CoapResponse, SeparatedResponse. At first sight (maybe I'm wrong) I think this could make java-coap user code more elegant.

Regarding adding this static method, to be honest, I'm not sure will really makes my user code better. :thinking:

Anyway, maybe better to work first on https://github.com/open-coap/java-coap/issues/84 and see if you also need this kind of abstraction in java-coap code too ?