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:
ParseRequest ParseResponse VersionRequest VersionResponse
Example ¶
package main
import (
"context"
"fmt"
"net"
"time"
"gopkg.in/bblfsh/sdk.v1/protocol"
"google.golang.org/grpc"
)
type mockParser struct{}
func (p *mockParser) Parse(req *protocol.ParseRequest) *protocol.ParseResponse {
return &protocol.ParseResponse{Status: protocol.Ok}
}
func (p *mockParser) Close() error {
return nil
}
func main() {
lis, err := net.Listen("tcp", ":0")
checkError(err)
// Use a mock parser on the server.
protocol.DefaultParser = &mockParser{}
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.String())
server.GracefulStop()
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
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 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 (m *ParseResponse) String() string
- func (m *ParseResponse) Unmarshal(dAtA []byte) error
- type Parser
- type ProtocolServiceClient
- type ProtocolServiceServer
- 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
- type Versioner
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 ¶
func (Encoding) MarshalJSON ¶
func (*Encoding) UnmarshalJSON ¶
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
// Language. If specified, it will override language detection. This is
// optional.
Language string
// 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"`
}
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 {
// Status is the status of the parsing request.
Status Status `json:"status"`
// Errors contains a list of parsing errors. If Status is ok, this list
// should always be empty.
Errors []string `json:"errors"`
// UAST contains the UAST from the parsed code.
UAST *uast.Node `json:"uast"`
}
ParseResponse is the reply to ParseRequest.
func Parse ¶
func Parse(req *ParseRequest) *ParseResponse
Parse uses DefaultParser 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 (m *ParseResponse) String() string
func (*ParseResponse) Unmarshal ¶
func (m *ParseResponse) Unmarshal(dAtA []byte) error
type Parser ¶
type Parser interface {
Parse(*ParseRequest) *ParseResponse
}
Parser can parse code to UAST.
var DefaultParser Parser
DefaultParser is the default parser used by Parse and ParseNative.
type ProtocolServiceClient ¶
type ProtocolServiceClient interface {
// Parse uses DefaultParser 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 {
// Parse uses DefaultParser 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 Status ¶
type Status byte
Status is the status of a response.
func (Status) EnumDescriptor ¶
func (Status) MarshalJSON ¶
func (*Status) UnmarshalJSON ¶
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 {
// Version is the server version
Version string `json:"version"`
}
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
type Versioner ¶
type Versioner interface {
Version(*VersionRequest) *VersionResponse
}
var DefaultVersioner Versioner
DefaultVersioner is the default versioner user by Version
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
testdriver
command
|
|
|
testnative
command
|
|
|
Package json lines mimicks standard library json Encoder and Decoder, but to encode and decode one JSON per line.
|
Package json lines mimicks standard library json Encoder and Decoder, but to encode and decode one JSON per line. |
|
native package is used to parse AST using an external binary.
|
native package is used to parse AST using an external binary. |