10#include "lcf/dbstring.h"
27 static void ReadLcf(DBString& ref, LcfReader& stream, uint32_t length);
28 static void WriteLcf(
const DBString& ref, LcfWriter& stream);
29 static int LcfSize(
const DBString& ref, LcfWriter& stream);
30 static void WriteXml(
const DBString& ref, XmlWriter& stream);
31 static void BeginXml(DBString& ref, XmlReader& stream);
36 static void ReadLcf(std::vector<DBString>& ref, LcfReader& stream, uint32_t length);
37 static void WriteLcf(
const std::vector<DBString>& ref, LcfWriter& stream);
38 static int LcfSize(
const std::vector<DBString>& ref, LcfWriter& stream);
39 static void WriteXml(
const std::vector<DBString>& ref, XmlWriter& stream);
40 static void BeginXml(std::vector<DBString>& ref, XmlReader& stream);
44 stream.ReadString(ref, length);
46 printf(
" %s\n", ref.c_str());
55 return stream.Decode(ref).size();
68 void StartElement(XmlReader& stream,
const char* name,
const char** ) {
87 uint32_t startpos = stream.Tell();
88 uint32_t endpos = startpos + length;
89 while (stream.Tell() < endpos) {
92 auto size = stream.ReadUInt64();
93 if (size > std::numeric_limits<uint32_t>::max()) {
94 index +=
static_cast<uint32_t
>(0x800000000 - size);
98 stream.ReadString(string_var, size);
100 fprintf(stderr,
"t[%d]: %s\n", index + 1, string_var.c_str());
102 ref.push_back(string_var);
108 if (stream.Tell() != endpos) {
109#ifdef LCF_DEBUG_TRACE
110 fprintf(stderr,
"Misaligned!\n");
119 for (
size_t i = 0; i < ref.size(); ++i) {
120 const auto& e = ref[i];
127 stream.WriteUInt64(0x800000000 -
static_cast<uint64_t
>(gap_size));
132 stream.WriteInt(len);
141 for (
size_t i = 0; i < ref.size(); ++i) {
142 const auto& e = ref[i];
149 result += LcfReader::UInt64Size(0x800000000 -
static_cast<uint64_t
>(gap_size));
154 result += LcfReader::IntSize(size);
162 for (
size_t i = 0; i < ref.size(); ++i) {
163 const auto& e = ref[i];
168 stream.BeginElement(
"item", i + 1);
170 stream.EndElement(
"item");
178 void StartElement(XmlReader& stream,
const char* name,
const char** atts) {
179 if (strcmp(name,
"item") != 0) {
180 stream.Error(
"Expecting %s but got %s",
"item", name);
186 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
187 if (strcmp(atts[i],
"id") == 0) {
188 id = atoi(atts[i + 1]);
193 if (
id <= last_id ||
id < -1) {
194 stream.Error(
"Bad Id %d / %d",
id, last_id);
199 DBString& obj =
ref.back();
204 std::vector<DBString>&
ref;
std::vector< DBString > & ref
DbStringVectorXmlHandler(std::vector< DBString > &ref)
void StartElement(XmlReader &stream, const char *name, const char **atts)
void StartElement(XmlReader &stream, const char *name, const char **)
void CharacterData(XmlReader &, const std::string &data)
DbStringXmlHandler(DBString &ref)
void EndElement(XmlReader &, const char *)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void WriteXml(const T &ref, XmlWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)