@@ -894,6 +894,20 @@ write_i16_le(PyObject *module, PyObject *const *args, size_t nargs) {
894894 Py_RETURN_NONE ;
895895}
896896
897+ static PyObject *
898+ write_i16_be (PyObject * module , PyObject * const * args , size_t nargs ) {
899+ BytesWriterObject * bw = parse_write_int_args (args , nargs , "write_i16_be" );
900+ if (bw == NULL )
901+ return NULL ;
902+ int16_t unboxed = CPyLong_AsInt16 (args [1 ]);
903+ if (unlikely (unboxed == CPY_LL_INT_ERROR && PyErr_Occurred ()))
904+ return NULL ;
905+ if (unlikely (!ensure_bytes_writer_size (bw , 2 )))
906+ return NULL ;
907+ BytesWriter_WriteI16BEUnsafe (bw , unboxed );
908+ Py_RETURN_NONE ;
909+ }
910+
897911static PyObject *
898912read_i16_le (PyObject * module , PyObject * const * args , size_t nargs ) {
899913 int64_t index ;
@@ -903,6 +917,15 @@ read_i16_le(PyObject *module, PyObject *const *args, size_t nargs) {
903917 return PyLong_FromLong (CPyBytes_ReadI16LEUnsafe (data + index ));
904918}
905919
920+ static PyObject *
921+ read_i16_be (PyObject * module , PyObject * const * args , size_t nargs ) {
922+ int64_t index ;
923+ const unsigned char * data = parse_read_int_args (args , nargs , "read_i16_be" , 2 , & index );
924+ if (data == NULL )
925+ return NULL ;
926+ return PyLong_FromLong (CPyBytes_ReadI16BEUnsafe (data + index ));
927+ }
928+
906929static PyObject *
907930write_i32_le (PyObject * module , PyObject * const * args , size_t nargs ) {
908931 BytesWriterObject * bw = parse_write_int_args (args , nargs , "write_i32_le" );
@@ -917,6 +940,20 @@ write_i32_le(PyObject *module, PyObject *const *args, size_t nargs) {
917940 Py_RETURN_NONE ;
918941}
919942
943+ static PyObject *
944+ write_i32_be (PyObject * module , PyObject * const * args , size_t nargs ) {
945+ BytesWriterObject * bw = parse_write_int_args (args , nargs , "write_i32_be" );
946+ if (bw == NULL )
947+ return NULL ;
948+ int32_t unboxed = CPyLong_AsInt32 (args [1 ]);
949+ if (unlikely (unboxed == CPY_LL_INT_ERROR && PyErr_Occurred ()))
950+ return NULL ;
951+ if (unlikely (!ensure_bytes_writer_size (bw , 4 )))
952+ return NULL ;
953+ BytesWriter_WriteI32BEUnsafe (bw , unboxed );
954+ Py_RETURN_NONE ;
955+ }
956+
920957static PyObject *
921958read_i32_le (PyObject * module , PyObject * const * args , size_t nargs ) {
922959 int64_t index ;
@@ -926,6 +963,15 @@ read_i32_le(PyObject *module, PyObject *const *args, size_t nargs) {
926963 return PyLong_FromLong (CPyBytes_ReadI32LEUnsafe (data + index ));
927964}
928965
966+ static PyObject *
967+ read_i32_be (PyObject * module , PyObject * const * args , size_t nargs ) {
968+ int64_t index ;
969+ const unsigned char * data = parse_read_int_args (args , nargs , "read_i32_be" , 4 , & index );
970+ if (data == NULL )
971+ return NULL ;
972+ return PyLong_FromLong (CPyBytes_ReadI32BEUnsafe (data + index ));
973+ }
974+
929975static PyObject *
930976write_i64_le (PyObject * module , PyObject * const * args , size_t nargs ) {
931977 BytesWriterObject * bw = parse_write_int_args (args , nargs , "write_i64_le" );
@@ -940,6 +986,20 @@ write_i64_le(PyObject *module, PyObject *const *args, size_t nargs) {
940986 Py_RETURN_NONE ;
941987}
942988
989+ static PyObject *
990+ write_i64_be (PyObject * module , PyObject * const * args , size_t nargs ) {
991+ BytesWriterObject * bw = parse_write_int_args (args , nargs , "write_i64_be" );
992+ if (bw == NULL )
993+ return NULL ;
994+ int64_t unboxed = CPyLong_AsInt64 (args [1 ]);
995+ if (unlikely (unboxed == CPY_LL_INT_ERROR && PyErr_Occurred ()))
996+ return NULL ;
997+ if (unlikely (!ensure_bytes_writer_size (bw , 8 )))
998+ return NULL ;
999+ BytesWriter_WriteI64BEUnsafe (bw , unboxed );
1000+ Py_RETURN_NONE ;
1001+ }
1002+
9431003static PyObject *
9441004read_i64_le (PyObject * module , PyObject * const * args , size_t nargs ) {
9451005 int64_t index ;
@@ -949,28 +1009,55 @@ read_i64_le(PyObject *module, PyObject *const *args, size_t nargs) {
9491009 return PyLong_FromLongLong (CPyBytes_ReadI64LEUnsafe (data + index ));
9501010}
9511011
1012+ static PyObject *
1013+ read_i64_be (PyObject * module , PyObject * const * args , size_t nargs ) {
1014+ int64_t index ;
1015+ const unsigned char * data = parse_read_int_args (args , nargs , "read_i64_be" , 8 , & index );
1016+ if (data == NULL )
1017+ return NULL ;
1018+ return PyLong_FromLongLong (CPyBytes_ReadI64BEUnsafe (data + index ));
1019+ }
1020+
9521021#endif
9531022
9541023static PyMethodDef librt_strings_module_methods [] = {
9551024#ifdef MYPYC_EXPERIMENTAL
9561025 {"write_i16_le" , (PyCFunction ) write_i16_le , METH_FASTCALL ,
9571026 PyDoc_STR ("Write a 16-bit signed integer to BytesWriter in little-endian format" )
9581027 },
1028+ {"write_i16_be" , (PyCFunction ) write_i16_be , METH_FASTCALL ,
1029+ PyDoc_STR ("Write a 16-bit signed integer to BytesWriter in big-endian format" )
1030+ },
9591031 {"read_i16_le" , (PyCFunction ) read_i16_le , METH_FASTCALL ,
9601032 PyDoc_STR ("Read a 16-bit signed integer from bytes in little-endian format" )
9611033 },
1034+ {"read_i16_be" , (PyCFunction ) read_i16_be , METH_FASTCALL ,
1035+ PyDoc_STR ("Read a 16-bit signed integer from bytes in big-endian format" )
1036+ },
9621037 {"write_i32_le" , (PyCFunction ) write_i32_le , METH_FASTCALL ,
9631038 PyDoc_STR ("Write a 32-bit signed integer to BytesWriter in little-endian format" )
9641039 },
1040+ {"write_i32_be" , (PyCFunction ) write_i32_be , METH_FASTCALL ,
1041+ PyDoc_STR ("Write a 32-bit signed integer to BytesWriter in big-endian format" )
1042+ },
9651043 {"read_i32_le" , (PyCFunction ) read_i32_le , METH_FASTCALL ,
9661044 PyDoc_STR ("Read a 32-bit signed integer from bytes in little-endian format" )
9671045 },
1046+ {"read_i32_be" , (PyCFunction ) read_i32_be , METH_FASTCALL ,
1047+ PyDoc_STR ("Read a 32-bit signed integer from bytes in big-endian format" )
1048+ },
9681049 {"write_i64_le" , (PyCFunction ) write_i64_le , METH_FASTCALL ,
9691050 PyDoc_STR ("Write a 64-bit signed integer to BytesWriter in little-endian format" )
9701051 },
1052+ {"write_i64_be" , (PyCFunction ) write_i64_be , METH_FASTCALL ,
1053+ PyDoc_STR ("Write a 64-bit signed integer to BytesWriter in big-endian format" )
1054+ },
9711055 {"read_i64_le" , (PyCFunction ) read_i64_le , METH_FASTCALL ,
9721056 PyDoc_STR ("Read a 64-bit signed integer from bytes in little-endian format" )
9731057 },
1058+ {"read_i64_be" , (PyCFunction ) read_i64_be , METH_FASTCALL ,
1059+ PyDoc_STR ("Read a 64-bit signed integer from bytes in big-endian format" )
1060+ },
9741061#endif
9751062 {NULL , NULL , 0 , NULL }
9761063};
0 commit comments