Home | History | Annotate | Download | only in files
      1 // Copyright 2017 The Android Open Source Project
      2 //
      3 // This software is licensed under the terms of the GNU General Public
      4 // License version 2, as published by the Free Software Foundation, and
      5 // may be copied, distributed, and modified under those terms.
      6 //
      7 // This program is distributed in the hope that it will be useful,
      8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 // GNU General Public License for more details.
     11 
     12 #include "android/base/files/StreamSerializing.h"
     13 
     14 namespace android {
     15 namespace base {
     16 
     17 void saveStream(Stream* stream, const MemStream& memStream) {
     18     memStream.save(stream);
     19 }
     20 
     21 void loadStream(Stream* stream, MemStream* memStream) {
     22     memStream->load(stream);
     23 }
     24 
     25 void saveBufferRaw(Stream* stream, char* buffer, uint32_t len) {
     26     stream->putBe32(len);
     27     stream->write(buffer, len);
     28 }
     29 
     30 bool loadBufferRaw(Stream* stream, char* buffer) {
     31     auto len = stream->getBe32();
     32     int ret = (int)stream->read(buffer, len);
     33     return ret == (int)len;
     34 }
     35 
     36 void saveStringArray(Stream* stream, const char* const* strings, uint32_t count) {
     37     stream->putBe32(count);
     38     for (uint32_t i = 0; i < count; ++i) {
     39         stream->putString(strings[i]);
     40     }
     41 }
     42 
     43 std::vector<std::string> loadStringArray(Stream* stream) {
     44     uint32_t count = stream->getBe32();
     45     std::vector<std::string> res;
     46     for (uint32_t i = 0; i < count; ++i) {
     47         res.push_back(stream->getString());
     48     }
     49     return res;
     50 }
     51 
     52 }  // namespace base
     53 }  // namespace android
     54