commit 961194b38c7cf7d7f20d04f1275232ff953f5175 from: Stephen Day date: Fri Dec 04 22:56:23 2015 UTC Merge pull request #2 from djs55/upstream/add-dir-array-encode-decode p9p: add a marshaller and unmarshaller for `[]Dir` commit - 6b62df4706f86d9f1d38e2dcc363d440561d8c8d commit + 961194b38c7cf7d7f20d04f1275232ff953f5175 blob - 41ddbf0319ea6be32598c3273d6880fe8cf3b4f1 blob + 228904f47bccd17e2149da9f8130a7ac9dc5e42f --- encoding.go +++ encoding.go @@ -181,6 +181,19 @@ func (e *encoder) encode(vs ...interface{}) error { return err } case *Dir: + if err := e.encode(*v); err != nil { + return err + } + case []Dir: + elements := make([]interface{}, len(v)) + for i := range v { + elements[i] = &v[i] + } + + if err := e.encode(elements...); err != nil { + return err + } + case *[]Dir: if err := e.encode(*v); err != nil { return err } @@ -330,6 +343,18 @@ func (d *decoder) decode(vs ...interface{}) error { if err := dec.decode(elements...); err != nil { return err } + case *[]Dir: + *v = make([]Dir, 0) + for { + element := Dir{} + if err := d.decode(&element); err != nil { + if err == io.EOF { + return nil + } + return err + } + *v = append(*v, element) + } case *Fcall: if err := d.decode(&v.Type, &v.Tag); err != nil { return err @@ -443,6 +468,14 @@ func size9p(vs ...interface{}) uint32 { s += size9p(elements...) + size9p(uint16(0)) case *Dir: s += size9p(*v) + case []Dir: + elements := make([]interface{}, len(v)) + for i := range elements { + elements[i] = &v[i] + } + s += size9p(elements...) + case *[]Dir: + s += size9p(*v) case Fcall: s += size9p(v.Type, v.Tag, v.Message) case *Fcall: blob - e55b866f5ed22f8ee8692f15ce3bf466609194c6 blob + b7970f2c8cc66f4ce604a9ec80480cabd5cd7530 --- encoding_test.go +++ encoding_test.go @@ -177,6 +177,156 @@ func TestEncodeDecode(t *testing.T) { 0x3, 0x0, 0x75, 0x69, 0x64, // uid 0x3, 0x0, 0x67, 0x69, 0x64, // gid 0x4, 0x0, 0x6d, 0x75, 0x69, 0x64}, // muid + }, + { + description: "Dir[]", + target: []Dir{ + { + Type: uint16(0), + Dev: uint32(0), + Qid: Qid{ + Type: QTDIR, + Version: uint32(0), + Path: ^uint64(0), + }, + Mode: DMDIR | DMREAD, + AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + Length: 0x88, + Name: ".", + UID: "501", + GID: "20", + MUID: "none", + }, + { + Type: uint16(0), + Dev: uint32(0), + Qid: Qid{ + Type: QTDIR, + Version: uint32(0), + Path: ^uint64(0), + }, + Mode: DMDIR | DMREAD, + AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + Length: 0x63e, + Name: "..", + UID: "501", + GID: "20", + MUID: "none", + }, + { + Type: uint16(0), + Dev: uint32(0), + Qid: Qid{ + Type: QTDIR, + Version: uint32(0), + Path: ^uint64(0), + }, + Mode: DMDIR | DMREAD, + AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + Length: 0x44, + Name: "hello", + UID: "501", + GID: "20", + MUID: "none", + }, + { + Type: uint16(0), + Dev: uint32(0), + Qid: Qid{ + Type: QTDIR, + Version: uint32(0), + Path: ^uint64(0), + }, + Mode: DMDIR | DMREAD, + AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC), + Length: 0x44, + Name: "there", + UID: "501", + GID: "20", + MUID: "none", + }, + }, + marshaled: []byte{ + 0x39, 0x0, // size + 0x0, 0x0, // type + 0x0, 0x0, 0x0, 0x0, // dev + 0x80, // qid.type == QTDIR + 0x0, 0x0, 0x0, 0x0, // qid.vers + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path + 0x4, 0x0, 0x0, 0x80, // mode + 0x25, 0x98, 0xb8, 0x43, // atime + 0x25, 0x98, 0xb8, 0x43, // mtime + 0x88, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length + 0x1, 0x0, + 0x2e, // . + 0x3, 0x0, + 0x35, 0x30, 0x31, // 501 + 0x2, 0x0, + 0x32, 0x30, // 20 + 0x4, 0x0, + 0x6e, 0x6f, 0x6e, 0x65, // none + + 0x3a, 0x0, + 0x0, 0x0, // type + 0x0, 0x0, 0x0, 0x0, // dev + 0x80, // qid.type == QTDIR + 0x0, 0x0, 0x0, 0x0, // qid.vers + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path + 0x4, 0x0, 0x0, 0x80, // mode + 0x25, 0x98, 0xb8, 0x43, // atime + 0x25, 0x98, 0xb8, 0x43, // mtime + 0x3e, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length + 0x2, 0x0, + 0x2e, 0x2e, // .. + 0x3, 0x0, + 0x35, 0x30, 0x31, // 501 + 0x2, 0x0, + 0x32, 0x30, // 20 + 0x4, 0x0, + 0x6e, 0x6f, 0x6e, 0x65, // none + + 0x3d, 0x0, + 0x0, 0x0, // type + 0x0, 0x0, 0x0, 0x0, // dev + 0x80, // qid.type == QTDIR + 0x0, 0x0, 0x0, 0x0, // qid.vers + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.Path + 0x4, 0x0, 0x0, 0x80, // mode + 0x25, 0x98, 0xb8, 0x43, // atime + 0x25, 0x98, 0xb8, 0x43, // mtime + 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length + 0x5, 0x0, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, // hello + 0x3, 0x0, + 0x35, 0x30, 0x31, // 501 + 0x2, 0x0, + 0x32, 0x30, // 20 + 0x4, 0x0, + 0x6e, 0x6f, 0x6e, 0x65, // none + + 0x3d, 0x0, + 0x0, 0x0, // type + 0x0, 0x0, 0x0, 0x0, // dev + 0x80, // qid.type == QTDIR + 0x0, 0x0, 0x0, 0x0, //qid.vers + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path + 0x4, 0x0, 0x0, 0x80, // mode + 0x25, 0x98, 0xb8, 0x43, // atime + 0x25, 0x98, 0xb8, 0x43, // mtime + 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length + 0x5, 0x0, + 0x74, 0x68, 0x65, 0x72, 0x65, // there + 0x3, 0x0, + 0x35, 0x30, 0x31, // 501 + 0x2, 0x0, + 0x32, 0x30, // 20 + 0x4, 0x0, + 0x6e, 0x6f, 0x6e, 0x65, // none + }, }, { description: "Rerror fcall",