From: Dave Watson Date: Thu, 9 Apr 2015 16:59:36 +0000 (-0700) Subject: Move StringHandler to its own file X-Git-Tag: v0.35.0~2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e426c673e9cf39a1cf9011bebbee540b775a0911;p=folly.git Move StringHandler to its own file Summary: Move this from a test to its own file in codec folder Test Plan: already has a unittest fbconfig -r folly/wangle; fbmake runtests Reviewed By: hans@fb.com Subscribers: doug, fugalh, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D1959152 Signature: t1:1959152:1427935371:9d1338986df97fd94f98ad2bf08c731d229bc2b1 --- diff --git a/folly/wangle/codec/StringCodec.h b/folly/wangle/codec/StringCodec.h new file mode 100644 index 00000000..0f8c96d4 --- /dev/null +++ b/folly/wangle/codec/StringCodec.h @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace folly { namespace wangle { + +/* + * StringCodec converts a pipeline from IOBufs to std::strings. + */ +class StringCodec : public ChannelHandler> { + public: + typedef typename ChannelHandler< + IOBufQueue&, std::string, + std::string, std::unique_ptr>::Context Context; + + void read(Context* ctx, IOBufQueue& q) override { + auto buf = q.pop_front(); + buf->coalesce(); + std::string data((const char*)buf->data(), buf->length()); + + ctx->fireRead(data); + } + + Future write(Context* ctx, std::string msg) override { + auto buf = IOBuf::copyBuffer(msg.data(), msg.length()); + return ctx->fireWrite(std::move(buf)); + } +}; + +}} // namespace diff --git a/folly/wangle/service/ClientDispatcher.h b/folly/wangle/service/ClientDispatcher.h index a42a74f4..f0a5e89c 100644 --- a/folly/wangle/service/ClientDispatcher.h +++ b/folly/wangle/service/ClientDispatcher.h @@ -16,6 +16,7 @@ #pragma once #include +#include namespace folly { namespace wangle { diff --git a/folly/wangle/service/ServerDispatcher.h b/folly/wangle/service/ServerDispatcher.h index 7ec3a4dc..8152dc60 100644 --- a/folly/wangle/service/ServerDispatcher.h +++ b/folly/wangle/service/ServerDispatcher.h @@ -16,6 +16,7 @@ #pragma once #include +#include namespace folly { namespace wangle { diff --git a/folly/wangle/service/ServiceTest.cpp b/folly/wangle/service/ServiceTest.cpp index 8c1c8314..843f80d0 100644 --- a/folly/wangle/service/ServiceTest.cpp +++ b/folly/wangle/service/ServiceTest.cpp @@ -15,9 +15,10 @@ */ #include -#include -#include +#include #include +#include +#include namespace folly { @@ -39,27 +40,6 @@ class EchoIntService : public Service { } }; -class StringCodec : public ChannelHandler> { - public: - typedef typename ChannelHandler< - IOBufQueue&, std::string, - std::string, std::unique_ptr>::Context Context; - - void read(Context* ctx, IOBufQueue& q) override { - auto buf = q.pop_front(); - buf->coalesce(); - std::string data((const char*)buf->data(), buf->length()); - - ctx->fireRead(data); - } - - Future write(Context* ctx, std::string msg) override { - auto buf = IOBuf::copyBuffer(msg.data(), msg.length()); - return ctx->fireWrite(std::move(buf)); - } -}; - template class ServerPipelineFactory : public PipelineFactory {