Skip to content

Commit

Permalink
Merge pull request #16 from nlowe/feat/support-getting-message-struct…
Browse files Browse the repository at this point in the history
…-fields

Add support for gst_structure_get* for types supported by (*gst.Structure).SetValue(...)
  • Loading branch information
notedit authored Aug 30, 2020
2 parents 185e5fb + 7d1a261 commit 6d794a7
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package gst
import "C"

import (
"runtime"
"unsafe"
"fmt"
"runtime"
"unsafe"
)

type Structure struct {
Expand All @@ -30,6 +31,67 @@ func NewStructure(name string) (structure *Structure) {
return
}

func errNoSuchField(t, name string) error {
return fmt.Errorf("structure does not have a %s named %s", t, name)
}

func (s *Structure) GetName() string {
return C.GoString(C.gst_structure_get_name(s.C))
}

func (s *Structure) GetBool(name string) (bool, error) {
var out C.gboolean

if C.FALSE == C.gst_structure_get_boolean(s.C, C.CString(name), &out) {
return false, errNoSuchField("bool", name)
}

if out == C.TRUE {
return true, nil
}

return false, nil
}

func (s *Structure) GetInt(name string) (int, error) {
var out C.gint

if C.FALSE == C.gst_structure_get_int(s.C, C.CString(name), &out) {
return 0, errNoSuchField("int", name)
}

return int(out), nil
}

func (s *Structure) GetInt64(name string) (int64, error) {
var out C.gint64

if C.FALSE == C.gst_structure_get_int64(s.C, C.CString(name), &out) {
return 0, errNoSuchField("int64", name)
}

return int64(out), nil
}

func (s *Structure) GetUint(name string) (uint, error) {
var out C.guint

if C.FALSE == C.gst_structure_get_uint(s.C, C.CString(name), &out) {
return 0, errNoSuchField("uint", name)
}

return uint(out), nil
}

func (s *Structure) GetString(name string) (string, error) {
out := C.gst_structure_get_string(s.C, C.CString(name))
if out == nil {
return "", errNoSuchField("string", name)
}

return C.GoString(out), nil
}

func (s *Structure) SetValue(name string, value interface{}) {

CName := (*C.gchar)(unsafe.Pointer(C.CString(name)))
Expand Down

0 comments on commit 6d794a7

Please sign in to comment.