1 // Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef OTS_GRAPHITE_H_
6 #define OTS_GRAPHITE_H_
13 template<typename ParentType
>
16 TablePart(ParentType
* parent
) : parent(parent
) { }
17 virtual ~TablePart() { }
18 virtual bool ParsePart(Buffer
& table
) = 0;
19 virtual bool SerializePart(OTSStream
* out
) const = 0;
25 bool SerializeParts(const std::vector
<T
>& vec
, OTSStream
* out
) {
26 for (const T
& part
: vec
) {
27 if (!part
.SerializePart(out
)) {
35 bool SerializeParts(const std::vector
<std::vector
<T
>>& vec
, OTSStream
* out
) {
36 for (const std::vector
<T
>& part
: vec
) {
37 if (!SerializeParts(part
, out
)) {
44 inline bool SerializeParts(const std::vector
<uint8_t>& vec
, OTSStream
* out
) {
45 for (uint8_t part
: vec
) {
46 if (!out
->WriteU8(part
)) {
53 inline bool SerializeParts(const std::vector
<uint16_t>& vec
, OTSStream
* out
) {
54 for (uint16_t part
: vec
) {
55 if (!out
->WriteU16(part
)) {
62 inline bool SerializeParts(const std::vector
<int16_t>& vec
, OTSStream
* out
) {
63 for (int16_t part
: vec
) {
64 if (!out
->WriteS16(part
)) {
71 inline bool SerializeParts(const std::vector
<uint32_t>& vec
, OTSStream
* out
) {
72 for (uint32_t part
: vec
) {
73 if (!out
->WriteU32(part
)) {
80 inline bool SerializeParts(const std::vector
<int32_t>& vec
, OTSStream
* out
) {
81 for (int32_t part
: vec
) {
82 if (!out
->WriteS32(part
)) {
90 size_t datasize(std::vector
<T
> vec
) {
91 return sizeof(T
) * vec
.size();
96 #endif // OTS_GRAPHITE_H_