IWAMessage.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libetonyek project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef IWAMESSAGE_H_INCLUDED
11 #define IWAMESSAGE_H_INCLUDED
12
13 #include <map>
14 #include <utility>
15
16 #include "IWAField.h"
17
18 namespace libetonyek
19 {
20
21 class IWAMessage
22 {
23 public:
24 IWAMessage();
25 IWAMessage(const RVNGInputStreamPtr_t &input, unsigned long length);
26 IWAMessage(const RVNGInputStreamPtr_t &input, long start, long end);
27
28 const IWAUInt32Field &uint32(std::size_t field) const;
29 const IWAUInt64Field &uint64(std::size_t field) const;
30 const IWASInt32Field &sint32(std::size_t field) const;
31 const IWASInt64Field &sint64(std::size_t field) const;
32 const IWABoolField &bool_(std::size_t field) const;
33
34 const IWAFixed64Field &fixed64(std::size_t field) const;
35 const IWADoubleField &double_(std::size_t field) const;
36
37 const IWAStringField &string(std::size_t field) const;
38 const IWABytesField &bytes(std::size_t field) const;
39 const IWAMessageField &message(std::size_t field) const;
40
41 const IWAFixed32Field &fixed32(std::size_t field) const;
42 const IWAFloatField &float_(std::size_t field) const;
43
44 private:
45 enum WireType
46 {
47 WIRE_TYPE_VARINT,
48 WIRE_TYPE_64_BIT,
49 WIRE_TYPE_LENGTH_DELIMITED,
50 WIRE_TYPE_32_BIT = 5
51 };
52
53 typedef std::pair<long, long> InputRange_t;
54
55 struct Field
56 {
57 explicit Field(WireType wireType);
58
59 WireType m_wireType;
60 std::deque<InputRange_t> m_pieces;
61 IWAFieldPtr_t m_realField;
62 };
63
64 typedef std::map<unsigned, Field> FieldList_t;
65
66 private:
67 void parse(unsigned long length);
68
69 template<typename FieldT>
70 const FieldT &getField(std::size_t field, WireType wireType, IWAField::Tag tag) const;
71
72 private:
73 RVNGInputStreamPtr_t m_input;
74 mutable FieldList_t m_fields;
75 };
76
77 }
78
79 #endif
80
81 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWORKToken::start
Definition: IWORKToken.h:405
libetonyek
Definition: IWORKBezierElement.cpp:20
libetonyek::IWAMessage::string
const IWAStringField & string(std::size_t field) const
Definition: IWAMessage.cpp:157
libetonyek::IWAMessage::message
const IWAMessageField & message(std::size_t field) const
Definition: IWAMessage.cpp:167
libetonyek::IWAMessage::fixed64
const IWAFixed64Field & fixed64(std::size_t field) const
Definition: IWAMessage.cpp:147
libetonyek::IWAMessage::IWAMessage
IWAMessage()
Definition: IWAMessage.cpp:35
libetonyek::IWAMessage::m_fields
FieldList_t m_fields
Definition: IWAMessage.h:74
libetonyek::IWAMessage::parse
void parse(unsigned long length)
Definition: IWAMessage.cpp:61
libetonyek::IWAMessage::sint64
const IWASInt64Field & sint64(std::size_t field) const
Definition: IWAMessage.cpp:137
libetonyek::IWAMessage::Field::Field
Field(WireType wireType)
Definition: IWAMessage.cpp:28
libetonyek::IWAMessage::getField
const FieldT & getField(std::size_t field, WireType wireType, IWAField::Tag tag) const
Definition: IWAMessage.cpp:183
libetonyek::IWAMessage::double_
const IWADoubleField & double_(std::size_t field) const
Definition: IWAMessage.cpp:152
libetonyek::IWAMessage::uint32
const IWAUInt32Field & uint32(std::size_t field) const
Definition: IWAMessage.cpp:122
libetonyek::IWAMessage::InputRange_t
std::pair< long, long > InputRange_t
Definition: IWAMessage.h:53
libetonyek::IWAMessage::WireType
WireType
Definition: IWAMessage.h:45
libetonyek::IWAMessage::WIRE_TYPE_64_BIT
Definition: IWAMessage.h:48
libetonyek::IWORKToken::end
Definition: IWORKToken.h:189
libetonyek::IWAMessage::bool_
const IWABoolField & bool_(std::size_t field) const
Definition: IWAMessage.cpp:142
libetonyek::IWAMessage::float_
const IWAFloatField & float_(std::size_t field) const
Definition: IWAMessage.cpp:177
libetonyek::IWAMessage::Field::m_pieces
std::deque< InputRange_t > m_pieces
Definition: IWAMessage.h:60
libetonyek::IWAField::Tag
Tag
Definition: IWAField.h:29
libetonyek::IWAMessage::WIRE_TYPE_32_BIT
Definition: IWAMessage.h:50
libetonyek::IWAMessage::WIRE_TYPE_VARINT
Definition: IWAMessage.h:47
libetonyek::RVNGInputStreamPtr_t
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:82
libetonyek::detail::IWAFieldImpl
Definition: IWAField.h:73
libetonyek::IWAMessageField
Definition: IWAField.h:222
libetonyek::IWAMessage::fixed32
const IWAFixed32Field & fixed32(std::size_t field) const
Definition: IWAMessage.cpp:172
libetonyek::IWAMessage
Definition: IWAMessage.h:21
libetonyek::IWAMessage::uint64
const IWAUInt64Field & uint64(std::size_t field) const
Definition: IWAMessage.cpp:127
IWAField.h
libetonyek::IWAMessage::WIRE_TYPE_LENGTH_DELIMITED
Definition: IWAMessage.h:49
libetonyek::IWAMessage::Field
Definition: IWAMessage.h:55
libetonyek::IWAMessage::Field::m_realField
IWAFieldPtr_t m_realField
Definition: IWAMessage.h:61
libetonyek::IWAMessage::FieldList_t
std::map< unsigned, Field > FieldList_t
Definition: IWAMessage.h:64
libetonyek::IWAMessage::Field::m_wireType
WireType m_wireType
Definition: IWAMessage.h:59
libetonyek::IWAFieldPtr_t
std::shared_ptr< IWAField > IWAFieldPtr_t
Definition: IWAField.h:67
libetonyek::IWAMessage::bytes
const IWABytesField & bytes(std::size_t field) const
Definition: IWAMessage.cpp:162
libetonyek::IWAMessage::m_input
RVNGInputStreamPtr_t m_input
Definition: IWAMessage.h:73
libetonyek::IWAMessage::sint32
const IWASInt32Field & sint32(std::size_t field) const
Definition: IWAMessage.cpp:132