summaryrefslogtreecommitdiff
path: root/py/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'py/stream.h')
-rw-r--r--py/stream.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/stream.h b/py/stream.h
index a1d1c4f8a..3dec49a2e 100644
--- a/py/stream.h
+++ b/py/stream.h
@@ -62,6 +62,16 @@ struct mp_stream_seek_t {
#define MP_SEEK_CUR (1)
#define MP_SEEK_END (2)
+// Stream protocol
+typedef struct _mp_stream_p_t {
+ // On error, functions should return MP_STREAM_ERROR and fill in *errcode (values
+ // are implementation-dependent, but will be exposed to user, e.g. via exception).
+ mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
+ mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
+ mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
+ mp_uint_t is_text : 1; // default is bytes, set this for text stream
+} mp_stream_p_t;
+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj);