1/**
2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef GLOW_EXPORTER_PROTOBUFWRITER_H
18#define GLOW_EXPORTER_PROTOBUFWRITER_H
19
20#include "glow/Graph/Graph.h"
21#include "glow/Support/Error.h"
22
23#include <fstream>
24#include <google/protobuf/text_format.h>
25
26namespace glow {
27/// Writes model: graph and weights.
28class ProtobufWriter {
29protected:
30 /// The graph that we are constructing.
31 Function *F_;
32 /// Output file stream.
33 std::ofstream ff_;
34
35 Error writeModel(const ::google::protobuf::Message &modelProto,
36 bool textMode = false);
37
38public:
39 /// Constructs new ProtobufWriter object. It will write protopuf messages into
40 /// \p modelFilename using graph and constants from \p F.
41 /// If \p errPtr is not null then if an error occurs it will get assigned
42 /// there otherwise if an error occurs it will abort.
43 ProtobufWriter(const std::string &modelFilename, Function *F,
44 Error *errPtr = nullptr, bool writingToFile = true);
45};
46
47} // namespace glow
48
49#endif // GLOW_EXPORTER_PROTOBUFWRITER_H
50