From 236c7277e0c88980a0e3cd858465f342835c8bbe Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Fri, 14 Jan 2022 14:58:59 +0100 Subject: [PATCH] Adds documentation and reformats names --- pkg/cutils/byteslice.go | 7 +++++++ pkg/goutils/goutils.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/cutils/byteslice.go b/pkg/cutils/byteslice.go index f0fffc0..a506b3b 100644 --- a/pkg/cutils/byteslice.go +++ b/pkg/cutils/byteslice.go @@ -7,6 +7,13 @@ import ( "unsafe" ) +// ByteSlice builds a byte Slice over a C pointer returned by a +// C function. +// The C pointer has to be passed as an unsafe.Pointer +// and the size of the pointed memery area has to be +// indicated through the size parameter. +// No memory allocation is done by that function. It +// just consists in mapping a Go object too a C one. func ByteSlice(pointer unsafe.Pointer, size int) []byte { var s []byte diff --git a/pkg/goutils/goutils.go b/pkg/goutils/goutils.go index 68a901c..c2309ea 100644 --- a/pkg/goutils/goutils.go +++ b/pkg/goutils/goutils.go @@ -5,14 +5,21 @@ import ( "encoding/gob" ) +// NotAnInteger defines a new type of Error : "NotAnInteger" type NotAnInteger struct { message string } +// Error() retreives the error message associated to the "NotAnInteger" +// error. Tha addition of that Error message make the "NotAnInteger" +// complying with the error interface func (m *NotAnInteger) Error() string { return m.message } +// InterfaceToInt converts a interface{} to an integer value if possible. +// If not a "NotAnInteger" error is returned via the err +// return value and val is set to 0. func InterfaceToInt(i interface{}) (val int, err error) { err = nil @@ -47,6 +54,7 @@ func InterfaceToInt(i interface{}) (val int, err error) { return } +// CopyMap makes a deep copy of a map[string]interface{}. func CopyMap(dest, src map[string]interface{}) { buf := new(bytes.Buffer) gob.NewEncoder(buf).Encode(src)