/src/opendnp3/cpp/lib/src/app/Serializer.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2013-2022 Step Function I/O, LLC |
3 | | * |
4 | | * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O |
5 | | * LLC (https://stepfunc.io) under one or more contributor license agreements. |
6 | | * See the NOTICE file distributed with this work for additional information |
7 | | * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license |
8 | | * this file to you under the Apache License, Version 2.0 (the "License"); you |
9 | | * may not use this file except in compliance with the License. You may obtain |
10 | | * a copy of the License at: |
11 | | * |
12 | | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | | * |
14 | | * Unless required by applicable law or agreed to in writing, software |
15 | | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | | * See the License for the specific language governing permissions and |
18 | | * limitations under the License. |
19 | | */ |
20 | | #ifndef OPENDNP3_SERIALIZER_H |
21 | | #define OPENDNP3_SERIALIZER_H |
22 | | |
23 | | #include <ser4cpp/container/SequenceTypes.h> |
24 | | |
25 | | namespace opendnp3 |
26 | | { |
27 | | |
28 | | template<class T> class Serializer |
29 | | { |
30 | | public: |
31 | | using read_func_t = bool (*)(ser4cpp::rseq_t& buffer, T& output); |
32 | | using write_func_t = bool (*)(const T& value, ser4cpp::wseq_t& buffer); |
33 | | |
34 | 0 | Serializer() = default; Unexecuted instantiation: opendnp3::Serializer<opendnp3::ControlRelayOutputBlock>::Serializer() Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt32>::Serializer() Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt16>::Serializer() Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputFloat32>::Serializer() Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputDouble64>::Serializer() |
35 | | |
36 | | Serializer(size_t size, read_func_t read_func, write_func_t write_func) |
37 | 0 | : size(size), read_func(read_func), write_func(write_func) |
38 | 0 | { |
39 | 0 | } Unexecuted instantiation: opendnp3::Serializer<opendnp3::TimeAndInterval>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::TimeAndInterval&), bool (*)(opendnp3::TimeAndInterval const&, ser4cpp::WSeq<unsigned long>&)) Unexecuted instantiation: opendnp3::Serializer<opendnp3::ControlRelayOutputBlock>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::ControlRelayOutputBlock&), bool (*)(opendnp3::ControlRelayOutputBlock const&, ser4cpp::WSeq<unsigned long>&)) Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt32>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::AnalogOutputInt32&), bool (*)(opendnp3::AnalogOutputInt32 const&, ser4cpp::WSeq<unsigned long>&)) Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt16>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::AnalogOutputInt16&), bool (*)(opendnp3::AnalogOutputInt16 const&, ser4cpp::WSeq<unsigned long>&)) Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputFloat32>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::AnalogOutputFloat32&), bool (*)(opendnp3::AnalogOutputFloat32 const&, ser4cpp::WSeq<unsigned long>&)) Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputDouble64>::Serializer(unsigned long, bool (*)(ser4cpp::RSeq<unsigned long>&, opendnp3::AnalogOutputDouble64&), bool (*)(opendnp3::AnalogOutputDouble64 const&, ser4cpp::WSeq<unsigned long>&)) |
40 | | |
41 | | /** |
42 | | * @return The size (in bytes) required for every call to read/write |
43 | | */ |
44 | | size_t get_size() const |
45 | 0 | { |
46 | 0 | return size; |
47 | 0 | } Unexecuted instantiation: opendnp3::Serializer<opendnp3::TimeAndInterval>::get_size() const Unexecuted instantiation: opendnp3::Serializer<opendnp3::ControlRelayOutputBlock>::get_size() const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt32>::get_size() const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt16>::get_size() const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputFloat32>::get_size() const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputDouble64>::get_size() const |
48 | | |
49 | | /** |
50 | | * reads the value and advances the read buffer |
51 | | */ |
52 | | bool read(ser4cpp::rseq_t& buffer, T& output) const |
53 | | { |
54 | | return (*read_func)(buffer, output); |
55 | | } |
56 | | |
57 | | /** |
58 | | * writes the value and advances the write buffer |
59 | | */ |
60 | | bool write(const T& value, ser4cpp::wseq_t& buffer) const |
61 | 0 | { |
62 | 0 | return (*write_func)(value, buffer); |
63 | 0 | } Unexecuted instantiation: opendnp3::Serializer<opendnp3::TimeAndInterval>::write(opendnp3::TimeAndInterval const&, ser4cpp::WSeq<unsigned long>&) const Unexecuted instantiation: opendnp3::Serializer<opendnp3::ControlRelayOutputBlock>::write(opendnp3::ControlRelayOutputBlock const&, ser4cpp::WSeq<unsigned long>&) const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt32>::write(opendnp3::AnalogOutputInt32 const&, ser4cpp::WSeq<unsigned long>&) const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputInt16>::write(opendnp3::AnalogOutputInt16 const&, ser4cpp::WSeq<unsigned long>&) const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputFloat32>::write(opendnp3::AnalogOutputFloat32 const&, ser4cpp::WSeq<unsigned long>&) const Unexecuted instantiation: opendnp3::Serializer<opendnp3::AnalogOutputDouble64>::write(opendnp3::AnalogOutputDouble64 const&, ser4cpp::WSeq<unsigned long>&) const |
64 | | |
65 | | private: |
66 | | size_t size = 0; |
67 | | read_func_t read_func = nullptr; |
68 | | write_func_t write_func = nullptr; |
69 | | }; |
70 | | } // namespace opendnp3 |
71 | | |
72 | | #endif |