Minor changes

Add copyright
Return proto.Marshal(fd)
Comments
This commit is contained in:
Menghan Li
2016-06-21 15:30:00 -07:00
parent 69c7425a21
commit 439f11e63d
2 changed files with 40 additions and 22 deletions

View File

@ -185,11 +185,7 @@ func (s *serverReflectionServer) fileDescEncodingByFilename(name string) ([]byte
if err != nil { if err != nil {
return nil, err return nil, err
} }
b, err := proto.Marshal(fd) return proto.Marshal(fd)
if err != nil {
return nil, err
}
return b, nil
} }
// fileDescEncodingContainingSymbol finds the file descriptor containing the given symbol, // fileDescEncodingContainingSymbol finds the file descriptor containing the given symbol,
@ -210,8 +206,7 @@ func (s *serverReflectionServer) fileDescEncodingContainingSymbol(name string) (
meta := s.s.ServiceMetadata(name, "") meta := s.s.ServiceMetadata(name, "")
// Check if it's a method name. // Check if it's a method name.
if meta == nil { if meta == nil {
pos := strings.LastIndex(name, ".") if pos := strings.LastIndex(name, "."); pos != -1 {
if pos != -1 {
meta = s.s.ServiceMetadata(name[:pos], name[pos+1:]) meta = s.s.ServiceMetadata(name[:pos], name[pos+1:])
} }
} }
@ -225,15 +220,10 @@ func (s *serverReflectionServer) fileDescEncodingContainingSymbol(name string) (
} }
} }
// Marshal to wire format. if fd == nil {
if fd != nil { return nil, fmt.Errorf("unknown symbol: %v", name)
b, err := proto.Marshal(fd)
if err != nil {
return nil, err
}
return b, nil
} }
return nil, fmt.Errorf("unknown symbol: %v", name) return proto.Marshal(fd)
} }
// fileDescEncodingContainingExtension finds the file descriptor containing given extension, // fileDescEncodingContainingExtension finds the file descriptor containing given extension,
@ -247,11 +237,7 @@ func (s *serverReflectionServer) fileDescEncodingContainingExtension(typeName st
if err != nil { if err != nil {
return nil, err return nil, err
} }
b, err := proto.Marshal(fd) return proto.Marshal(fd)
if err != nil {
return nil, err
}
return b, nil
} }
// allExtensionNumbersForTypeName returns all extension numbers for the given type. // allExtensionNumbersForTypeName returns all extension numbers for the given type.
@ -268,7 +254,6 @@ func (s *serverReflectionServer) allExtensionNumbersForTypeName(name string) ([]
} }
// ServerReflectionInfo is the reflection service handler. // ServerReflectionInfo is the reflection service handler.
// It calls help function for the received request, and sends response back.
func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflection_ServerReflectionInfoServer) error { func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflection_ServerReflectionInfoServer) error {
for { for {
in, err := stream.Recv() in, err := stream.Recv()

View File

@ -1,3 +1,36 @@
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package reflection package reflection
import ( import (
@ -21,7 +54,7 @@ var (
fdTest *dpb.FileDescriptorProto fdTest *dpb.FileDescriptorProto
fdProto2 *dpb.FileDescriptorProto fdProto2 *dpb.FileDescriptorProto
fdProto2Ext *dpb.FileDescriptorProto fdProto2Ext *dpb.FileDescriptorProto
// fileDescriptor marshelled. // fileDescriptor marshalled.
fdTestByte []byte fdTestByte []byte
fdProto2Byte []byte fdProto2Byte []byte
fdProto2ExtByte []byte fdProto2ExtByte []byte