protocol

package
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2018 License: GPL-3.0 Imports: 13 Imported by: 39

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

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowGenerated   = fmt.Errorf("proto: integer overflow")
)
View Source
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.

View Source
var Encoding_value = map[string]int32{
	"UTF8":   0,
	"BASE64": 1,
}
View Source
var Status_name = map[int32]string{
	0: "OK",
	1: "ERROR",
	2: "FATAL",
}

Status is the status of a response.

View Source
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.

const (
	// UTF8 encoding
	UTF8 Encoding = iota
	// Base64 encoding
	Base64
)

func (Encoding) EnumDescriptor

func (Encoding) EnumDescriptor() ([]byte, []int)

func (Encoding) String

func (i Encoding) String() string

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) MarshalTo

func (m *ParseRequest) MarshalTo(dAtA []byte) (int, 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) MarshalTo

func (m *ParseResponse) MarshalTo(dAtA []byte) (int, 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 Status

type Status byte

Status is the status of a response.

const (
	// Ok status code.
	Ok Status = iota
	// Error status code. It is replied when the driver has got the AST with errors.
	Error
	// Fatal status code. It is replied when the driver hasn't could get the AST.
	Fatal
)

func (Status) EnumDescriptor

func (Status) EnumDescriptor() ([]byte, []int)

func (Status) String

func (i Status) String() string

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) MarshalTo

func (m *VersionRequest) MarshalTo(dAtA []byte) (int, 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) MarshalTo

func (m *VersionResponse) MarshalTo(dAtA []byte) (int, 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL