blob: d6e7b4e82e598a55bbc921c6ec4c2b37614b70a4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <cstring>
#include <cstdint>
namespace mbus {
/**
* A context is an application specific unit of information that can
* be attached to a routable. Specifically, messagebus will ensure
* that when a reply is obtained, it will have the same context as the
* original message.
**/
struct Context
{
/**
* This is a region of memory that can be interpreted as either an
* integer or a pointer.
**/
union {
uint64_t UINT64;
void *PTR;
} value;
/**
* Create a context that is set to 0, however you interpret it.
**/
Context() { memset(&value, 0, sizeof(value)); }
/**
* Create a contex from an integer.
*
* @param v the value
**/
Context(uint64_t v) { value.UINT64 = v; }
/**
* Create a context from a pointer
*
* @param pt the pointer
**/
Context(void *pt) { value.PTR = pt; }
};
} // namespace mbus
|