summaryrefslogtreecommitdiff
path: root/proto/io.go
diff options
context:
space:
mode:
Diffstat (limited to 'proto/io.go')
-rw-r--r--proto/io.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/proto/io.go b/proto/io.go
index 1f46503..ba8c8d0 100644
--- a/proto/io.go
+++ b/proto/io.go
@@ -40,6 +40,25 @@ type nslcdObjectPtr interface {
nslcdRead(fd io.Reader)
}
+type String []byte
+func (s String) String() string {
+ return string(s)
+}
+func (s String) GoString() string {
+ return fmt.Sprintf("nslcd_proto.String(%#v)", string(s))
+}
+func (data String) nslcdWrite(fd io.Writer) {
+ Write(fd, int32(len(data)))
+ Write(fd, []byte(data))
+}
+func (data *String) nslcdRead(fd io.Reader) {
+ var len int32
+ Read(fd, &len)
+ buf := make([]byte, len)
+ Read(fd, &buf)
+ *data = String(buf)
+}
+
// Write an object to a stream. In the event of an error, this
// function may panic! Handle it!
func Write(fd io.Writer, data interface{}) {
@@ -60,10 +79,7 @@ func Write(fd io.Writer, data interface{}) {
panic(err)
}
// composite datatypes
- case string:
- Write(fd, int32(len(data)))
- Write(fd, []byte(data))
- case []string:
+ case []String:
Write(fd, int32(len(data)))
for _, item := range data {
Write(fd, item)
@@ -123,16 +139,10 @@ func Read(fd io.Reader, data interface{}) {
panic(err)
}
// composite datatypes
- case *string:
- var len int32
- Read(fd, &len)
- buf := make([]byte, len)
- Read(fd, &buf)
- *data = string(buf)
- case *[]string:
+ case *[]String:
var num int32
Read(fd, &num)
- *data = make([]string, num)
+ *data = make([]String, num)
for i := 0; i < int(num); i++ {
Read(fd, &((*data)[i]))
}