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#ifndef _HDFS_LIBHDFS3_CLIENT_PIPELINEACK_H_
29#define _HDFS_LIBHDFS3_CLIENT_PIPELINEACK_H_
30
31#include "datatransfer.pb.h"
32
33namespace Hdfs {
34namespace Internal {
35
36class PipelineAck {
37public:
38 PipelineAck() :
39 invalid(true) {
40 }
41
42 PipelineAck(const char * buf, int size) :
43 invalid(false) {
44 readFrom(buf, size);
45 }
46
47 bool isInvalid() {
48 return invalid;
49 }
50
51 int getNumOfReplies() {
52 return proto.status_size();
53 }
54
55 int64_t getSeqno() {
56 return proto.seqno();
57 }
58
59 Status getReply(int i) {
60 return proto.status(i);
61 }
62
63 bool isSuccess() {
64 int size = proto.status_size();
65
66 for (int i = 0; i < size; ++i) {
67 if (Status::DT_PROTO_SUCCESS != proto.status(i)) {
68 return false;
69 }
70 }
71
72 return true;
73 }
74
75 void readFrom(const char * buf, int size) {
76 invalid = !proto.ParseFromArray(buf, size);
77 }
78
79 void reset() {
80 proto.Clear();
81 invalid = true;
82 }
83
84private:
85 PipelineAckProto proto;
86 bool invalid;
87};
88
89}
90}
91
92#endif /* _HDFS_LIBHDFS3_CLIENT_PIPELINEACK_H_ */
93