Documentation ¶
Overview ¶
Package protocol is a generated protocol buffer package.
It is generated from these files:
gopkg.in/bblfsh/sdk.v1/protocol/generated.proto
It has these top-level messages:
NativeParseRequest NativeParseResponse ParseRequest ParseResponse VersionRequest VersionResponse
Example ¶
package main import ( "context" "fmt" "net" "time" "gopkg.in/bblfsh/sdk.v1/protocol" "google.golang.org/grpc" ) func main() { protocol.DefaultService = NewServiceMock() lis, err := net.Listen("tcp", "localhost:0") checkError(err) server := grpc.NewServer() protocol.RegisterProtocolServiceServer( server, protocol.NewProtocolServiceServer(), ) go server.Serve(lis) conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTimeout(time.Second*2), grpc.WithInsecure()) checkError(err) client := protocol.NewProtocolServiceClient(conn) req := &protocol.ParseRequest{Content: "my source code"} fmt.Println("Sending Parse for:", req.Content) resp, err := client.Parse(context.TODO(), req) checkError(err) fmt.Println("Got response with status:", resp.Status) server.GracefulStop() } func checkError(err error) { if err != nil { panic(err) } } // ServiceMock implements the protocol.Servce interface and the methods to be // used in the test. type ServiceMock struct { P func(req *protocol.ParseRequest) *protocol.ParseResponse N func(req *protocol.NativeParseRequest) *protocol.NativeParseResponse V func(*protocol.VersionRequest) *protocol.VersionResponse } func NewServiceMock() *ServiceMock { return &ServiceMock{ P: func(req *protocol.ParseRequest) *protocol.ParseResponse { return &protocol.ParseResponse{ Response: protocol.Response{Status: protocol.Ok}, } }, N: func(req *protocol.NativeParseRequest) *protocol.NativeParseResponse { return &protocol.NativeParseResponse{ Response: protocol.Response{Status: protocol.Ok}, } }, } } func (m *ServiceMock) Parse(req *protocol.ParseRequest) *protocol.ParseResponse { return m.P(req) } func (m *ServiceMock) NativeParse(req *protocol.NativeParseRequest) *protocol.NativeParseResponse { return m.N(req) } func (m *ServiceMock) Version(req *protocol.VersionRequest) *protocol.VersionResponse { return m.V(req) }
Output: Sending Parse for: my source code Got response with status: Ok
Index ¶
- Variables
- func NewProtocolServiceServer() *protocolServiceServer
- func RegisterProtocolServiceServer(s *grpc.Server, srv ProtocolServiceServer)
- type Encoding
- type NativeParseRequest
- func (*NativeParseRequest) Descriptor() ([]byte, []int)
- func (m *NativeParseRequest) Marshal() (dAtA []byte, err error)
- func (m *NativeParseRequest) MarshalTo(dAtA []byte) (int, error)
- func (*NativeParseRequest) ProtoMessage()
- func (m *NativeParseRequest) ProtoSize() (n int)
- func (m *NativeParseRequest) Reset()
- func (m *NativeParseRequest) String() string
- func (m *NativeParseRequest) Unmarshal(dAtA []byte) error
- type NativeParseResponse
- func (*NativeParseResponse) Descriptor() ([]byte, []int)
- func (m *NativeParseResponse) Marshal() (dAtA []byte, err error)
- func (m *NativeParseResponse) MarshalTo(dAtA []byte) (int, error)
- func (*NativeParseResponse) ProtoMessage()
- func (m *NativeParseResponse) ProtoSize() (n int)
- func (m *NativeParseResponse) Reset()
- func (r *NativeParseResponse) String() string
- func (m *NativeParseResponse) Unmarshal(dAtA []byte) error
- type ParseRequest
- func (*ParseRequest) Descriptor() ([]byte, []int)
- func (m *ParseRequest) Marshal() (dAtA []byte, err error)
- func (m *ParseRequest) MarshalTo(dAtA []byte) (int, error)
- func (*ParseRequest) ProtoMessage()
- func (m *ParseRequest) ProtoSize() (n int)
- func (m *ParseRequest) Reset()
- func (m *ParseRequest) String() string
- func (m *ParseRequest) Unmarshal(dAtA []byte) error
- type ParseResponse
- func (*ParseResponse) Descriptor() ([]byte, []int)
- func (m *ParseResponse) Marshal() (dAtA []byte, err error)
- func (m *ParseResponse) MarshalTo(dAtA []byte) (int, error)
- func (*ParseResponse) ProtoMessage()
- func (m *ParseResponse) ProtoSize() (n int)
- func (m *ParseResponse) Reset()
- func (r *ParseResponse) String() string
- func (m *ParseResponse) Unmarshal(dAtA []byte) error
- type ProtocolServiceClient
- type ProtocolServiceServer
- type Response
- type Service
- type Status
- type VersionRequest
- func (*VersionRequest) Descriptor() ([]byte, []int)
- func (m *VersionRequest) Marshal() (dAtA []byte, err error)
- func (m *VersionRequest) MarshalTo(dAtA []byte) (int, error)
- func (*VersionRequest) ProtoMessage()
- func (m *VersionRequest) ProtoSize() (n int)
- func (m *VersionRequest) Reset()
- func (m *VersionRequest) String() string
- func (m *VersionRequest) Unmarshal(dAtA []byte) error
- type VersionResponse
- func (*VersionResponse) Descriptor() ([]byte, []int)
- func (m *VersionResponse) Marshal() (dAtA []byte, err error)
- func (m *VersionResponse) MarshalTo(dAtA []byte) (int, error)
- func (*VersionResponse) ProtoMessage()
- func (m *VersionResponse) ProtoSize() (n int)
- func (m *VersionResponse) Reset()
- func (m *VersionResponse) String() string
- func (m *VersionResponse) Unmarshal(dAtA []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowGenerated = fmt.Errorf("proto: integer overflow") )
var Encoding_name = map[int32]string{
0: "UTF8",
1: "BASE64",
}
Encoding is the encoding used for the content string. Currently only UTF-8 or Base64 encodings are supported. You should use UTF-8 if you can and Base64 as a fallback.
var Encoding_value = map[string]int32{
"UTF8": 0,
"BASE64": 1,
}
var Status_name = map[int32]string{
0: "OK",
1: "ERROR",
2: "FATAL",
}
Status is the status of a response.
var Status_value = map[string]int32{
"OK": 0,
"ERROR": 1,
"FATAL": 2,
}
Functions ¶
func NewProtocolServiceServer ¶
func NewProtocolServiceServer() *protocolServiceServer
func RegisterProtocolServiceServer ¶
func RegisterProtocolServiceServer(s *grpc.Server, srv ProtocolServiceServer)
Types ¶
type Encoding ¶
type Encoding byte
Encoding is the encoding used for the content string. Currently only UTF-8 or Base64 encodings are supported. You should use UTF-8 if you can and Base64 as a fallback.
func (Encoding) EnumDescriptor ¶
type NativeParseRequest ¶ added in v1.1.0
type NativeParseRequest ParseRequest
NativeParseRequest is a request to parse a file and get its native AST.
func (*NativeParseRequest) Descriptor ¶ added in v1.1.0
func (*NativeParseRequest) Descriptor() ([]byte, []int)
func (*NativeParseRequest) Marshal ¶ added in v1.1.0
func (m *NativeParseRequest) Marshal() (dAtA []byte, err error)
func (*NativeParseRequest) MarshalTo ¶ added in v1.1.0
func (m *NativeParseRequest) MarshalTo(dAtA []byte) (int, error)
func (*NativeParseRequest) ProtoMessage ¶ added in v1.1.0
func (*NativeParseRequest) ProtoMessage()
func (*NativeParseRequest) ProtoSize ¶ added in v1.1.0
func (m *NativeParseRequest) ProtoSize() (n int)
func (*NativeParseRequest) Reset ¶ added in v1.1.0
func (m *NativeParseRequest) Reset()
func (*NativeParseRequest) String ¶ added in v1.1.0
func (m *NativeParseRequest) String() string
func (*NativeParseRequest) Unmarshal ¶ added in v1.1.0
func (m *NativeParseRequest) Unmarshal(dAtA []byte) error
type NativeParseResponse ¶ added in v1.1.0
type NativeParseResponse struct { Response // AST contains the AST from the parsed code in json format. AST string `json:"ast"` // Language. The language that was parsed. Usedful if you used language // autodetection for the request. Language string `json:"language"` }
NativeParseResponse is the reply to NativeParseRequest by the native parser.
func NativeParse ¶ added in v1.1.0
func NativeParse(req *NativeParseRequest) *NativeParseResponse
NativeParse uses DefaultService to process the given parsing request to get the AST.
func (*NativeParseResponse) Descriptor ¶ added in v1.1.0
func (*NativeParseResponse) Descriptor() ([]byte, []int)
func (*NativeParseResponse) Marshal ¶ added in v1.1.0
func (m *NativeParseResponse) Marshal() (dAtA []byte, err error)
func (*NativeParseResponse) MarshalTo ¶ added in v1.1.0
func (m *NativeParseResponse) MarshalTo(dAtA []byte) (int, error)
func (*NativeParseResponse) ProtoMessage ¶ added in v1.1.0
func (*NativeParseResponse) ProtoMessage()
func (*NativeParseResponse) ProtoSize ¶ added in v1.1.0
func (m *NativeParseResponse) ProtoSize() (n int)
func (*NativeParseResponse) Reset ¶ added in v1.1.0
func (m *NativeParseResponse) Reset()
func (*NativeParseResponse) String ¶ added in v1.1.0
func (r *NativeParseResponse) String() string
func (*NativeParseResponse) Unmarshal ¶ added in v1.1.0
func (m *NativeParseResponse) Unmarshal(dAtA []byte) error
type ParseRequest ¶
type ParseRequest struct { // Filename is the name of the file containing the source code. Used for // language detection. Only filename is required, path might be used but // ignored. This is optional. Filename string `json:"filename"` // Language. If specified, it will override language detection. This is // optional. Language string `json:"language"` // Content is the source code to be parsed. Content string `json:"content"` // Encoding is the encoding that the Content uses. Currently only UTF-8 and // Base64 are supported. Encoding Encoding `json:"encoding"` // Timeout amount of time for wait until the request is proccessed. Timeout time.Duration `json:"timeout"` }
ParseRequest is a request to parse a file and get its UAST.
func (*ParseRequest) Descriptor ¶
func (*ParseRequest) Descriptor() ([]byte, []int)
func (*ParseRequest) Marshal ¶
func (m *ParseRequest) Marshal() (dAtA []byte, err error)
func (*ParseRequest) ProtoMessage ¶
func (*ParseRequest) ProtoMessage()
func (*ParseRequest) ProtoSize ¶
func (m *ParseRequest) ProtoSize() (n int)
func (*ParseRequest) Reset ¶
func (m *ParseRequest) Reset()
func (*ParseRequest) String ¶
func (m *ParseRequest) String() string
func (*ParseRequest) Unmarshal ¶
func (m *ParseRequest) Unmarshal(dAtA []byte) error
type ParseResponse ¶
type ParseResponse struct { Response // UAST contains the UAST from the parsed code. UAST *uast.Node `json:"uast"` // Language. The language that was parsed. Usedful if you used language // autodetection for the request. Language string `json:"language"` }
ParseResponse is the reply to ParseRequest.
func Parse ¶
func Parse(req *ParseRequest) *ParseResponse
Parse uses DefaultService to process the given parsing request to get the UAST.
func (*ParseResponse) Descriptor ¶
func (*ParseResponse) Descriptor() ([]byte, []int)
func (*ParseResponse) Marshal ¶
func (m *ParseResponse) Marshal() (dAtA []byte, err error)
func (*ParseResponse) ProtoMessage ¶
func (*ParseResponse) ProtoMessage()
func (*ParseResponse) ProtoSize ¶
func (m *ParseResponse) ProtoSize() (n int)
func (*ParseResponse) Reset ¶
func (m *ParseResponse) Reset()
func (*ParseResponse) String ¶
func (r *ParseResponse) String() string
func (*ParseResponse) Unmarshal ¶
func (m *ParseResponse) Unmarshal(dAtA []byte) error
type ProtocolServiceClient ¶
type ProtocolServiceClient interface { // NativeParse uses DefaultService to process the given parsing request to get // the AST. NativeParse(ctx context.Context, in *NativeParseRequest, opts ...grpc.CallOption) (*NativeParseResponse, error) // Parse uses DefaultService to process the given parsing request to get the UAST. Parse(ctx context.Context, in *ParseRequest, opts ...grpc.CallOption) (*ParseResponse, error) // Version uses DefaultVersioner to process the given version request to get the version. Version(ctx context.Context, in *VersionRequest, opts ...grpc.CallOption) (*VersionResponse, error) }
func NewProtocolServiceClient ¶
func NewProtocolServiceClient(cc *grpc.ClientConn) ProtocolServiceClient
type ProtocolServiceServer ¶
type ProtocolServiceServer interface { // NativeParse uses DefaultService to process the given parsing request to get // the AST. NativeParse(context.Context, *NativeParseRequest) (*NativeParseResponse, error) // Parse uses DefaultService to process the given parsing request to get the UAST. Parse(context.Context, *ParseRequest) (*ParseResponse, error) // Version uses DefaultVersioner to process the given version request to get the version. Version(context.Context, *VersionRequest) (*VersionResponse, error) }
type Response ¶ added in v1.1.0
type Response struct { // Status is the status of the parsing request. Status Status `json:"status"` // Status is the status of the parsing request. Errors []string `json:"errors"` // Elapsed is the amount of time consume processing the request. Elapsed time.Duration `json:"elapsed"` }
Response basic response, never used directly.
type Service ¶ added in v1.1.0
type Service interface { Parse(*ParseRequest) *ParseResponse NativeParse(*NativeParseRequest) *NativeParseResponse Version(*VersionRequest) *VersionResponse }
Service can parse code to UAST or AST.
var DefaultService Service
DefaultService is the default service used to process requests.
type VersionRequest ¶
type VersionRequest struct{}
VersionRequest is a request to get server version
func (*VersionRequest) Descriptor ¶
func (*VersionRequest) Descriptor() ([]byte, []int)
func (*VersionRequest) Marshal ¶
func (m *VersionRequest) Marshal() (dAtA []byte, err error)
func (*VersionRequest) ProtoMessage ¶
func (*VersionRequest) ProtoMessage()
func (*VersionRequest) ProtoSize ¶
func (m *VersionRequest) ProtoSize() (n int)
func (*VersionRequest) Reset ¶
func (m *VersionRequest) Reset()
func (*VersionRequest) String ¶
func (m *VersionRequest) String() string
func (*VersionRequest) Unmarshal ¶
func (m *VersionRequest) Unmarshal(dAtA []byte) error
type VersionResponse ¶
type VersionResponse struct { Response // Version is the server version. If is a local compilation the version // follows the pattern dev-<short-commit>[-dirty], dirty means that was // compile from a repository with un-committed changes. Version string `json:"version"` // Build contains the timestamp at the time of the build. Build time.Time `json:"build"` }
VersionResponse is the reply to VersionRequest
func Version ¶
func Version(req *VersionRequest) *VersionResponse
Version uses DefaultVersioner to process the given version request to get the version.
func (*VersionResponse) Descriptor ¶
func (*VersionResponse) Descriptor() ([]byte, []int)
func (*VersionResponse) Marshal ¶
func (m *VersionResponse) Marshal() (dAtA []byte, err error)
func (*VersionResponse) ProtoMessage ¶
func (*VersionResponse) ProtoMessage()
func (*VersionResponse) ProtoSize ¶
func (m *VersionResponse) ProtoSize() (n int)
func (*VersionResponse) Reset ¶
func (m *VersionResponse) Reset()
func (*VersionResponse) String ¶
func (m *VersionResponse) String() string
func (*VersionResponse) Unmarshal ¶
func (m *VersionResponse) Unmarshal(dAtA []byte) error