1 | /******************************************************************** |
2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
3 | * All rights reserved. |
4 | * |
5 | * Author: Zhanwei Wang |
6 | ********************************************************************/ |
7 | /******************************************************************** |
8 | * 2014 - |
9 | * open source under Apache License Version 2.0 |
10 | ********************************************************************/ |
11 | /** |
12 | * Licensed to the Apache Software Foundation (ASF) under one |
13 | * or more contributor license agreements. See the NOTICE file |
14 | * distributed with this work for additional information |
15 | * regarding copyright ownership. The ASF licenses this file |
16 | * to you under the Apache License, Version 2.0 (the |
17 | * "License"); you may not use this file except in compliance |
18 | * with the License. You may obtain a copy of the License at |
19 | * |
20 | * http://www.apache.org/licenses/LICENSE-2.0 |
21 | * |
22 | * Unless required by applicable law or agreed to in writing, software |
23 | * distributed under the License is distributed on an "AS IS" BASIS, |
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
25 | * See the License for the specific language governing permissions and |
26 | * limitations under the License. |
27 | */ |
28 | #include <google/protobuf/io/coded_stream.h> |
29 | |
30 | #include "RpcContentWrapper.h" |
31 | |
32 | using namespace ::google::protobuf; |
33 | using namespace ::google::protobuf::io; |
34 | |
35 | namespace Hdfs { |
36 | namespace Internal { |
37 | |
38 | RpcContentWrapper::RpcContentWrapper(Message * , Message * msg) : |
39 | header(header), msg(msg) { |
40 | } |
41 | |
42 | int RpcContentWrapper::getLength() { |
43 | int , msgLen = 0; |
44 | headerLen = header->ByteSize(); |
45 | msgLen = msg == NULL ? 0 : msg->ByteSize(); |
46 | return headerLen + CodedOutputStream::VarintSize32(headerLen) |
47 | + (msg == NULL ? |
48 | 0 : msgLen + CodedOutputStream::VarintSize32(msgLen)); |
49 | } |
50 | |
51 | void RpcContentWrapper::writeTo(WriteBuffer & buffer) { |
52 | int size = header->ByteSize(); |
53 | buffer.writeVarint32(size); |
54 | header->SerializeToArray(buffer.alloc(size), size); |
55 | |
56 | if (msg != NULL) { |
57 | size = msg->ByteSize(); |
58 | buffer.writeVarint32(size); |
59 | msg->SerializeToArray(buffer.alloc(size), size); |
60 | } |
61 | } |
62 | |
63 | } |
64 | } |
65 | |
66 | |