Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(501)

Issue 4942051: code review 4942051: reflect: add Value.Bytes, Value.SetBytes methods (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 11 months ago by rsc
Modified:
13 years, 11 months ago
Reviewers:
gustavo, rog
CC:
r, golang-dev
Visibility:
Public.

Description

reflect: add Value.Bytes, Value.SetBytes methods This allows code that wants to handle []byte separately to get at the actual slice instead of just at individual bytes. It seems to come up often enough.

Patch Set 1 #

Patch Set 2 : diff -r 59231dccb894 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 59231dccb894 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 59231dccb894 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+50 lines, -0 lines) Patch
M src/pkg/reflect/all_test.go View 1 2 1 chunk +25 lines, -0 lines 0 comments Download
M src/pkg/reflect/value.go View 1 2 2 chunks +25 lines, -0 lines 0 comments Download

Messages

Total messages: 10
rsc
Hello r (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 11 months ago (2011-08-24 02:45:58 UTC) #1
r
LGTM
13 years, 11 months ago (2011-08-24 02:48:29 UTC) #2
rsc
*** Submitted as http://code.google.com/p/go/source/detail?r=43a8f5250576 *** reflect: add Value.Bytes, Value.SetBytes methods This allows code that wants ...
13 years, 11 months ago (2011-08-24 02:50:11 UTC) #3
rog
i'm sure i'm being ignorant here, but what's the difference between - v.Bytes() and v.Interface().([]byte) ...
13 years, 11 months ago (2011-08-24 11:31:36 UTC) #4
rsc
On Wed, Aug 24, 2011 at 07:31, roger peppe <rogpeppe@gmail.com> wrote: > i'm sure i'm ...
13 years, 11 months ago (2011-08-24 12:59:31 UTC) #5
rog
On 24 August 2011 13:59, Russ Cox <rsc@golang.org> wrote: > On Wed, Aug 24, 2011 ...
13 years, 11 months ago (2011-08-24 22:24:35 UTC) #6
gustavo_niemeyer.net
> // Convert converts v to the given type. It panics > // if the ...
13 years, 11 months ago (2011-08-24 22:48:19 UTC) #7
rsc
> // Convert converts v to the given type. It panics > // if the ...
13 years, 11 months ago (2011-08-25 02:33:40 UTC) #8
rog
On 25 August 2011 03:33, Russ Cox <rsc@golang.org> wrote: >> // Convert converts v to ...
13 years, 11 months ago (2011-08-25 17:52:42 UTC) #9
rsc
13 years, 11 months ago (2011-08-25 17:53:53 UTC) #10
On Thu, Aug 25, 2011 at 13:52, roger peppe <rogpeppe@gmail.com> wrote:
> On 25 August 2011 03:33, Russ Cox <rsc@golang.org> wrote:
>>> // Convert converts v to the given type. It panics
>>> // if the type of v is not statically convertible to t.
>>> func (v Value) Convert(t Type) Value
>>
>> this basically already exists.
>>
>> i could write
>>
>> b := reflect.ValueOf(&[]byte{}).Elem()
>> b.Set(v)
>> b.Interface().([]byte)
>>
>> but i would rather write
>>
>> v.Bytes()
>>
>> the only thing Convert gets you beyond
>> Set+AssignableTo is being able to convert
>> directly between named types.
>> that's non-trivial (for example float64->int)
>> and not clearly necessary, since for the
>> trivial cases you can Set via an unnamed type.
>
> you can make an unnamed type out of a float64?

that's not a trivial case.

> i guess i don't see why []byte gets special treatment here;
> why not []int too, for instance?

because []byte comes up over and over
in code that uses reflect.  []int does not.

> a reflect analogue to the built-in conversion operator
> (even if some parts are non-trivial) seems to me like an
> obvious thing to add.

feel free to file an issue.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b