1 // Copyright 2021 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 // 15 // The header provides a set of helper utils for protobuf related operations. 16 // The APIs may not be finalized yet. 17 18 #pragma once 19 20 #include "pw_result/result.h" 21 22 namespace pw::protobuf::internal { 23 24 // A base class for representing parsed proto integer types or an error code 25 // to indicate parsing failure. 26 template <typename Integer> 27 class ProtoIntegerBase { 28 public: ProtoIntegerBase(Result<Integer> value)29 constexpr ProtoIntegerBase(Result<Integer> value) : value_(value) {} ProtoIntegerBase(Status status)30 constexpr ProtoIntegerBase(Status status) : value_(status) {} 31 ok()32 bool ok() { return value_.ok(); } status()33 Status status() { return value_.status(); } value()34 Integer value() { return value_.value(); } 35 36 private: 37 Result<Integer> value_ = 0; 38 }; 39 40 } // namespace pw::protobuf::internal 41