Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1b497c6af2
Fetching contributors…

Cannot retrieve contributors at this time

file 45 lines (31 sloc) 0.815 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Coffer 0.0.2
============

Small package for copying between a memory range managed
by C code and Go Buffers.

Requires installation of github.com/boggle/gonewrong

Status: Only barely tested right now but it appears to be working :-)

Typical Usage:

import buffer
import unsafe.coffer
import io

var start uintptr
var sz int
var buf io.Buffer

coffer := coffer.NewPtrCoffer(start, sz)

// Read Bytes from C
buf.ReadFrom(coffer)
bytes := buf.Bytes()

// Write Bytes to C
buf.WriteTo(coffer)

// or
coffer.Write(buf.Bytes())

// Reset to start of memory range
coffer.Seek(0, 0)

// Subsequent Read, Write, or Seek will fail
// Does *NOT* free
coffer.Close()

// Variant: Allocs using C.malloc and frees on Close()
// (independent from Go's GC)
coffer := coffer.NewMemCoffer(sz)
Coffer.Close()

// Have fun!
Something went wrong with that request. Please try again.