blob: 2a0bea9643635af86417741f7dc56a32666384f9 (
plain)
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
|
#pragma once
#include <forstio/core/buffer.h>
#include <forstio/core/common.h>
#include <forstio/codec/data.h>
#include "json.tmpl.h"
#include <algorithm>
namespace saw {
namespace encode {
struct Json {};
}
template<typename Schema>
class data<Schema, encode::Json> {
private:
own<buffer> buffer_;
public:
data() = default;
std::size_t get_size() const {
return buffer_.size();
}
uint8_t& at(std::size_t i){
return buffer_.at(i);
}
const uint8_t& at(std::size_t i) const {
return buffer_.at(i);
}
};
/**
* Codec class for json
*/
template<typename Schema>
class codec<Schema, encode::Json> {
public:
struct config {
size_t depth = 16;
size_t length = 1024;
};
private:
config cfg_;
public:
/**
* Default constructor
*/
config(){}
/**
* Constructor
*/
codec(config cfg__):cfg_{std::move(cfg__)}{}
SAW_FORBID_COPY(codec);
SAW_DEFAULT_MOVE(codec);
template <typename FromEncoding>
ErrorOr<void> encode(const data<Schema, FromEncoding>& from_encode, data<Schema, encode::Json>& to_encode){
// To Be encoded
return Void {};
}
template <typename ToEncoding>
ErrorOr<void> decode(const data<Schema, encode::Json>& from_decode, data<Schema, ToEncoding>& to_decode){
return Void {};
}
};
}
|