Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Release notes
* Use (new) buffer protocol in ``MsgPack`` codec `decode()` method.
By :user:`John Kirkham <jakirkham>`, :issue:`148`.

* Use (new) buffer protocol in ``JSON`` codec `decode()` method.
By :user:`John Kirkham <jakirkham>`, :issue:`151`.

* Avoid copying into data in ``GZip``'s `decode()` method on Python 2.
By :user:`John Kirkham <jakirkham>`, :issue:`152`.

Expand Down
11 changes: 6 additions & 5 deletions numcodecs/json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division
import codecs
import json as _json
import textwrap

Expand All @@ -8,7 +9,7 @@


from .abc import Codec
from .compat import ensure_bytes
from .compat import ensure_contiguous_ndarray


class JSON(Codec):
Expand Down Expand Up @@ -63,8 +64,8 @@ def encode(self, buf):
return self._encoder.encode(items).encode(self._text_encoding)

def decode(self, buf, out=None):
buf = ensure_bytes(buf)
items = self._decoder.decode(buf.decode(self._text_encoding))
buf = ensure_contiguous_ndarray(buf)
items = self._decoder.decode(codecs.decode(buf, self._text_encoding))
dec = np.empty(items[-1], dtype=items[-2])
dec[:] = items[:-2]
if out is not None:
Expand Down Expand Up @@ -125,8 +126,8 @@ def encode(self, buf):
return self._encoder.encode(items).encode(self._text_encoding)

def decode(self, buf, out=None):
buf = ensure_bytes(buf)
items = self._decoder.decode(buf.decode(self._text_encoding))
buf = ensure_contiguous_ndarray(buf)
items = self._decoder.decode(codecs.decode(buf, self._text_encoding))
dec = np.array(items[:-1], dtype=items[-1])
if out is not None:
np.copyto(out, dec)
Expand Down