Guest User

Untitled

a guest
May 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. typedef struct {
  2. uint8_t* buf;
  3. size_t buflen;
  4. } API_t;
  5.  
  6. void API_init_as_writer(API_t* p, uint8_t* buf, size_t buflen);
  7.  
  8. data API -- empty decl (needs EmptyDataDecls extension)
  9.  
  10. foreign import ccall unsafe "API.h API_init_as_writer"
  11. init :: Ptr API -> Ptr Word8 -> Int -> IO ()
  12.  
  13. writer <- initWriter 1024 -- inits with buflen of 1024 via mallocPlainForeignPtrBytes
  14. writeSomething writer
  15. writeSomethingElse writer
  16. ...
  17. bs <- getByteString writer -- construct ByteString with PS
  18. writeFile "Some.file" bs
  19.  
  20. bs <- ByteString.readFile("Some.file")
  21. reader <- initReader bs
  22. info1 <- readSomething reader
  23. info2 <- readSomethingElse reader
Add Comment
Please, Sign In to add comment