On 12 April 2013 11:36, Donovan Hide <
donov...@gmail.com> wrote:
>
>> Interesting, I hadn't seen this in json-rpc before.
>>
>> Just to check: a "notification" is just a client->server request that
>> doesn't require a reply, right?
>
>
> A notification doesn't require a reply and, in fact, cannot by replied to
> because it does not have an id to reply with.
>
>>
>> I can't see quite how that would relate to "a prior subscription request
>> in the opposite direction", which would seem to indicate that
>> the server is sending requests to the client.
>
>
> Stratum flow is:
>
> client sends request "mining.subscribe" to server
> server sends reply confirming subscription succeed or fail
> server later sends notification(s) indicating new work
that doesn't seem to fit with the description in json.RPC:
"A Notification is a Request object without an "id" member. "
which would seem to indicate that notifications flow from
client to server only (which seems fine).
If the server can asynchronously send notications to the client,
the model is quite different, and incompatible with the way that
rpc usually works. And there are various kinds of potential flow-control
issues.
>> It would not be too hard to change the net/rpc package to allow this,
>> I think. Perhaps Client.Notify(serviceMethod string, args interface{})
>> error
>>
>> The codecs could probably remain the same.
>
>
> I tried using net/rpc/ with a custom codec, but gave up quickly when I
> realised you cannot have a client and server run on the same socket. Stratum
> requires requests to be able to go either way. Have ended up with a homespun
> mux that seems to do the job.
That seems very unusual for an rpc-like protocol. Usually only a single
party initiates requests.
> Another issue I encountered was that the model Stratum implementation sends
> replies as JSON tuples (ie. positional arguments in Python-land) and the
> encoding/json package does not know about how to unmarshal this type of data
> structure into a struct. Ended up doing some []interface{} mapping to struct
> field order, reflect/magic/hack, that does work. Would be nice if there was
> a positional json tag:
>
> type Example struct{
> First int `json:"0"`
> Second int `json:"1"`
> }
>
> which could unmarshal
>
> {"test":(123,456)}
>
> and handle appropriately type mismatches and nested arrays or objects, etc.
> Have done this myself, but would be nice if it was in the standard
> library...
You can unmarshal into a []json.RawMessage and unmarshal
each item individually, but the positional-argument syntax
is an interesting idea - I could have used it myself recently.