ONE - On-device Neural Engine
Loading...
Searching...
No Matches
EncodeCommand.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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#include "EncodeCommand.h"
18
19#include <caffe/proto/caffe.pb.h>
20
21#include <google/protobuf/io/coded_stream.h>
22#include <google/protobuf/io/zero_copy_stream_impl.h>
23#include <google/protobuf/text_format.h>
24
25#include <iostream>
26
27int EncodeCommand::run(int, const char *const *) const
28{
29 caffe::NetParameter param;
30
31 // Load text from standard input
32 google::protobuf::io::IstreamInputStream is{&std::cin};
33
34 if (!google::protobuf::TextFormat::Parse(&is, &param))
35 {
36 std::cerr << "ERROR: Failed to parse prototxt" << std::endl;
37 return 255;
38 }
39
40 // Write binary into standard output
41 google::protobuf::io::OstreamOutputStream os{&std::cout};
42 google::protobuf::io::CodedOutputStream coded_os{&os};
43
44 if (!param.SerializeToCodedStream(&coded_os))
45 {
46 std::cerr << "ERROR: Failed to serialize" << std::endl;
47 return 255;
48 }
49
50 return 0;
51}
int run(int argc, const char *const *argv) const override