nshead_message.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Licensed to the Apache Software Foundation (ASF) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. #include <algorithm>
  18. #include <google/protobuf/reflection_ops.h> // ReflectionOps::Merge
  19. #include <google/protobuf/wire_format.h>
  20. #include "brpc/nshead_message.h"
  21. #include "butil/logging.h"
  22. namespace brpc {
  23. NsheadMessage::NsheadMessage()
  24. : ::google::protobuf::Message() {
  25. SharedCtor();
  26. }
  27. NsheadMessage::NsheadMessage(const NsheadMessage& from)
  28. : ::google::protobuf::Message() {
  29. SharedCtor();
  30. MergeFrom(from);
  31. }
  32. void NsheadMessage::SharedCtor() {
  33. memset(&head, 0, sizeof(head));
  34. }
  35. NsheadMessage::~NsheadMessage() {
  36. SharedDtor();
  37. }
  38. void NsheadMessage::SharedDtor() {
  39. }
  40. const ::google::protobuf::Descriptor* NsheadMessage::descriptor() {
  41. return NsheadMessageBase::descriptor();
  42. }
  43. NsheadMessage* NsheadMessage::New() const {
  44. return new NsheadMessage;
  45. }
  46. void NsheadMessage::Clear() {
  47. memset(&head, 0, sizeof(head));
  48. body.clear();
  49. }
  50. bool NsheadMessage::MergePartialFromCodedStream(
  51. ::google::protobuf::io::CodedInputStream* input) {
  52. #define DO_(EXPRESSION) if (!(EXPRESSION)) return false
  53. ::google::protobuf::uint32 tag;
  54. while ((tag = input->ReadTag()) != 0) {
  55. if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
  56. ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
  57. return true;
  58. }
  59. }
  60. return true;
  61. #undef DO_
  62. }
  63. void NsheadMessage::SerializeWithCachedSizes(
  64. ::google::protobuf::io::CodedOutputStream*) const {
  65. }
  66. ::google::protobuf::uint8* NsheadMessage::SerializeWithCachedSizesToArray(
  67. ::google::protobuf::uint8* target) const {
  68. return target;
  69. }
  70. int NsheadMessage::ByteSize() const {
  71. return sizeof(nshead_t) + body.size();
  72. }
  73. void NsheadMessage::MergeFrom(const ::google::protobuf::Message& from) {
  74. GOOGLE_CHECK_NE(&from, this);
  75. const NsheadMessage* source = dynamic_cast<const NsheadMessage*>(&from);
  76. if (source == NULL) {
  77. LOG(ERROR) << "Can only merge from NsheadMessage";
  78. return;
  79. } else {
  80. MergeFrom(*source);
  81. }
  82. }
  83. void NsheadMessage::MergeFrom(const NsheadMessage& from) {
  84. GOOGLE_CHECK_NE(&from, this);
  85. // No way to merge two nshead messages, just overwrite.
  86. head = from.head;
  87. body = from.body;
  88. }
  89. void NsheadMessage::CopyFrom(const ::google::protobuf::Message& from) {
  90. if (&from == this) return;
  91. Clear();
  92. MergeFrom(from);
  93. }
  94. void NsheadMessage::CopyFrom(const NsheadMessage& from) {
  95. if (&from == this) return;
  96. Clear();
  97. MergeFrom(from);
  98. }
  99. bool NsheadMessage::IsInitialized() const {
  100. return true;
  101. }
  102. void NsheadMessage::Swap(NsheadMessage* other) {
  103. if (other != this) {
  104. const nshead_t tmp = other->head;
  105. other->head = head;
  106. head = tmp;
  107. body.swap(other->body);
  108. }
  109. }
  110. ::google::protobuf::Metadata NsheadMessage::GetMetadata() const {
  111. ::google::protobuf::Metadata metadata;
  112. metadata.descriptor = NsheadMessage::descriptor();
  113. metadata.reflection = NULL;
  114. return metadata;
  115. }
  116. } // namespace brpc