From cf9ba53a0e3635074b2117f471d6741f3a2396ba Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Mon, 13 Nov 2017 13:32:49 -0800 Subject: [PATCH] Add ByteRange/StringPiece Conversion for Cython Summary: Moving the cython definition to folly/python. Adding simple conversion helper to_bytes This is to cut down on duplicate folly::range cython definitions Reviewed By: yfeldblum Differential Revision: D6291125 fbshipit-source-id: 314b732a1516a03fb5c9a57939552bbabd81970b --- folly/python/range.pxd | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 folly/python/range.pxd diff --git a/folly/python/range.pxd b/folly/python/range.pxd new file mode 100644 index 00000000..fef1dd9b --- /dev/null +++ b/folly/python/range.pxd @@ -0,0 +1,17 @@ +cdef extern from "folly/Range.h" namespace "folly": + cdef cppclass Range[T]: + Range() + Range(T, int) + T data() + int size() + +ctypedef Range[const char*] StringPiece +ctypedef Range[const unsigned char*] ByteRange + +ctypedef fused R: + StringPiece + ByteRange + +# Conversion Helpers +cdef inline bytes to_bytes(R range): + return range.data()[:range.size()] -- 2.34.1