laforge has uploaded this change for review.
pySim.esim.saip.File: move away from stream for file content
Let's linearize the file content in a bytes member variable self.body.
Change-Id: I6cb23a3a644854abd3dfd3b50b586ce80da21353
---
M pySim/esim/saip/__init__.py
1 file changed, 11 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/47/37847/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 7ee43f7..58c26ae 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -97,7 +97,7 @@
self.pe_name = pename
self.template = template
self.fileDescriptor = {}
- self.stream = None
+ self.body = None
# apply some defaults from profile
if self.template:
self.from_template(self.template)
@@ -173,7 +173,7 @@
raise ValueError("No fileDescriptor found in tuple, and none set by template before")
if fd:
self.fileDescriptor.update(dict(fd))
- self.stream = self.linearize_file_content(l)
+ self.body = self.linearize_file_content(l)
def from_gfm(self, d: Dict):
print(d)
@@ -184,7 +184,7 @@
raise NotImplementedError
@staticmethod
- def linearize_file_content(l: List[Tuple]) -> Optional[io.BytesIO]:
+ def linearize_file_content(l: List[Tuple]) -> Optional[bytes]:
"""linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes."""
stream = io.BytesIO()
for k, v in l:
@@ -199,7 +199,14 @@
stream.write(v)
else:
return ValueError("Unknown key '%s' in tuple list" % k)
- return stream
+ return stream.read()
+
+ def file_content_to_tuples(self) -> List[Tuple]:
+ # FIXME: simplistic approach. needs optimization. We should first check if the content
+ # matches the expanded default value from the template. If it does, return empty list.
+ # Next, we should compute the diff between the default value and self.body, and encode
+ # that as a sequence of fillFileOffset and fillFileContent tuples.
+ return [('fillFileContent', self.body)]
def __str__(self) -> str:
return "File(%s)" % self.pe_name
To view, visit change 37847. To unsubscribe, or for help writing mail filters, visit settings.