protocol

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2017 License: GPL-3.0 Imports: 9 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:

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

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

func (e Encoding) MarshalJSON() ([]byte, error)

func (Encoding) String

func (e Encoding) String() string

func (*Encoding) UnmarshalJSON

func (e *Encoding) UnmarshalJSON(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
	// 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) 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 {
	// 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) 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 (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.

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

func (s Status) MarshalJSON() ([]byte, error)

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

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 {
	// 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) 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

type Versioner

type Versioner interface {
	Version(*VersionRequest) *VersionResponse
}
var DefaultVersioner Versioner

DefaultVersioner is the default versioner user by Version

Directories

Path Synopsis
internal
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.

Jump to

Keyboard shortcuts

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