18 // used with TLVReader::Read*
20 // these are used below to manufacture arguments
21 #define OBJ_READ_ARGS(s,l) s_MDD_Table[MDDindex_##s##_##l], &l
22 #define OBJ_READ_ARGS_R(s,l,r) s_MDD_Table[MDDindex_##s##_##l], &r
24 #define OBJ_WRITE_ARGS(s,l) s_MDD_Table[MDDindex_##s##_##l], &l
26 #define OBJ_TYPE_ARGS(t) s_MDD_Table[MDDindex_##t].ul
33 typedef std::pair<ui32_t, ui32_t> ItemInfo;
34 typedef std::map<TagValue, ItemInfo> TagMap;
37 class TLVReader : public ASDCP::MemIOReader
41 IPrimerLookup* m_Lookup;
44 ASDCP_NO_COPY_CONSTRUCT(TLVReader);
45 bool FindTL(const MDDEntry&);
48 TLVReader(const byte_t* p, ui32_t c, IPrimerLookup* = 0);
49 Result_t ReadObject(const MDDEntry&, IArchive*);
50 Result_t ReadUi8(const MDDEntry&, ui8_t*);
51 Result_t ReadUi16(const MDDEntry&, ui16_t*);
52 Result_t ReadUi32(const MDDEntry&, ui32_t*);
53 Result_t ReadUi64(const MDDEntry&, ui64_t*);
57 class TLVWriter : public ASDCP::MemIOWriter
61 IPrimerLookup* m_Lookup;
64 ASDCP_NO_COPY_CONSTRUCT(TLVWriter);
65 Result_t WriteTag(const MDDEntry&);
68 TLVWriter(byte_t* p, ui32_t c, IPrimerLookup* = 0);
69 Result_t WriteObject(const MDDEntry&, IArchive*);
70 Result_t WriteUi8(const MDDEntry&, ui8_t*);
71 Result_t WriteUi16(const MDDEntry&, ui16_t*);
72 Result_t WriteUi32(const MDDEntry&, ui32_t*);
73 Result_t WriteUi64(const MDDEntry&, ui64_t*);
78 class Batch : public std::vector<T>, public IArchive
84 Batch() : ItemCount(0), ItemSize(0) { ItemSize = sizeof(T); }
88 Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
89 Result_t result = Reader.ReadUi32BE(&ItemCount);
91 if ( ASDCP_SUCCESS(result) )
92 result = Reader.ReadUi32BE(&ItemSize);
94 if ( ( ItemCount > 65536 ) || ( ItemSize > 1024 ) )
97 for ( ui32_t i = 0; i < ItemCount && ASDCP_SUCCESS(result); i++ )
100 result = Tmp.ReadFrom(Reader);
102 if ( ASDCP_SUCCESS(result) )
110 Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
111 Result_t result = Writer.WriteUi32BE(size());
113 if ( ASDCP_SUCCESS(result) )
114 result = Writer.WriteUi32BE(ItemSize);
116 typename std::vector<T>::iterator l_i = begin();
117 for ( ; l_i != end() && ASDCP_SUCCESS(result); l_i++ )
118 result = (*l_i).WriteTo(Writer);
124 void Dump(FILE* stream = 0, ui32_t depth = 0)
126 char identbuf[IdentBufferLen];
131 typename std::vector<T>::iterator i = this->begin();
132 for ( ; i != this->end(); i++ )
133 fprintf(stream, " %s\n", (*i).ToString(identbuf));
139 class Array : public std::list<T>, public IArchive
146 Result_t ReadFrom(ASDCP::MemIOReader& Reader)
148 while ( Reader.Remainder() > 0 )
151 Tmp.ReadFrom(Reader);
159 Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
160 Result_t result = RESULT_OK;
161 typename std::list<T>::iterator l_i = begin();
163 for ( ; l_i != end() && ASDCP_SUCCESS(result); l_i++ )
164 result = (*l_i).WriteTo(Writer);
170 void Dump(FILE* stream = 0, ui32_t depth = 0)
172 char identbuf[IdentBufferLen];
177 typename std::list<T>::iterator i = this->begin();
178 for ( ; i != this->end(); i++ )
179 fprintf(stream, " %s\n", (*i).ToString(identbuf));
184 class Timestamp : public IArchive
196 Year(0), Month(0), Day(0),
197 Hour(0), Minute(0), Second(0), mSec_4(0) {}
200 inline const char* ToString(char* str_buf) const {
201 sprintf(str_buf, "%04hu-%02hu-%02hu %02hu:%02hu:%02hu.%03hu",
202 Year, Month, Day, Hour, Minute, Second, mSec_4);
207 inline Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
208 Result_t result = Reader.ReadUi16BE(&Year);
210 if ( ASDCP_SUCCESS(result) )
211 result = Reader.ReadRaw(&Month, 6);
217 inline Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
218 Result_t result = Writer.WriteUi16BE(Year);
220 if ( ASDCP_SUCCESS(result) )
221 result = Writer.WriteRaw(&Month, 6);
228 class UTF16String : public IArchive
231 char m_buffer[IdentBufferLen];
234 UTF16String() : m_length(0) { *m_buffer = 0; }
238 const char* ToString(char* str_buf) const {
239 strncpy(str_buf, m_buffer, m_length+1);
243 Result_t ReadFrom(ASDCP::MemIOReader& Reader);
244 Result_t WriteTo(ASDCP::MemIOWriter& Writer);
248 class Rational : public ASDCP::Rational, public IArchive
255 const char* ToString(char* str_buf) const {
256 sprintf(str_buf, "%lu/%lu", Numerator, Denominator);
260 Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
261 Result_t result = Reader.ReadUi32BE((ui32_t*)&Numerator);
263 if ( ASDCP_SUCCESS(result) )
264 result = Reader.ReadUi32BE((ui32_t*)&Denominator);
269 Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
270 Result_t result = Writer.WriteUi32BE((ui32_t)Numerator);
272 if ( ASDCP_SUCCESS(result) )
273 result = Writer.WriteUi32BE((ui32_t)Denominator);