summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nslcd_proto/io.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/nslcd_proto/io.go b/src/nslcd_proto/io.go
index 87783ac..a6ff582 100644
--- a/src/nslcd_proto/io.go
+++ b/src/nslcd_proto/io.go
@@ -19,6 +19,8 @@ type NslcdObjectPtr interface {
func write(fd io.Writer, data interface{}) {
switch data := data.(type) {
// basic data types
+ case NslcdObject:
+ data.NslcdWrite(fd)
case []byte:
_, err := fd.Write(data)
if err != nil {
@@ -29,8 +31,6 @@ func write(fd io.Writer, data interface{}) {
if err != nil {
panic(err)
}
- case NslcdObject:
- data.NslcdWrite(fd)
// composite datatypes
case string:
write(fd, int32(len(data)))
@@ -78,6 +78,8 @@ func write(fd io.Writer, data interface{}) {
func read(fd io.Reader, data interface{}) {
switch data := data.(type) {
// basic data types
+ case NslcdObjectPtr:
+ data.NslcdRead(fd)
case *[]byte:
_, err := fd.Read(*data)
if err != nil {
@@ -88,8 +90,6 @@ func read(fd io.Reader, data interface{}) {
if err != nil {
panic(err)
}
- case NslcdObjectPtr:
- data.NslcdRead(fd)
// composite datatypes
case *string:
var len int32
@@ -132,14 +132,13 @@ func read(fd io.Reader, data interface{}) {
read(fd, &((*data)[i]))
}
default:
- v := reflect.ValueOf(data)
- switch v.Kind() {
- case reflect.Struct:
- for i, n := 0, v.NumField(); i < n; i++ {
- read(fd, v.Field(i).Interface())
- }
- default:
+ p := reflect.ValueOf(data)
+ v := reflect.Indirect(p)
+ if p == v || v.Kind() != reflect.Struct {
panic(fmt.Sprintf("The argument to nslcd_proto.read() must be a pointer: %T ( %#v )", data, data))
}
+ for i, n := 0, v.NumField(); i < n; i++ {
+ read(fd, v.Field(i).Addr().Interface())
+ }
}
}