Skip to content

Commit 76d24e9

Browse files
authored
RSDK-6684 - remove binarydata shadow type (#605)
1 parent 96ef235 commit 76d24e9

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

src/viam/app/data_client.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
AddBoundingBoxToImageByIDResponse,
1515
AddTagsToBinaryDataByFilterRequest,
1616
AddTagsToBinaryDataByIDsRequest,
17+
BinaryData,
1718
BinaryDataByFilterRequest,
1819
BinaryDataByFilterResponse,
1920
BinaryDataByIDsRequest,
2021
BinaryDataByIDsResponse,
2122
BinaryID,
22-
BinaryMetadata,
2323
BoundingBoxLabelsByFilterRequest,
2424
BoundingBoxLabelsByFilterResponse,
2525
CaptureMetadata,
@@ -140,25 +140,6 @@ def __eq__(self, other: object) -> bool:
140140
return str(self) == str(other)
141141
return False
142142

143-
# TODO (RSDK-6684): Revisit if this shadow type is necessary
144-
@dataclass
145-
class BinaryData:
146-
"""Class representing a piece of binary data and associated metadata."""
147-
148-
data: bytes
149-
"""The request data"""
150-
151-
metadata: BinaryMetadata
152-
"""The metadata associated with the data"""
153-
154-
def __str__(self) -> str:
155-
return f"{self.data}\n{self.metadata}"
156-
157-
def __eq__(self, other: object) -> bool:
158-
if isinstance(other, DataClient.BinaryData):
159-
return str(self) == str(other)
160-
return False
161-
162143
def __init__(self, channel: Channel, metadata: Mapping[str, str]):
163144
"""Create a `DataClient` that maintains a connection to app.
164145
@@ -335,7 +316,7 @@ async def binary_data_by_filter(
335316
dest (str): Optional filepath for writing retrieved data.
336317
337318
Returns:
338-
List[BinaryData]: The binary data.
319+
List[viam.proto.app.data.BinaryData]: The binary data.
339320
int: The count (number of entries)
340321
str: The last-returned page ID.
341322
"""
@@ -354,7 +335,7 @@ async def binary_data_by_filter(
354335
include_internal_data=include_internal_data,
355336
)
356337
response: BinaryDataByFilterResponse = await self._data_client.BinaryDataByFilter(request, metadata=self._metadata)
357-
data = [DataClient.BinaryData(data.binary, data.metadata) for data in response.data]
338+
data = list(response.data)
358339
if dest:
359340
try:
360341
file = open(dest, "w")
@@ -401,7 +382,7 @@ async def binary_data_by_ids(
401382
GRPCError: If no `BinaryID` objects are provided.
402383
403384
Returns:
404-
List[BinaryData]: The binary data.
385+
List[viam.proto.app.data.BinaryData]: The binary data.
405386
"""
406387
request = BinaryDataByIDsRequest(binary_ids=binary_ids, include_binary=True)
407388
response: BinaryDataByIDsResponse = await self._data_client.BinaryDataByIDs(request, metadata=self._metadata)
@@ -412,7 +393,7 @@ async def binary_data_by_ids(
412393
file.flush()
413394
except Exception as e:
414395
LOGGER.error(f"Failed to write binary data to file {dest}", exc_info=e)
415-
return [DataClient.BinaryData(data.binary, data.metadata) for data in response.data]
396+
return list(response.data)
416397

417398
async def delete_tabular_data(self, organization_id: str, delete_older_than_days: int) -> int:
418399
"""Delete tabular data older than a specified number of days.

tests/mocks/services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def __init__(
754754
self,
755755
tabular_response: List[DataClient.TabularData],
756756
tabular_query_response: List[Dict[str, ValueTypes]],
757-
binary_response: List[DataClient.BinaryData],
757+
binary_response: List[BinaryData],
758758
delete_remove_response: int,
759759
tags_response: List[str],
760760
bbox_labels_response: List[str],
@@ -817,7 +817,7 @@ async def BinaryDataByFilter(self, stream: Stream[BinaryDataByFilterRequest, Bin
817817
self.last = request.data_request.last
818818
await stream.send_message(
819819
BinaryDataByFilterResponse(
820-
data=[BinaryData(binary=data.data, metadata=data.metadata) for data in self.binary_response],
820+
data=self.binary_response,
821821
count=len(self.binary_response),
822822
last="LAST_BINARY_DATA_PAGE_ID",
823823
)
@@ -829,7 +829,7 @@ async def BinaryDataByIDs(self, stream: Stream[BinaryDataByIDsRequest, BinaryDat
829829
assert request is not None
830830
self.binary_ids = request.binary_ids
831831
await stream.send_message(
832-
BinaryDataByIDsResponse(data=[BinaryData(binary=data.data, metadata=data.metadata) for data in self.binary_response])
832+
BinaryDataByIDsResponse(data=self.binary_response)
833833
)
834834

835835
async def DeleteTabularData(self, stream: Stream[DeleteTabularDataRequest, DeleteTabularDataResponse]) -> None:

tests/test_data_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from grpclib.testing import ChannelFor
66

77
from viam.app.data_client import DataClient
8-
from viam.proto.app.data import Annotations, BinaryID, BinaryMetadata, BoundingBox, CaptureMetadata, Filter, Order
8+
from viam.proto.app.data import Annotations, BinaryData, BinaryID, BinaryMetadata, BoundingBox, CaptureMetadata, Filter, Order
99
from viam.utils import create_filter
1010

1111
from .mocks.services import MockData
@@ -103,7 +103,7 @@
103103
TABULAR_QUERY_RESPONSE = [
104104
{"key1": 1, "key2": "2", "key3": [1, 2, 3], "key4": {"key4sub1": 1}},
105105
]
106-
BINARY_RESPONSE = [DataClient.BinaryData(BINARY_DATA, BINARY_METADATA)]
106+
BINARY_RESPONSE = [BinaryData(binary=BINARY_DATA, metadata=BINARY_METADATA)]
107107
DELETE_REMOVE_RESPONSE = 1
108108
TAGS_RESPONSE = ["tag"]
109109
HOSTNAME_RESPONSE = "host"

0 commit comments

Comments
 (0)