35 if (size_ <= max_vsm_size) {
36 const int rc = init_size (size_);
45 return init_external_storage (content_,
data_, size_, ffn_, hint_);
47 return init_data (
data_, size_, ffn_, hint_);
52 _u.vsm.metadata =
NULL;
53 _u.vsm.type = type_vsm;
56 _u.vsm.group.sgroup.group[0] =
'\0';
57 _u.vsm.group.type = group_type_short;
58 _u.vsm.routing_id = 0;
64 if (size_ <= max_vsm_size) {
65 _u.vsm.metadata =
NULL;
66 _u.vsm.type = type_vsm;
68 _u.vsm.size =
static_cast<unsigned char> (size_);
69 _u.vsm.group.sgroup.group[0] =
'\0';
70 _u.vsm.group.type = group_type_short;
71 _u.vsm.routing_id = 0;
73 _u.lmsg.metadata =
NULL;
74 _u.lmsg.type = type_lmsg;
76 _u.lmsg.group.sgroup.group[0] =
'\0';
77 _u.lmsg.group.type = group_type_short;
78 _u.lmsg.routing_id = 0;
79 _u.lmsg.content =
NULL;
88 _u.lmsg.content->data = _u.lmsg.content + 1;
89 _u.lmsg.content->size = size_;
90 _u.lmsg.content->ffn =
NULL;
91 _u.lmsg.content->hint =
NULL;
99 const int rc = init_size (size_);
105 assert (
NULL != buf_);
106 memcpy (
data (), buf_, size_);
120 _u.zclmsg.metadata =
NULL;
121 _u.zclmsg.type = type_zclmsg;
123 _u.zclmsg.group.sgroup.group[0] =
'\0';
124 _u.zclmsg.group.type = group_type_short;
125 _u.zclmsg.routing_id = 0;
127 _u.zclmsg.content = content_;
129 _u.zclmsg.content->size = size_;
130 _u.zclmsg.content->ffn = ffn_;
131 _u.zclmsg.content->hint = hint_;
148 _u.cmsg.metadata =
NULL;
149 _u.cmsg.type = type_cmsg;
151 _u.cmsg.data =
data_;
152 _u.cmsg.size = size_;
153 _u.cmsg.group.sgroup.group[0] =
'\0';
154 _u.cmsg.group.type = group_type_short;
155 _u.cmsg.routing_id = 0;
157 _u.lmsg.metadata =
NULL;
158 _u.lmsg.type = type_lmsg;
160 _u.lmsg.group.sgroup.group[0] =
'\0';
161 _u.lmsg.group.type = group_type_short;
162 _u.lmsg.routing_id = 0;
165 if (!_u.lmsg.content) {
170 _u.lmsg.content->data =
data_;
171 _u.lmsg.content->size = size_;
172 _u.lmsg.content->ffn = ffn_;
173 _u.lmsg.content->hint = hint_;
181 _u.delimiter.metadata =
NULL;
182 _u.delimiter.type = type_delimiter;
183 _u.delimiter.flags = 0;
184 _u.delimiter.group.sgroup.group[0] =
'\0';
185 _u.delimiter.group.type = group_type_short;
186 _u.delimiter.routing_id = 0;
192 _u.base.metadata =
NULL;
193 _u.base.type = type_join;
195 _u.base.group.sgroup.group[0] =
'\0';
196 _u.base.group.type = group_type_short;
197 _u.base.routing_id = 0;
203 _u.base.metadata =
NULL;
204 _u.base.type = type_leave;
206 _u.base.group.sgroup.group[0] =
'\0';
207 _u.base.group.type = group_type_short;
208 _u.base.routing_id = 0;
214 int rc = init_size (size_);
221 memcpy (
data (), topic_, size_);
229 int rc = init_size (size_);
236 memcpy (
data (), topic_, size_);
250 if (_u.base.type == type_lmsg) {
254 || !_u.lmsg.content->refcnt.sub (1)) {
257 _u.lmsg.content->refcnt.~atomic_counter_t ();
259 if (_u.lmsg.content->ffn)
260 _u.lmsg.content->ffn (_u.lmsg.content->data,
261 _u.lmsg.content->hint);
262 free (_u.lmsg.content);
272 || !_u.zclmsg.content->refcnt.sub (1)) {
275 _u.zclmsg.content->refcnt.~atomic_counter_t ();
277 _u.zclmsg.content->ffn (_u.zclmsg.content->data,
278 _u.zclmsg.content->hint);
282 if (_u.base.metadata !=
NULL) {
283 if (_u.base.metadata->drop_ref ()) {
286 _u.base.metadata =
NULL;
289 if (_u.base.group.type == group_type_long) {
290 if (!_u.base.group.lgroup.content->refcnt.sub (1)) {
293 _u.base.group.lgroup.content->refcnt.~atomic_counter_t ();
295 free (_u.base.group.lgroup.content);
334 const int rc = close ();
349 src_.
refcnt ()->
set (initial_shared_refcnt);
354 src_.
_u.
base.metadata->add_ref ();
356 if (src_.
_u.
base.group.type == group_type_long)
357 src_.
_u.
base.group.lgroup.content->refcnt.add (1);
369 switch (_u.base.type) {
373 return _u.lmsg.content->data;
377 return _u.zclmsg.content->data;
389 switch (_u.base.type) {
393 return _u.lmsg.content->size;
395 return _u.zclmsg.content->size;
410 switch (_u.base.type) {
412 _u.vsm.size =
static_cast<unsigned char> (new_size_);
415 _u.lmsg.content->size = new_size_;
418 _u.zclmsg.content->size = new_size_;
421 _u.cmsg.size = new_size_;
430 return _u.base.flags;
435 _u.base.flags |= flags_;
440 _u.base.flags &= ~flags_;
445 return _u.base.metadata;
450 assert (metadata_ !=
NULL);
451 assert (_u.base.metadata ==
NULL);
453 _u.base.metadata = metadata_;
458 if (_u.base.metadata) {
459 if (_u.base.metadata->drop_ref ()) {
462 _u.base.metadata =
NULL;
468 return (_u.base.flags & routing_id) == routing_id;
473 return (_u.base.flags & credential) == credential;
478 return _u.base.type == type_delimiter;
483 return _u.base.type == type_vsm;
488 return _u.base.type == type_cmsg;
493 return _u.base.type == type_lmsg;
498 return _u.base.type == type_zclmsg;
503 return _u.base.type == type_join;
508 return _u.base.type == type_leave;
528 if (this->is_ping () || this->is_pong ())
529 return this->
size () - ping_cmd_name_size;
531 && (this->is_subscribe () || this->is_cancel ()))
532 return this->
size ();
533 else if (this->is_subscribe ())
534 return this->
size () - sub_cmd_name_size;
535 else if (this->is_cancel ())
536 return this->
size () - cancel_cmd_name_size;
545 if (this->is_ping () || this->is_pong ())
547 static_cast<unsigned char *
> (this->
data ()) + ping_cmd_name_size;
550 && (this->is_subscribe () || this->is_cancel ()))
551 data =
static_cast<unsigned char *
> (this->
data ());
552 else if (this->is_subscribe ())
553 data =
static_cast<unsigned char *
> (this->data ()) + sub_cmd_name_size;
554 else if (this->is_cancel ())
556 static_cast<unsigned char *
> (this->data ()) + cancel_cmd_name_size;
574 if (_u.base.type == type_lmsg || is_zcmsg ()) {
576 refcnt ()->add (refs_);
578 refcnt ()->set (refs_ + 1);
596 if ((_u.base.type != type_zclmsg && _u.base.type != type_lmsg)
603 if (_u.base.type == type_lmsg && !_u.lmsg.content->refcnt.sub (refs_)) {
606 _u.lmsg.content->refcnt.~atomic_counter_t ();
608 if (_u.lmsg.content->ffn)
609 _u.lmsg.content->ffn (_u.lmsg.content->data, _u.lmsg.content->hint);
610 free (_u.lmsg.content);
615 if (is_zcmsg () && !_u.zclmsg.content->refcnt.sub (refs_)) {
617 if (_u.zclmsg.content->ffn) {
618 _u.zclmsg.content->ffn (_u.zclmsg.content->data,
619 _u.zclmsg.content->hint);
630 return _u.base.routing_id;
636 _u.base.routing_id = routing_id_;
645 _u.base.routing_id = 0;
651 if (_u.base.group.type == group_type_long)
652 return _u.base.
group.lgroup.content->group;
653 return _u.base.group.sgroup.group;
660 return set_group (group_,
length);
671 _u.base.group.lgroup.type = group_type_long;
672 _u.base.group.lgroup.content =
674 assert (_u.base.group.lgroup.content);
676 _u.base.group.lgroup.content->refcnt.
set (1);
677 strncpy (_u.base.group.lgroup.content->group, group_, length_);
678 _u.base.group.lgroup.content->group[length_] =
'\0';
680 strncpy (_u.base.group.sgroup.group, group_, length_);
681 _u.base.group.sgroup.group[length_] =
'\0';
689 switch (_u.base.type) {
691 return &_u.lmsg.content->refcnt;
693 return &_u.zclmsg.content->refcnt;