mirror of
https://github.com/jlengrand/Observer.git
synced 2026-03-10 08:31:23 +00:00
Adds JSon structure in README
Explains expected structure of the JSon messages. Changes default message values to None I will probably have to provide a imple way to create JSon elements.
This commit is contained in:
41
README.md
41
README.md
@@ -18,6 +18,47 @@ The notifications are sent in json format.
|
||||
An Observable is an entity holding information of interest for other entities.
|
||||
Observers subscribe or unsubscribe to an Observable to get notified any time message is updated.
|
||||
|
||||
### JSon Structure:
|
||||
|
||||
As already explained, the messages sent from the observable to the observers are formatted in JSon.
|
||||
This allows a simple yet efficient control of the data sent and received while staying in line with the standards.
|
||||
|
||||
Each transmitted package should be divided into 4 sections:
|
||||
|
||||
- name : The name of the Observer to send the data to. As each Observer is uniquely defined by its name, filling this section means the data will be sent to **at most** one Observer.
|
||||
- group : The group of Observers to send the data to. Each Observer may belong to a group. All Observers in the group will then be notified.
|
||||
- type : the type of message contained in data. This section is not processed by the Observable and is sent as is. It may be blank, or contain anything.
|
||||
- data : The actual data to be transmitted to the Observers
|
||||
|
||||
Here is are several examples of valid JSon message :
|
||||
|
||||
#### Data will be sent to Bob only. No particular message type
|
||||
{
|
||||
"name": 'Bob',
|
||||
"group": '',
|
||||
"type": '',
|
||||
"data": 42
|
||||
}
|
||||
|
||||
#### Data will be sent to all Observers in the GUI group. We may assess that this is an update :).
|
||||
{
|
||||
"name": '',
|
||||
"group": 'GUI',
|
||||
"type": 'Update',
|
||||
"data": 'coffee'
|
||||
}
|
||||
|
||||
#### No group, neither name specified. All subscribers will be notified. the message is an array of value object.
|
||||
{
|
||||
"name": '',
|
||||
"group": '',
|
||||
"type": '',
|
||||
"data": ["baz", null, 1.0, 2]
|
||||
}
|
||||
|
||||
According to the [JSon specifications](http://json.org/),
|
||||
_A value can be a string in double quotes, or a number, or true or false or null, or an object or an array._
|
||||
|
||||
## Description of the package
|
||||
|
||||
The Observer pattern does not need any external module to work. Any simple Python installation (>= 2.6) should be enough.
|
||||
|
||||
Reference in New Issue
Block a user