Apache Mesos
parse.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __V1_PARSE_HPP__
14 #define __V1_PARSE_HPP__
15 
16 #include <stout/error.hpp>
17 #include <stout/json.hpp>
18 #include <stout/protobuf.hpp>
19 #include <stout/try.hpp>
20 
21 #include <stout/flags/parse.hpp>
22 
23 #include <mesos/v1/mesos.hpp>
24 
25 namespace flags {
26 
27 template <>
28 inline Try<mesos::v1::CapabilityInfo> parse(const std::string& value)
29 {
30  Try<JSON::Object> json = parse<JSON::Object>(value);
31  if (json.isError()) {
32  return Error(json.error());
33  }
34 
35  return protobuf::parse<mesos::v1::CapabilityInfo>(json.get());
36 }
37 
38 
39 template <>
40 inline Try<mesos::v1::RLimitInfo> parse(const std::string& value)
41 {
42  Try<JSON::Object> json = parse<JSON::Object>(value);
43  if (json.isError()) {
44  return Error(json.error());
45  }
46 
47  return protobuf::parse<mesos::v1::RLimitInfo>(json.get());
48 }
49 
50 
51 template <>
52 inline Try<mesos::v1::TaskGroupInfo> parse(const std::string& value)
53 {
54  // Convert from string or file to JSON.
55  Try<JSON::Object> json = parse<JSON::Object>(value);
56  if (json.isError()) {
57  return Error(json.error());
58  }
59 
60  // Convert from JSON to Protobuf.
61  return protobuf::parse<mesos::v1::TaskGroupInfo>(json.get());
62 }
63 
64 
65 template <>
66 inline Try<mesos::v1::TaskInfo> parse(const std::string& value)
67 {
68  // Convert from string or file to JSON.
69  Try<JSON::Object> json = parse<JSON::Object>(value);
70  if (json.isError()) {
71  return Error(json.error());
72  }
73 
74  // Convert from JSON to Protobuf.
75  return protobuf::parse<mesos::v1::TaskInfo>(json.get());
76 }
77 
78 } // namespace flags {
79 
80 #endif // __V1_PARSE_HPP__
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
Definition: check.hpp:33
void json(JSON::ObjectWriter *writer, const asV1Protobuf &protobuf)
Try< mesos::ACLs > parse(const std::string &value)
Returns the OCI v1 descriptor, image index, image manifest and image configuration from the given str...
Definition: parse.hpp:36
static Try error(const E &e)
Definition: try.hpp:43
bool isError() const
Definition: try.hpp:78
Definition: parse.hpp:33