serialized_request.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef BRPC_SERIALIZED_REQUEST_H
  18. #define BRPC_SERIALIZED_REQUEST_H
  19. #include <google/protobuf/message.h>
  20. #include "butil/iobuf.h"
  21. #include "brpc/proto_base.pb.h"
  22. namespace brpc {
  23. class SerializedRequest : public ::google::protobuf::Message {
  24. public:
  25. SerializedRequest();
  26. virtual ~SerializedRequest();
  27. SerializedRequest(const SerializedRequest& from);
  28. inline SerializedRequest& operator=(const SerializedRequest& from) {
  29. CopyFrom(from);
  30. return *this;
  31. }
  32. static const ::google::protobuf::Descriptor* descriptor();
  33. void Swap(SerializedRequest* other);
  34. // implements Message ----------------------------------------------
  35. SerializedRequest* New() const;
  36. void CopyFrom(const ::google::protobuf::Message& from);
  37. void CopyFrom(const SerializedRequest& from);
  38. void Clear();
  39. bool IsInitialized() const;
  40. int ByteSize() const;
  41. int GetCachedSize() const { return (int)_serialized.size(); }
  42. butil::IOBuf& serialized_data() { return _serialized; }
  43. const butil::IOBuf& serialized_data() const { return _serialized; }
  44. protected:
  45. ::google::protobuf::Metadata GetMetadata() const;
  46. private:
  47. bool MergePartialFromCodedStream(
  48. ::google::protobuf::io::CodedInputStream* input);
  49. void SerializeWithCachedSizes(
  50. ::google::protobuf::io::CodedOutputStream* output) const;
  51. ::google::protobuf::uint8* SerializeWithCachedSizesToArray(
  52. ::google::protobuf::uint8* output) const;
  53. void MergeFrom(const ::google::protobuf::Message& from);
  54. void MergeFrom(const SerializedRequest& from);
  55. void SharedCtor();
  56. void SharedDtor();
  57. void SetCachedSize(int size) const;
  58. private:
  59. butil::IOBuf _serialized;
  60. };
  61. } // namespace brpc
  62. #endif // BRPC_SERIALIZED_REQUEST_H