preliminary implementation of UE DataFormat in Python
This commit is contained in:
parent
f79118ac31
commit
ddc17071db
@ -15,6 +15,17 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from io import FileIO
|
||||
|
||||
class DataFormat:
|
||||
|
||||
pass
|
||||
def load(self, stream : FileIO):
|
||||
self.load_internal(stream)
|
||||
|
||||
def load_internal (self, stream : FileIO):
|
||||
pass
|
||||
def save_internal (self, stream : FileIO):
|
||||
pass
|
||||
|
||||
def save (self, stream : FileIO):
|
||||
self.save_internal(stream)
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
class InvalidDataFormatException (Exception):
|
||||
pass
|
||||
3
editor-python/src/editor/core/__init__.py
Normal file
3
editor-python/src/editor/core/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .DataFormat import DataFormat
|
||||
from .ObjectModel import ObjectModel
|
||||
from .InvalidDataFormatException import InvalidDataFormatException
|
||||
@ -34,10 +34,28 @@ class Reader (ReaderWriterBase):
|
||||
return self._stream
|
||||
|
||||
def read_fixedstring(self, length : int, encoding : Encoding = None) -> str:
|
||||
"""
|
||||
Reads a fixed-length string from the underlying stream.
|
||||
"""
|
||||
|
||||
data = self._stream.read(length)
|
||||
enc = 'utf-8' if encoding is None else encoding.get_value()
|
||||
return bytes.decode(data, enc)
|
||||
|
||||
def read_terminatedstring(self, encoding : Encoding = None, terminator : str = '\0') -> str:
|
||||
"""
|
||||
Reads a terminated string (e.g. zero/null terminated) from the underlying stream.
|
||||
"""
|
||||
v = ''
|
||||
enc = 'utf-8' if encoding is None else encoding.get_value()
|
||||
while True:
|
||||
c = self._stream.read(1)
|
||||
if bytes.decode(c, enc) == terminator:
|
||||
break
|
||||
v += bytes.decode(c, enc)
|
||||
|
||||
return v
|
||||
|
||||
def read_single(self) -> float:
|
||||
|
||||
data = self._stream.read(4)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user