Add big-endian support to String TensorType in TFLite FlatBuffer models
Hi @terryheo ,

Hope all is well with you and thanks for helping us review the previous TFLite related PRs.

Could you please review this PR when you have a chance? Thanks again! Hi @terryheo ,

Could you please take a look at this PR when you have some time?

Thank you very much! Hi @terryheo Can you please review this PR ? Thank you! Hi @terryheo ,

Could you please review this PR when you have a chance? 

Thank you very much! Hi @zichuan-wei ,

Thank you so much for reviewing this PR. 

I've made changes as per your review comment. Could you please take a look again? Thanks! Hi @zichuan-wei ,

Could you please review this PR again? Thank you very much! Hi @zichuan-wei ,

Could you please take a look at the code change when you have a chance?

Thanks! Hi @zichuan-wei ,

I think the failures in `Py+CPP Test Suite` check are not related to the code changes in this PR, since the changes are specific to Big-Endian systems and most are enclosed in `#if FLATBUFFERS_LITTLEENDIAN == 0` macros.

However, I'm not sure why the `feedback/copybara - Google internal checks` failed, since I couldn't access the logs.

Could you please take a look? Thank you very much! Hi @gbaned ,

Since I couldn't access the logs, could you please help check why the `feedback/copybara - Google internal checks` failed?  

Thank you very much! > Hi @gbaned ,
> 
> Since I couldn't access the logs, could you please help check why the `feedback/copybara - Google internal checks` failed?
> 
> Thank you very much!

Hi @kun-lu20 Sorry for the delay in response. We will check it. Thank you so much! Hi @gbaned ,

Do you have any updates reg this PR? 

Thank you very much! > Hi @gbaned ,
> 
> Do you have any updates reg this PR?
> 
> Thank you very much!

Hi @kun-lu20 Sorry for the delay in response. We are working on this PR internally. Thank you so much! @gbaned Thanks for letting me know!
PR #58494 has added big-endian support to numeric TensorTypes in TFLite FlatBuffers. However, since TFLite uses `tflite::DynamicBuffer` to encode vector of strings, the header of string buffer contains raw bytes which record the number of strings, the offsets of each string, etc., as shown in the following code snippet:  https://github.com/tensorflow/tensorflow/blob/864bf2ca8e4f314d9ad01d240d9e3fec2b653c93/tensorflow/lite/string_util.cc#L78-L87  Thus the String TensorType will have endianness issue if a TFLite model is used across platforms with different endianness formats.
 
This PR aims to solve this issue in both C++ and Python code and uses the same guidelines on big-endian machines as PR #58494 , such as:

1. Convert the string buffers from LE(little-endian) to BE(big-endian) format when loading a TFLite model from a file.
2. Convert the string buffers from BE to LE format when writing a serialized binary string of TFLite model to a file.
3. Keep the header of string buffers in BE format when the model/buffer is in memory.

 
An argument `bool from_big_endian` was added to the function declaration of `FlatBufferModel::ByteSwapBuffer()` , because in this function we need to know the endianness of the raw bytes in the header of string buffer, so that we can read the `num_of_strings` data correctly.
 
After applying this PR, the String TensorType will be correctly byte-swapped along with other numeric TensorTypes when necessary. We've tested the code change on TensorFlow test suite, it won't cause any regressions on BE/LE platforms, and can fix the following test failure on s390x (big-endian arch) in master branch:
```bash
//tensorflow/compiler/xla/service/cpu/tests:cpu_infeed_test
```
 
We've also tested this PR with the [tensorflow/serving](https://github.com/tensorflow/serving) test suite, failures in the following test cases could pass on s390x after this change, since the string tensors in TFLite models which were generated on LE machines could now be loaded successfully on BE platforms.
```bash
//tensorflow_serving/servables/tensorflow:saved_model_bundle_factory_test
//tensorflow_serving/servables/tensorflow:tflite_interpreter_pool_test
//tensorflow_serving/servables/tensorflow:tflite_session_test
```