Skip to content

Commit

Permalink
Map C++ [u]intXX_t types to Go [u]intXX types
Browse files Browse the repository at this point in the history
This required reimplementing HostToNetXX/NetToHostXX functions as
helpers instead of simply exposing templated version under custom names,
because apparently typemap intercept does not work on template argument
types.
  • Loading branch information
Eugene Kim committed Dec 7, 2018
1 parent d5e3d01 commit cbee330
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/impl/libraptorq/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type DecoderFactory struct {
func (*DecoderFactory) New(commonOTI uint64, schemeSpecificOTI uint32) (
decoder raptorq.Decoder, err error) {
wrapped := swig.NewBytesDecoder(swig.HostToNet64(commonOTI),
swig.HostToNet32(uint(schemeSpecificOTI)))
swig.HostToNet32(schemeSpecificOTI))
if wrapped.Initialized() {
decoder = &Decoder{wrapped, commonOTI, schemeSpecificOTI}
runtime.SetFinalizer(decoder, finalizeDecoder)
Expand Down
30 changes: 22 additions & 8 deletions pkg/impl/libraptorq/swig/stdint.swg
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
%{
#include <stdint.h>
#include <cstdint>
%}

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;
%include "stdint.i"

namespace std {
using uint8_t = ::uint8_t;
using int8_t = ::int8_t;
using uint16_t = ::uint16_t;
using int16_t = ::int16_t;
using uint32_t = ::uint32_t;
using int32_t = ::int32_t;
using uint64_t = ::uint64_t;
using int64_t = ::int64_t;
}

%typemap(gotype) uint8_t, uint8_t const, uint8_t const &, std::uint8_t, std::uint8_t const, std::uint8_t const & "uint8"
%typemap(gotype) int8_t, int8_t const, int8_t const &, std::int8_t, std::int8_t const, std::int8_t const & "int8"
%typemap(gotype) uint16_t, uint16_t const, uint16_t const &, std::uint16_t, std::uint16_t const, std::uint16_t const & "uint16"
%typemap(gotype) int16_t, int16_t const, int16_t const &, std::int16_t, std::int16_t const, std::int16_t const & "int16"
%typemap(gotype) uint32_t, uint32_t const, uint32_t const &, std::uint32_t, std::uint32_t const, std::uint32_t const & "uint32"
%typemap(gotype) int32_t, int32_t const, int32_t const &, std::int32_t, std::int32_t const, std::int32_t const & "int32"
%typemap(gotype) uint64_t, uint64_t const, uint64_t const &, std::uint64_t, std::uint64_t const, std::uint64_t const & "uint64"
%typemap(gotype) int64_t, int64_t const, int64_t const &, std::int64_t, std::int64_t const, std::int64_t const & "int64"
30 changes: 17 additions & 13 deletions pkg/impl/libraptorq/swig/swig.swigcxx
Original file line number Diff line number Diff line change
Expand Up @@ -728,23 +728,27 @@ bool set_compression(Compress const compression);
size_t local_cache_size (size_t const local_cache);
size_t get_local_cache_size();

namespace Impl {
namespace Endian {
} // namespace RaptorQ__v1

template <typename T> constexpr T b_to_h(T const b);
template <typename T> constexpr T h_to_b(T const h);
%define NET_TO_HOST_TO_NET(size)
%inline %{

%template(NetToHost16) b_to_h<uint16_t>;
%template(NetToHost32) b_to_h<uint32_t>;
%template(NetToHost64) b_to_h<uint64_t>;
constexpr uint##size##_t NetToHost##size(uint##size##_t const b) {
return RaptorQ__v1::Impl::Endian::b_to_h(b);
}

%template(HostToNet16) h_to_b<uint16_t>;
%template(HostToNet32) h_to_b<uint32_t>;
%template(HostToNet64) h_to_b<uint64_t>;
constexpr uint##size##_t HostToNet##size(uint##size##_t const h) {
return RaptorQ__v1::Impl::Endian::h_to_b(h);
}

} // namespace Endian
} // namespace Impl
} // namespace RaptorQ__v1
%}
%enddef

NET_TO_HOST_TO_NET(16)
NET_TO_HOST_TO_NET(32)
NET_TO_HOST_TO_NET(64)

#undef NET_TO_HOST_TO_NET

namespace RFC6330__v1 {

Expand Down

0 comments on commit cbee330

Please sign in to comment.