1 // Copyright 2015 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "aemu/base/c_header.h" 18 #include "aemu/base/msvc.h" 19 20 #include <inttypes.h> 21 #include <sys/types.h> 22 23 ANDROID_BEGIN_HEADER 24 25 // Opaque declaration for an object modelling a stream of bytes. 26 // This really is backed by an android::base::Stream implementation. 27 typedef struct Stream Stream; 28 29 ssize_t stream_read(Stream* stream, void* buffer, size_t size); 30 ssize_t stream_write(Stream* stream, const void* buffer, size_t size); 31 32 void stream_put_byte(Stream* stream, int v); 33 void stream_put_be16(Stream* stream, uint16_t v); 34 void stream_put_be32(Stream* stream, uint32_t v); 35 void stream_put_be64(Stream* stream, uint64_t v); 36 37 uint8_t stream_get_byte(Stream* stream); 38 uint16_t stream_get_be16(Stream* stream); 39 uint32_t stream_get_be32(Stream* stream); 40 uint64_t stream_get_be64(Stream* stream); 41 42 void stream_put_float(Stream* stream, float v); 43 float stream_get_float(Stream* stream); 44 45 void stream_put_string(Stream* stream, const char* str); 46 47 // Return a heap-allocated string, or NULL if empty string or error. 48 // Caller must free() the resturned value. 49 char* stream_get_string(Stream* stream); 50 51 void stream_free(Stream* stream); 52 53 ANDROID_END_HEADER 54