2 * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "encode_metadata.h"
23 static const int FIELD_NUM_WIDTH = 2;
25 encode_metadata_record(ResourceStorage& storage, const MetaData_Record& metadata_record ) {
26 storage.put(metadata_record.m_name);
27 unsigned short field_num = metadata_record.vField.size();
28 storage.put<sint_t>(field_num, FIELD_NUM_WIDTH);
30 std::vector<MetaData_Field>::const_iterator it;
31 for (it = metadata_record.vField.begin(); it != metadata_record.vField.end(); ++it) {
32 storage.put(it->m_name);
33 storage.put(it->m_type);
34 storage.put<sint_t>(it->m_width, FIELD_SIZE_WIDTH);
38 encode_metadata(ResourceStorage& storage, const MetaData& metadata ) {
39 int init_size = storage.get_size();
42 storage.put(metadata.m_version);
44 unsigned short size = metadata.m_vec_metadata_record.size();
45 storage.put<sint_t>(size, RECORD_SIZE_WIDTH);
47 for (int i = 0; i < size; ++i) {
48 encode_metadata_record(storage, metadata.m_vec_metadata_record.at(i));
51 int block_size = storage.get_size() - init_size;
52 storage.random_put<sint_t>(block_size, 8, init_size);