You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The old request/response setup worked great, but had its limitations.
The new model types are request, message (zero or more) and a receipt.
The receipt can immplement some optional interfaces that gets/sets
* ETag
* ELastModified
* ESize
These may autimatically be set by the library if not provided by user (the `Etag` bassed on all message bodies if there's a hash function configured).
The primary use case for the above would be client side caching.
This also removes the slow Gob codec.
// Raw messages are passed directly to the client,
84
+
// typically used for log messages.
85
+
c.SendRaw(
86
+
execrpc.Message{
87
+
Header: execrpc.Header{
88
+
Version: 32,
89
+
Status: 150,
90
+
},
91
+
Body: []byte("a log message"),
92
+
},
93
+
)
94
+
95
+
// Enqueue one or more messages.
96
+
c.Enqueue(
97
+
model.ExampleMessage{
98
+
Hello: "Hello 1!",
99
+
},
100
+
model.ExampleMessage{
101
+
Hello: "Hello 2!",
102
+
},
103
+
)
104
+
105
+
c.Enqueue(
106
+
model.ExampleMessage{
107
+
Hello: "Hello 3!",
108
+
},
109
+
)
110
+
111
+
// Wait for the framework generated receipt.
112
+
receipt:=<-c.Receipt()
113
+
114
+
// ETag provided by the framework.
115
+
// A hash of all message bodies.
116
+
fmt.Println("Receipt:", receipt.ETag)
117
+
118
+
// Modify if needed.
119
+
receipt.Size = uint32(123)
120
+
121
+
// Close the message stream.
122
+
c.Close(false, receipt)
44
123
},
45
124
},
46
125
)
126
+
if err != nil {
127
+
log.Fatal(err)
128
+
}
129
+
130
+
// Start the server. This will block.
47
131
iferr:= server.Start(); err != nil {
48
-
// ... handle error
132
+
log.Fatal(err)
49
133
}
50
-
_ = server.Wait()
51
134
}
52
135
```
53
136
54
-
Of the included codecs, JSON seems to win by a small margin (but only tested with small requests/responses):
55
-
56
-
```bsh
57
-
name time/op
58
-
Client/JSON-10 4.89µs ± 0%
59
-
Client/TOML-10 5.51µs ± 0%
60
-
Client/Gob-10 17.0µs ± 0%
61
-
62
-
name alloc/op
63
-
Client/JSON-10 922B ± 0%
64
-
Client/TOML-10 1.67kB ± 0%
65
-
Client/Gob-10 9.22kB ± 0%
66
-
67
-
name allocs/op
68
-
Client/JSON-10 19.0 ± 0%
69
-
Client/TOML-10 28.0 ± 0%
70
-
Client/Gob-10 227 ± 0%
71
-
```
72
-
73
137
## Status Codes
74
138
75
139
The status codes in the header between 1 and 99 are reserved for the system. This will typically be used to catch decoding/encoding errors on the server.
0 commit comments