File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,25 @@ func (self Node) int() (int, error) {
128128 }
129129}
130130
131+ // Enum returns the int value contained by a Enum node
132+ func (self Node ) Enum () (int , error ) {
133+ if self .IsError () {
134+ return 0 , self
135+ }
136+ return self .enum ()
137+ }
138+
139+ func (self Node ) enum () (int , error ) {
140+ buf := rt .BytesFrom (self .v , int (self .l ), int (self .l ))
141+ switch self .t {
142+ case proto .ENUM :
143+ v , _ := protowire.BinaryDecoder {}.DecodeInt32 (buf )
144+ return int (v ), nil
145+ default :
146+ return 0 , errNode (meta .ErrUnsupportedType , "Node.enum: the Node type is not Enum" , nil )
147+ }
148+ }
149+
131150// Float64 returns the float64 value contained by a DOUBLE node
132151func (self Node ) Float64 () (float64 , error ) {
133152 if self .IsError () {
@@ -336,6 +355,8 @@ func (self Value) Interface(opts *Options) (interface{}, error) {
336355 return self .binary ()
337356 }
338357 return self .string ()
358+ case proto .ENUM :
359+ return self .enum ()
339360 case proto .LIST :
340361 return self .List (opts )
341362 case proto .MAP :
You can’t perform that action at this time.
0 commit comments