Mercurial > hg > orthanc
changeset 6796:e2241b1bcac8
added BufferHttpSender::SwapBuffer()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Mon, 18 May 2026 12:57:36 +0200 |
| parents | 7872e2d293bb |
| children | 8ac77592226e cdf8b88c60c8 |
| files | OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.h OrthancFramework/Sources/Enumerations.cpp OrthancFramework/Sources/FileStorage/StorageAccessor.cpp OrthancFramework/Sources/HttpServer/BufferHttpSender.cpp OrthancFramework/Sources/HttpServer/BufferHttpSender.h OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp OrthancFramework/Sources/RestApi/RestApiOutput.cpp OrthancFramework/Sources/RestApi/RestApiOutput.h OrthancFramework/UnitTestsSources/StreamTests.cpp |
| diffstat | 10 files changed, 69 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Mon May 18 12:57:36 2026 +0200 @@ -120,22 +120,6 @@ }; - StorageAreaDataSource::StorageAreaDataSource(IPluginStorageArea* area) : - area_(area) - { - if (area == NULL) - { - throw OrthancException(ErrorCode_NullPointer); - } - } - - - IPluginStorageArea& StorageAreaDataSource::GetArea() const - { - assert(area_.get() != NULL); - return *area_; - } - size_t StorageAreaDataSource::GetValueSize(const IDynamicObject& value) const { const Value& tmp = dynamic_cast<const Value&>(value); @@ -145,7 +129,7 @@ IDynamicObject* StorageAreaDataSource::Load(const IDataIdentifier& identifier) { const Identifier& id = dynamic_cast<const Identifier&>(identifier); - return id.Read(*area_); + return id.Read(area_); }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Mon May 18 12:57:36 2026 +0200 @@ -47,12 +47,13 @@ class Identifier; private: - std::unique_ptr<IPluginStorageArea> area_; + IPluginStorageArea& area_; public: - explicit StorageAreaDataSource(IPluginStorageArea* area); - - IPluginStorageArea& GetArea() const; + explicit StorageAreaDataSource(IPluginStorageArea& area) : + area_(area) + { + } virtual size_t GetValueSize(const IDynamicObject& value) const ORTHANC_OVERRIDE;
--- a/OrthancFramework/Sources/Enumerations.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/Enumerations.cpp Mon May 18 12:57:36 2026 +0200 @@ -1765,7 +1765,8 @@ target = MimeType_Jpeg2000; return true; } - else if (source == MIME_JSON) + else if (source == MIME_JSON || + source == MIME_JSON_UTF8) { target = MimeType_Json; return true;
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Mon May 18 12:57:36 2026 +0200 @@ -720,7 +720,9 @@ const FileInfo& info, const std::string& mime) { - Read(sender.GetBuffer(), info); + std::string tmp; + Read(tmp, info); + sender.SwapBuffer(tmp); sender.SetContentType(mime);
--- a/OrthancFramework/Sources/HttpServer/BufferHttpSender.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/BufferHttpSender.cpp Mon May 18 12:57:36 2026 +0200 @@ -37,12 +37,31 @@ { } - std::string &BufferHttpSender::GetBuffer() + void BufferHttpSender::SetBuffer(const std::string& buffer) { - return buffer_; + if (position_ != 0) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + buffer_ = buffer; + } } - const std::string &BufferHttpSender::GetBuffer() const + void BufferHttpSender::SwapBuffer(std::string& buffer) + { + if (position_ != 0) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + buffer_.swap(buffer); + } + } + + const std::string& BufferHttpSender::GetBuffer() const { return buffer_; }
--- a/OrthancFramework/Sources/HttpServer/BufferHttpSender.h Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/BufferHttpSender.h Mon May 18 12:57:36 2026 +0200 @@ -38,7 +38,10 @@ public: BufferHttpSender(); - std::string& GetBuffer(); + void SetBuffer(const std::string& buffer); + + // This flavor is more efficient + void SwapBuffer(std::string& buffer); const std::string& GetBuffer() const;
--- a/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp Mon May 18 12:57:36 2026 +0200 @@ -91,10 +91,12 @@ std::string compressed; ReadSource(compressed); - uncompressed_.reset(new BufferHttpSender); + std::string tmp; + ZlibCompressor compressor; + IBufferCompressor::Uncompress(tmp, compressor, compressed); - ZlibCompressor compressor; - IBufferCompressor::Uncompress(uncompressed_->GetBuffer(), compressor, compressed); + uncompressed_.reset(new BufferHttpSender); + uncompressed_->SwapBuffer(tmp); return HttpCompression_None; }
--- a/OrthancFramework/Sources/RestApi/RestApiOutput.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/RestApi/RestApiOutput.cpp Mon May 18 12:57:36 2026 +0200 @@ -150,6 +150,24 @@ } } + void RestApiOutput::AnswerBuffer(const void* buffer, + size_t length, + const std::string& contentType) + { + MimeType mime; + if (LookupMimeType(mime, contentType)) + { + AnswerBuffer(buffer, length, mime); + } + else + { + CheckStatus(); + output_.SetContentType(contentType); + output_.Answer(buffer, length); + alreadySent_ = true; + } + } + void RestApiOutput::Redirect(const std::string& path) { CheckStatus();
--- a/OrthancFramework/Sources/RestApi/RestApiOutput.h Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/Sources/RestApi/RestApiOutput.h Mon May 18 12:57:36 2026 +0200 @@ -79,6 +79,10 @@ size_t length, MimeType contentType); + void AnswerBuffer(const void* buffer, + size_t length, + const std::string& contentType); + void SetContentFilename(const char* filename); void SignalError(HttpStatus status);
--- a/OrthancFramework/UnitTestsSources/StreamTests.cpp Mon May 18 09:15:19 2026 +0200 +++ b/OrthancFramework/UnitTestsSources/StreamTests.cpp Mon May 18 12:57:36 2026 +0200 @@ -221,7 +221,7 @@ { BufferHttpSender sender; sender.SetChunkSize(cs); - sender.GetBuffer() = s; + sender.SetBuffer(s); ASSERT_TRUE(ReadAllStream(t, sender)); ASSERT_EQ(s, t); } @@ -267,7 +267,7 @@ { BufferHttpSender sender; sender.SetChunkSize(cs); - sender.GetBuffer() = t; + sender.SetBuffer(t); std::string u; ASSERT_TRUE(ReadAllStream(u, sender)); @@ -281,7 +281,7 @@ { BufferHttpSender sender; sender.SetChunkSize(cs); - sender.GetBuffer() = t; + sender.SetBuffer(t); HttpStreamTranscoder transcode(sender, CompressionType_None); @@ -296,7 +296,7 @@ { BufferHttpSender sender; sender.SetChunkSize(cs); - sender.GetBuffer() = t; + sender.SetBuffer(t); HttpStreamTranscoder transcode(sender, CompressionType_ZlibWithSize); @@ -311,7 +311,7 @@ { BufferHttpSender sender; sender.SetChunkSize(cs); - sender.GetBuffer() = t; + sender.SetBuffer(t); HttpStreamTranscoder transcode(sender, CompressionType_ZlibWithSize);
