예제 #1
0
파일: node.go 프로젝트: caervs/golibrdf
//ToString returns a string representation of the node
func (node *Node) ToString() (string, error) {
	var stringPointer unsafe.Pointer
	var length C.size_t

	raptorWorld := node.world.GetRaptorWorld()
	stream := C.raptor_new_iostream_to_string(raptorWorld, &stringPointer, &length, nil)

	if stream == nil {
		return "", errors.New("Unable to obtain raptor stream")
	}

	defer C.free(unsafe.Pointer(stringPointer))

	C.librdf_node_write(node.librdf_node, stream)
	C.raptor_free_iostream(stream)

	return C.GoString((*C.char)(unsafe.Pointer(stringPointer))), nil
}
예제 #2
0
//ToString serializers a statement to string
func (statement *Statement) ToString() (string, error) {
	var stringPointer unsafe.Pointer
	var length C.size_t

	raptorWorld := statement.world.GetRaptorWorld()

	stream := C.raptor_new_iostream_to_string(raptorWorld, &stringPointer, &length, nil)
	if stream == nil {
		return "", errors.New("Unable to obtain raptor stream")
	}
	defer C.raptor_free_iostream(stream)

	if result := C.librdf_statement_write(statement.librdf_statement, stream); result != 0 {
		return "", errors.New("Unable to write statement")
	}
	defer C.free(unsafe.Pointer(stringPointer))

	return C.GoString((*C.char)(unsafe.Pointer(stringPointer))), nil
}