blob: 09c03e827db81fdb156582b3f4373afba6f049cb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "object2slime.h"
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/data/slime/cursor.h>
namespace vespalib {
Object2Slime::Object2Slime(slime::Cursor & cursor)
: _cursor(cursor),
_stack()
{
}
Object2Slime::~Object2Slime() = default;
//-----------------------------------------------------------------------------
void
Object2Slime::openStruct(const vespalib::string &name, const vespalib::string &type)
{
if (name.empty()) {
_cursor.get().setString("[type]", type);
} else {
_stack.push_back(_cursor);
_cursor = _cursor.get().setObject(name);
_cursor.get().setString("[type]", type);
}
}
void
Object2Slime::closeStruct()
{
if ( ! _stack.empty()) {
_cursor = _stack.back();
_stack.pop_back();
}
}
void
Object2Slime::visitBool(const vespalib::string &name, bool value)
{
_cursor.get().setBool(name, value);
}
void
Object2Slime::visitInt(const vespalib::string &name, int64_t value)
{
_cursor.get().setLong(name, value);
}
void
Object2Slime::visitFloat(const vespalib::string &name, double value)
{
_cursor.get().setDouble(name, value);
}
void
Object2Slime::visitString(const vespalib::string &name, const vespalib::string &value)
{
_cursor.get().setString(name, value);
}
void
Object2Slime::visitNull(const vespalib::string &name)
{
_cursor.get().setNix(name);
}
void
Object2Slime::visitNotImplemented()
{
_cursor.get().setNix("not_implemented");
}
}
|