Skip to content

Commit

Permalink
Base64Codec support single value
Browse files Browse the repository at this point in the history
  • Loading branch information
pepesi committed Aug 30, 2022
1 parent 24413cf commit 38b68a2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions mlserver/codecs/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import partial

from ..types import RequestInput, ResponseOutput
from .utils import is_list_of
from .utils import is_list_of, is_single_value
from .base import InputCodec, register_input_codec
from .pack import unpack, PackElement

Expand Down Expand Up @@ -66,8 +66,14 @@ def encode_output(
)

@classmethod
def decode_output(cls, response_output: ResponseOutput) -> List[bytes]:
def decode_output(
cls, response_output: ResponseOutput
) -> Union[List[bytes], bytes]:
packed = response_output.data.__root__
if is_single_value(response_output):
if len(packed) == 0:
raise ValueError("can't decode empty data as a single value")
return next(map(_decode_base64, unpack(packed)))
return list(map(_decode_base64, unpack(packed)))

@classmethod
Expand All @@ -84,7 +90,10 @@ def encode_input(
)

@classmethod
def decode_input(cls, request_input: RequestInput) -> List[bytes]:
def decode_input(cls, request_input: RequestInput) -> Union[List[bytes], bytes]:
packed = request_input.data.__root__

if is_single_value(request_input):
if len(packed) == 0:
raise ValueError("can't decode empty data as a single value")
return next(map(_decode_base64, unpack(packed)))
return list(map(_decode_base64, unpack(packed)))

0 comments on commit 38b68a2

Please sign in to comment.