perf(server): batch achievement updates and eliminate redundant snapshots, writes and JSON round trips
This commit is contained in:
@@ -31,15 +31,25 @@ func Encode(code int, proto, key []byte, now int64) ([]byte, error) {
|
||||
// Notify is plain base64 protobuf in the JSON envelope. The client parses it
|
||||
// separately after decrypting the response data (NetworkManager.OnAfterResponse).
|
||||
func EncodeWithNotify(code int, proto, key []byte, now int64, notify []byte) ([]byte, error) {
|
||||
data, err := cryptox.EncryptBase64Payload(proto, key)
|
||||
envelope, err := EnvelopeWithNotify(code, proto, key, now, notify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(Envelope{
|
||||
return json.Marshal(envelope)
|
||||
}
|
||||
|
||||
// EnvelopeWithNotify builds the same wire response without an intermediate
|
||||
// JSON round trip when the caller is assembling a batch.
|
||||
func EnvelopeWithNotify(code int, proto, key []byte, now int64, notify []byte) (Envelope, error) {
|
||||
data, err := cryptox.EncryptBase64Payload(proto, key)
|
||||
if err != nil {
|
||||
return Envelope{}, err
|
||||
}
|
||||
return Envelope{
|
||||
PacketCode: code, Length: base64.StdEncoding.EncodedLen(len(proto)),
|
||||
Data: data, ServerNowTime: now,
|
||||
Notify: base64.StdEncoding.EncodeToString(notify),
|
||||
})
|
||||
}, nil
|
||||
}
|
||||
|
||||
type BatchRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user