diff options
| author | Rob Pike <r@golang.org> | 2009-01-23 12:40:55 -0800 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2009-01-23 12:40:55 -0800 |
| commit | 1b3299ed0beb81066ea2baef3bd9eaf9428c3d11 (patch) | |
| tree | 21a39f9d956b044bb82cd1a9a68a6f80761ee963 /src/lib/reflect | |
| parent | 9e3b0f444ae27629b3e93b2e8d0d8ba0f6f939ba (diff) | |
| download | go-1b3299ed0beb81066ea2baef3bd9eaf9428c3d11.tar.xz | |
change the representation of arrays in protobufs from *[]item to []item.
for simplicity of user's code, optional arrays of bytes also don't have a pointer.
requires adding a "Set()" method to arrays in reflect.
still to do: protocol compilers, google/net/rpc.
R=rsc
DELTA=227 (36 added, 95 deleted, 96 changed)
OCL=23387
CL=23389
Diffstat (limited to 'src/lib/reflect')
| -rw-r--r-- | src/lib/reflect/value.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/reflect/value.go b/src/lib/reflect/value.go index 6fd4fe2458..85fb38bc2c 100644 --- a/src/lib/reflect/value.go +++ b/src/lib/reflect/value.go @@ -553,6 +553,7 @@ type ArrayValue interface { Cap() int; Elem(i int) Value; SetLen(len int); + Set(src ArrayValue); CopyFrom(src ArrayValue, n int) } @@ -598,6 +599,17 @@ func (v *openArrayValueStruct) SetLen(len int) { v.array.len = uint32(len); } +func (v *openArrayValueStruct) Set(src ArrayValue) { + if !src.Open() { + panic("can't set from fixed array"); + } + s := src.(*openArrayValueStruct); + if !equalType(v.typ, s.typ) { + panicln("incompatible array types in ArrayValue.Set()"); + } + *v.array = *s.array; +} + func (v *openArrayValueStruct) Elem(i int) Value { data_uint := uintptr(v.array.data) + uintptr(i * v.elemsize); return newValueAddr(v.elemtype, Addr(data_uint)); @@ -629,6 +641,10 @@ func (v *fixedArrayValueStruct) Cap() int { func (v *fixedArrayValueStruct) SetLen(len int) { } +func (v *fixedArrayValueStruct) Set(src ArrayValue) { + panicln("can't set fixed array"); +} + func (v *fixedArrayValueStruct) Elem(i int) Value { data_uint := uintptr(v.addr) + uintptr(i * v.elemsize); return newValueAddr(v.elemtype, Addr(data_uint)); |
