Skip to content

Commit

Permalink
Using pbf_reader/writer.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Dec 2, 2018
1 parent 9034119 commit 8817ebc
Show file tree
Hide file tree
Showing 13 changed files with 2,112 additions and 36 deletions.
35 changes: 23 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML
option(YAML_CPP_BUILD_TESTS "Enable testing" ON)
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
option(YAML_CPP_BUILD_PROTOBUF "Enable protobuf stuff in library" ON)
option(YAML_CPP_INSTALL "Enable generation of install target" ON)

option(YAML_CPP_BUILD_PROTOBUF "Enable load/dump protobuf in library" ON)
option(YAML_CPP_USE_GOOGLE_PROTOBUF "Also use google's protobuf stuff in library" OFF)

## Build options
# --> General
# see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
Expand Down Expand Up @@ -88,8 +90,14 @@ endif()

if(YAML_CPP_BUILD_PROTOBUF)
set(protbuf_sources
src/proto/protobuf.cpp
src/proto/yaml.pb.cc)
src/proto/protobuf.cpp)

if(YAML_CPP_USE_GOOGLE_PROTOBUF)
set(protbuf_sources
${protbuf_sources}
src/proto/yaml.pb.cc)
endif()

endif()

set(library_sources
Expand Down Expand Up @@ -275,21 +283,24 @@ set_target_properties(yaml-cpp PROPERTIES
)

if(YAML_CPP_BUILD_PROTOBUF)
find_package(Protobuf REQUIRED)
if(YAML_CPP_USE_GOOGLE_PROTOBUF)
find_package(Protobuf REQUIRED)
target_link_libraries(yaml-cpp
PUBLIC
${Protobuf_LIBRARIES})
target_include_directories(yaml-cpp
PRIVATE
${Protobuf_INCLUDE_DIRS})
target_compile_definitions(yaml-cpp
PUBLIC
USE_GOOGLE_PROTOBUF)
endif()

target_include_directories(yaml-cpp
PRIVATE
${Protobuf_INCLUDE_DIRS}
PUBLIC
${YAML_CPP_SOURCE_DIR}/include/yaml-cpp/proto)

target_link_libraries(yaml-cpp
PUBLIC
${Protobuf_LIBRARIES})
endif()

if(YAML_CPP_BUILD_PROTOBUF)
endif()

if(IPHONE)
set_target_properties(yaml-cpp PROPERTIES
Expand Down
2 changes: 2 additions & 0 deletions include/yaml-cpp/node/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Node;
*/
YAML_CPP_API Node Load(const std::string& input);

YAML_CPP_API Node Load(const char* input, size_t length);

/**
* Loads the input string as a single YAML document.
*
Expand Down
13 changes: 11 additions & 2 deletions include/yaml-cpp/proto/protobuf.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
#pragma once

#include <stddef.h>
#include <string>

#ifdef USE_GOOGLE_PROTOBUF
#include "yaml.pb.h"
#endif

namespace YAML {

class Node;

struct Protobuf {
static proto::Node Dump(const YAML::Node& node);
static YAML::Node Load(const proto::Node& node);
#ifdef USE_GOOGLE_PROTOBUF
static proto::Node GDump(const YAML::Node& node);
static YAML::Node GLoad(const proto::Node& node);
#endif
static std::string Dump(const YAML::Node& node);
static YAML::Node Load(const char* data, size_t length);
};

}
24 changes: 24 additions & 0 deletions src/proto/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pbf.hpp copyright (c) Mapbox.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 changes: 34 additions & 0 deletions src/proto/pbf_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef MAPBOX_UTIL_PBF_COMMON_HPP
#define MAPBOX_UTIL_PBF_COMMON_HPP

#include <cstdint>

namespace mapbox { namespace util {

/**
* The type used for field tags (field numbers).
*/
typedef uint32_t pbf_tag_type;

/**
* The type used to encode type information.
* See the table on
* https://developers.google.com/protocol-buffers/docs/encoding
*/
enum class pbf_wire_type : uint32_t {
varint = 0, // int32/64, uint32/64, sint32/64, bool, enum
fixed64 = 1, // fixed64, sfixed64, double
length_delimited = 2, // string, bytes, embedded messages,
// packed repeated fields
fixed32 = 5, // fixed32, sfixed32, float
unknown = 99 // used for default setting in this library
};

/**
* The type used for length values, such as the length of a field.
*/
typedef uint32_t pbf_length_type;

}} // end namespace mapbox::util

#endif // MAPBOX_UTIL_PBF_COMMON_HPP
Loading

0 comments on commit 8817ebc

Please sign in to comment.