소스 검색

cbor encoding works

cbor
Ludovic 'Archivist' Lagouardette 4 년 전
부모
커밋
07b187ed63
8개의 변경된 파일95개의 추가작업 그리고 66개의 파일을 삭제
  1. +2
    -2
      Makefile
  2. +7
    -0
      include/gp/algorithm/foreach.hpp
  3. +0
    -59
      include/gp/array.hpp
  4. +7
    -1
      include/gp/bloomfilter.hpp
  5. +1
    -1
      include/gp/buffer.hpp
  6. +7
    -3
      include/gp/enveloppe/cbor.hpp
  7. +5
    -0
      include/gp/quotient_filter.hpp
  8. +66
    -0
      tests/cbor_test.cpp

+ 2
- 2
Makefile 파일 보기

@ -7,8 +7,8 @@ all: tests
tests: bin/tests
LLVM_PROFILE_FILE="./bin/tests.profraw" ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./bin/tests
@llvm-profdata merge -sparse ./bin/tests.profraw -o ./bin/tests.profdata
@llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp
@llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g'
@llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/allocator/*.hpp
@llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g'
bin/tests: tests.cpp $(wildcard tests/*.cpp) $(wildcard include/*.hpp) ./tests/test_scaffold.h
@mkdir -p $(@D)

+ 7
- 0
include/gp/algorithm/foreach.hpp 파일 보기

@ -18,4 +18,11 @@ namespace gp{
f(elem);
}
}
template <typename range, typename T>
void fill(range& range_v, T value) {
for(auto& elem : range_v) {
elem = value;
}
}
}

+ 0
- 59
include/gp/array.hpp 파일 보기

@ -14,65 +14,6 @@ namespace gp{
using associated_riterator = pointer_iterator<T, -1>;
using associated_const_riterator = const_pointer_iterator<T, -1>;
array()
: ary()
{}
array(const array& oth)
{
auto it_l = begin();
auto it_o = oth.cbegin();
for(size_t i = 0; i < sz; ++i)
{
new(&*(it_l++)) T(*(it_o++));
}
}
template<typename ...U>
array(U&& ...values)
: ary{gp::forward<U>((T&&)values)...}
{}
array(array&& values)
{
gp::move_uninitialized(
values,
*this
);
}
array(T (& oth)[sz]) {
gp::move_uninitialized<T>(
gp::nameless_range<int*>(oth, oth+sz),
gp::nameless_range<associated_iterator>(begin(), end())
);
}
array(T (&& oth)[sz]) {
gp::move_uninitialized(
gp::nameless_range<int*>((T*)oth, (T*)oth+sz),
gp::nameless_range<associated_iterator>(begin(), end())
);
}
array& operator=(array& oth)
{
for(size_t i = 0; i < sz; ++i)
{
ary[i]=oth[i];
}
return *this;
}
array& operator=(array&& oth)
{
for(size_t i = 0; i < sz; ++i)
{
ary[i]=gp::move(oth[i]);
}
return *this;
}
constexpr T& operator[] (size_t off)
{
if constexpr (gp_config::has_buffer_bounds)

+ 7
- 1
include/gp/bloomfilter.hpp 파일 보기

@ -1,5 +1,6 @@
#pragma once
#include <gp/algorithm/foreach.hpp>
#include <gp/algorithm/tmp_manip.hpp>
#include <gp/array.hpp>
@ -17,7 +18,7 @@ namespace gp {
uint32_t
>::type,
phys_size
> data{};
> data;
template<typename T>
static void set_bit(T* value, const int v_pos) {
@ -30,6 +31,11 @@ namespace gp {
}
public:
bloomfilter()
{
fill(data, 0);
}
void set_hash(hash_type v)
{
const size_t modulo = v & ((1 << magnitude)-1);

+ 1
- 1
include/gp/buffer.hpp 파일 보기

@ -114,7 +114,7 @@ namespace gp{
{
if(new_sz<=size())
{
return buffer{&*(end()-(mi">1+new_sz)), &*end()};
return buffer{&*(end()-(new_sz)), &*end()};
}
else
{

+ 7
- 3
include/gp/enveloppe/cbor.hpp 파일 보기

@ -252,11 +252,12 @@ namespace gp {
case cbor_composite<cbor_value>::alt<gp::vector<cbor_value>>(): {
auto& ary = contents.value<gp::vector<cbor_value>>();
auto it_begin = encode_length(dest, cbor_type::list, ary.size());
if(it_begin != dest.begin()) return dest.begin();
if(it_begin == dest.begin()) return dest.begin();
for(auto& elem : ary) {
auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin()));
auto it = elem.encode(slice);
if(it == it_begin) return dest.begin();
if(it == it_begin)
return dest.begin();
it_begin = it;
}
return it_begin;
@ -264,12 +265,14 @@ namespace gp {
case cbor_composite<cbor_value>::alt<gp::vector<gp::pair<cbor_value, cbor_value>>>(): {
auto& ary = contents.value<gp::vector<gp::pair<cbor_value,cbor_value>>>();
auto it_begin = encode_length(dest, cbor_type::hmap, ary.size());
if(it_begin != dest.begin()) return dest.begin();
if(it_begin == dest.begin()) return dest.begin();
for(auto& elem : ary) {
auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin()));
auto it = elem.first.encode(slice);
if(it == it_begin) return dest.begin();
it_begin = it;
slice = dest.slice_end(dest.size() - (it_begin - dest.begin()));
it = elem.second.encode(slice);
if(it == it_begin) return dest.begin();
@ -285,6 +288,7 @@ namespace gp {
case cbor_composite<cbor_value>::alt<cbor_floating_point>(): {
return encode_float(dest, contents.value<cbor_floating_point>());
}
default: return dest.begin();
}
}
};

+ 5
- 0
include/gp/quotient_filter.hpp 파일 보기

@ -1,5 +1,6 @@
#pragma once
#include <gp/algorithm/foreach.hpp>
#include <gp/algorithm/tmp_manip.hpp>
#include <gp/array.hpp>
#include <gp/exception.hpp>
@ -104,6 +105,10 @@ namespace gp {
}
public:
quotient_filter() {
gp::fill(data, node{0,0,0});
}
void set_hash(hash_type v)
{
const size_t q = v & ((1 << magnitude)-1);

+ 66
- 0
tests/cbor_test.cpp 파일 보기

@ -59,6 +59,72 @@ struct cbor_test : public test_scaffold {
gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc}));
gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc}));
data = gen;
gp::array<std::byte, 7> serialized;
gp::array<std::byte, 7> serialized_manual{
std::byte(0b10100010),
std::byte(0b00001100),
std::byte(0b00111000), std::byte(98),
std::byte(0b00001101),
std::byte(0b00011000), std::byte(98)
};
auto ret_it = data.encode(serialized.as_buffer());
gp_config::assertion(serialized.begin() != ret_it, "could not encode");
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly");
}
{
gp::cbor_value data{alloc};
data = gp::cbor_number(1);
gp::array<std::byte, 1> serialized;
gp::array<std::byte, 1> serialized_manual{
std::byte(1)
};
auto ret_it = data.encode(serialized.as_buffer());
gp_config::assertion(serialized.begin() != ret_it, "could not encode");
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly");
}
{
gp::cbor_value data{alloc};
data = gp::cbor_floating_point(128.5f);
gp::array<std::byte, 5> serialized;
gp::array<std::byte, 5> serialized_manual{
std::byte(0b11111010),
std::byte(0b01000011),
std::byte(0b00000000),
std::byte(0b10000000),
std::byte(0b00000000)
};
auto ret_it = data.encode(serialized.as_buffer());
gp_config::assertion(serialized.begin() != ret_it, "could not encode");
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly");
}
{
gp::array<char, 5> str{'h', 'e', 'l', 'l', 'o'};
gp::cbor_value data{alloc};
data = str.as_buffer().cast<std::byte>();
gp::array<std::byte, 6> serialized;
gp::array<std::byte, 6> serialized_manual{
std::byte(0b01000101),
std::byte('h'),
std::byte('e'),
std::byte('l'),
std::byte('l'),
std::byte('o')
};
auto ret_it = data.encode(serialized.as_buffer());
gp_config::assertion(serialized.begin() != ret_it, "could not encode");
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly");
}
return 0;

불러오는 중...
취소
저장