add-arcadia-stream-support.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --- a/src/google/protobuf/message.cc (index)
  2. +++ b/src/google/protobuf/message.cc (working tree)
  3. @@ -146,6 +146,52 @@ uint8* Message::_InternalSerialize(uint8* target,
  4. return WireFormat::_InternalSerialize(*this, target, stream);
  5. }
  6. +// Yandex-specific
  7. +void Message::PrintJSON(IOutputStream& out) const {
  8. + out << "(Something went wrong: no PrintJSON() override provided - are you using a non-styleguided .pb.h?)";
  9. +}
  10. +
  11. +bool Message::ParseFromArcadiaStream(IInputStream* input) {
  12. + bool res = false;
  13. + io::TInputStreamProxy proxy(input);
  14. + {
  15. + io::CopyingInputStreamAdaptor stream(&proxy);
  16. + res = ParseFromZeroCopyStream(&stream);
  17. + }
  18. + return res && !proxy.HasError();
  19. +}
  20. +
  21. +bool Message::ParsePartialFromArcadiaStream(IInputStream* input) {
  22. + bool res = false;
  23. + io::TInputStreamProxy proxy(input);
  24. + {
  25. + io::CopyingInputStreamAdaptor stream(&proxy);
  26. + res = ParsePartialFromZeroCopyStream(&stream);
  27. + }
  28. + return res && !proxy.HasError();
  29. +}
  30. +
  31. +bool Message::SerializeToArcadiaStream(IOutputStream* output) const {
  32. + bool res = false;
  33. + io::TOutputStreamProxy proxy(output);
  34. + {
  35. + io::CopyingOutputStreamAdaptor stream(&proxy);
  36. + res = SerializeToZeroCopyStream(&stream);
  37. + }
  38. + return res && !proxy.HasError();
  39. +}
  40. +
  41. +bool Message::SerializePartialToArcadiaStream(IOutputStream* output) const {
  42. + bool res = false;
  43. + io::TOutputStreamProxy proxy(output);
  44. + {
  45. + io::CopyingOutputStreamAdaptor stream(&proxy);
  46. + res = SerializePartialToZeroCopyStream(&stream);
  47. + }
  48. + return res && !proxy.HasError();
  49. +}
  50. +// End of Yandex-specific
  51. +
  52. size_t Message::ByteSizeLong() const {
  53. size_t size = WireFormat::ByteSize(*this);
  54. SetCachedSize(internal::ToCachedSize(size));
  55. --- a/src/google/protobuf/message.h (index)
  56. +++ b/src/google/protobuf/message.h (working tree)
  57. @@ -126,6 +126,8 @@
  58. #include "google/protobuf/generated_message_reflection.h"
  59. #include "google/protobuf/generated_message_tctable_decl.h"
  60. #include "google/protobuf/generated_message_util.h"
  61. +#include <google/protobuf/json_util.h>
  62. +#include <google/protobuf/messagext.h>
  63. #include "google/protobuf/map.h" // TODO(b/211442718): cleanup
  64. #include "google/protobuf/message_lite.h"
  65. #include "google/protobuf/port.h"
  66. @@ -341,6 +341,27 @@ class PROTOBUF_EXPORT Message : public MessageLite {
  67. uint8_t* _InternalSerialize(uint8_t* target,
  68. io::EpsCopyOutputStream* stream) const override;
  69. + // Yandex-specific
  70. + bool ParseFromArcadiaStream(IInputStream* input);
  71. + bool ParsePartialFromArcadiaStream(IInputStream* input);
  72. + bool SerializeToArcadiaStream(IOutputStream* output) const;
  73. + bool SerializePartialToArcadiaStream(IOutputStream* output) const;
  74. +
  75. + virtual void PrintJSON(IOutputStream&) const;
  76. +
  77. + io::TAsJSON<Message> AsJSON() const {
  78. + return io::TAsJSON<Message>(*this);
  79. + }
  80. +
  81. + internal::TAsBinary AsBinary() const {
  82. + return internal::TAsBinary{*this};
  83. + }
  84. +
  85. + internal::TAsStreamSeq AsStreamSeq() const {
  86. + return internal::TAsStreamSeq{*this};
  87. + }
  88. + // End of Yandex-specific
  89. +
  90. private:
  91. // This is called only by the default implementation of ByteSize(), to
  92. // update the cached size. If you override ByteSize(), you do not need