beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [1/2] beam git commit: Add unsigned 64 bit int read/write methods to cythonized stream
Date Wed, 15 Feb 2017 18:13:04 GMT
Repository: beam
Updated Branches:
  refs/heads/master 24ecf6bbf -> 00ea3f7d7


Add unsigned 64 bit int read/write methods to cythonized stream


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/be911e88
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/be911e88
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/be911e88

Branch: refs/heads/master
Commit: be911e881e060c5695f7c15aebce0e542176b1ff
Parents: 24ecf6b
Author: Vikas Kedigehalli <vikasrk@google.com>
Authored: Mon Feb 13 22:11:25 2017 -0800
Committer: Ahmet Altay <altay@google.com>
Committed: Wed Feb 15 09:58:45 2017 -0800

----------------------------------------------------------------------
 sdks/python/apache_beam/coders/stream.pxd     |  3 +++
 sdks/python/apache_beam/coders/stream.pyx     | 10 +++++++++-
 sdks/python/apache_beam/coders/stream_test.py | 11 +++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/be911e88/sdks/python/apache_beam/coders/stream.pxd
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/coders/stream.pxd b/sdks/python/apache_beam/coders/stream.pxd
index 16ea5d4..22ad8c1 100644
--- a/sdks/python/apache_beam/coders/stream.pxd
+++ b/sdks/python/apache_beam/coders/stream.pxd
@@ -27,6 +27,7 @@ cdef class OutputStream(object):
   cpdef write_byte(self, unsigned char val)
   cpdef write_var_int64(self, libc.stdint.int64_t v)
   cpdef write_bigendian_int64(self, libc.stdint.int64_t signed_v)
+  cpdef write_bigendian_uint64(self, libc.stdint.uint64_t signed_v)
   cpdef write_bigendian_int32(self, libc.stdint.int32_t signed_v)
   cpdef write_bigendian_double(self, double d)
 
@@ -41,6 +42,7 @@ cdef class ByteCountingOutputStream(OutputStream):
   cpdef write(self, bytes b, bint nested=*)
   cpdef write_byte(self, unsigned char val)
   cpdef write_bigendian_int64(self, libc.stdint.int64_t val)
+  cpdef write_bigendian_uint64(self, libc.stdint.uint64_t val)
   cpdef write_bigendian_int32(self, libc.stdint.int32_t val)
   cpdef size_t get_count(self)
   cpdef bytes get(self)
@@ -56,6 +58,7 @@ cdef class InputStream(object):
   cpdef long read_byte(self) except? -1
   cpdef libc.stdint.int64_t read_var_int64(self) except? -1
   cpdef libc.stdint.int64_t read_bigendian_int64(self) except? -1
+  cpdef libc.stdint.uint64_t read_bigendian_uint64(self) except? -1
   cpdef libc.stdint.int32_t read_bigendian_int32(self) except? -1
   cpdef double read_bigendian_double(self) except? -1
   cpdef bytes read_all(self, bint nested=*)

http://git-wip-us.apache.org/repos/asf/beam/blob/be911e88/sdks/python/apache_beam/coders/stream.pyx
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/coders/stream.pyx b/sdks/python/apache_beam/coders/stream.pyx
index cde900f..e29f121 100644
--- a/sdks/python/apache_beam/coders/stream.pyx
+++ b/sdks/python/apache_beam/coders/stream.pyx
@@ -63,7 +63,9 @@ cdef class OutputStream(object):
         break
 
   cpdef write_bigendian_int64(self, libc.stdint.int64_t signed_v):
-    cdef libc.stdint.uint64_t v = signed_v
+    self.write_bigendian_uint64(signed_v)
+
+  cpdef write_bigendian_uint64(self, libc.stdint.uint64_t v):
     if  self.size < self.pos + 8:
       self.extend(8)
     self.data[self.pos    ] = <unsigned char>(v >> 56)
@@ -124,6 +126,9 @@ cdef class ByteCountingOutputStream(OutputStream):
   cpdef write_bigendian_int64(self, libc.stdint.int64_t _):
     self.count += 8
 
+  cpdef write_bigendian_uint64(self, libc.stdint.uint64_t _):
+    self.count += 8
+
   cpdef write_bigendian_int32(self, libc.stdint.int32_t _):
     self.count += 4
 
@@ -182,6 +187,9 @@ cdef class InputStream(object):
     return result
 
   cpdef libc.stdint.int64_t read_bigendian_int64(self) except? -1:
+    return self.read_bigendian_uint64()
+
+  cpdef libc.stdint.uint64_t read_bigendian_uint64(self) except? -1:
     self.pos += 8
     return (<unsigned char>self.allc[self.pos - 1]
       | <libc.stdint.uint64_t><unsigned char>self.allc[self.pos - 2] <<
 8

http://git-wip-us.apache.org/repos/asf/beam/blob/be911e88/sdks/python/apache_beam/coders/stream_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/coders/stream_test.py b/sdks/python/apache_beam/coders/stream_test.py
index cfd627f..e6108b6 100644
--- a/sdks/python/apache_beam/coders/stream_test.py
+++ b/sdks/python/apache_beam/coders/stream_test.py
@@ -106,6 +106,15 @@ class StreamTest(unittest.TestCase):
     for v in values:
       self.assertEquals(v, in_s.read_bigendian_int64())
 
+  def test_read_write_bigendian_uint64(self):
+    values = 0, 1, 2**64-1, int(2**61 * math.pi)
+    out_s = self.OutputStream()
+    for v in values:
+      out_s.write_bigendian_uint64(v)
+    in_s = self.InputStream(out_s.get())
+    for v in values:
+      self.assertEquals(v, in_s.read_bigendian_uint64())
+
   def test_read_write_bigendian_int32(self):
     values = 0, 1, -1, 2**31-1, -2**31, int(2**29 * math.pi)
     out_s = self.OutputStream()
@@ -136,6 +145,8 @@ class StreamTest(unittest.TestCase):
     self.assertEquals(22, bc_s.get_count())
     bc_s.write_bigendian_double(6.25)
     self.assertEquals(30, bc_s.get_count())
+    bc_s.write_bigendian_uint64(47)
+    self.assertEquals(38, bc_s.get_count())
 
 
 try:


Mime
View raw message