signature

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MetaObjectSignature = "" /* 287-byte string literal not displayed */

MetaObjectSignature is the signature of MetaObject. It is used to generate the MetaObject struct which is used to generate the services. This step is referred as stage 1.

Variables

View Source
var ObjectSignature = fmt.Sprintf("(%sII)<ObjectReference,metaObject,serviceID,objectID>",
	MetaObjectSignature)

ObjectSignature is the signature of ObjectReference.

Functions

func CleanMethodName

func CleanMethodName(name string) string

func CleanName

func CleanName(name string) string

CleanName remove funky character from a name

func CleanVarName

func CleanVarName(i int, name string) string

func GenerateType

func GenerateType(v Type, packageName string, w io.Writer) error

GenerateType generate the code required to serialize the given type.

func Print

func Print(v Type) string

Print render the type into a string. It is only used for testing.

func TypeIsObjectReference

func TypeIsObjectReference(t Type) bool

func ValidName

func ValidName(name string) string

Types

type EnumMember

type EnumMember struct {
	Const string
	Value int
}

EnumMember is used during Enum parsing

type EnumType

type EnumType struct {
	Name   string
	Values map[string]int
}

EnumType represents a const.

func (*EnumType) Marshal

func (e *EnumType) Marshal(id string, writer string) *Statement

Marshal returns a statement which represent the code needed to put the variable "id" into the io.Writer "writer" while returning an error.

func (*EnumType) Reader

func (e *EnumType) Reader() TypeReader

Reader returns an enum TypeReader.

func (*EnumType) RegisterTo

func (e *EnumType) RegisterTo(set *TypeSet)

RegisterTo adds the enum to the type set.

func (*EnumType) Signature

func (e *EnumType) Signature() string

Signature returns "i" since enum are integer constant.

func (*EnumType) SignatureIDL

func (e *EnumType) SignatureIDL() string

SignatureIDL returns the name of the enum.

func (*EnumType) Type

func (e *EnumType) Type() reflect.Type

Type returns the Go representation of the type.

func (*EnumType) TypeDeclaration

func (e *EnumType) TypeDeclaration(file *jen.File)

TypeDeclaration writes the type declaration into file.

func (*EnumType) TypeName

func (e *EnumType) TypeName() *Statement

TypeName returns a statement to be inserted when the type is to be declared.

func (*EnumType) Unmarshal

func (e *EnumType) Unmarshal(reader string) *Statement

Unmarshal returns a statement which represent the code needed to read from a reader "reader" of type io.Reader and returns both the value read and an error.

type ListType

type ListType struct {
	// contains filtered or unexported fields
}

ListType represents a slice.

func NewListType

func NewListType(value Type) *ListType

NewListType is a contructor for the representation of a slice.

func (*ListType) Marshal

func (l *ListType) Marshal(listID string, writer string) *Statement

Marshal returns a statement which represent the code needed to put the variable "id" into the io.Writer "writer" while returning an error.

func (*ListType) Reader

func (l *ListType) Reader() TypeReader

Reader returns a list TypeReader.

func (*ListType) RegisterTo

func (l *ListType) RegisterTo(s *TypeSet)

RegisterTo adds the type to the TypeSet.

func (*ListType) Signature

func (l *ListType) Signature() string

Signature returns "[<signature>]" where <signature> is the signature of the type of the list.

func (*ListType) SignatureIDL

func (l *ListType) SignatureIDL() string

SignatureIDL returns "Vec<signature>" where "signature" is the IDL signature of the type of the list.

func (*ListType) Type

func (l *ListType) Type() reflect.Type

Type returns the Go representation of the type.

func (*ListType) TypeDeclaration

func (l *ListType) TypeDeclaration(file *jen.File)

TypeDeclaration writes the type declaration into file.

func (*ListType) TypeName

func (l *ListType) TypeName() *Statement

TypeName returns a statement to be inserted when the type is to be declared.

func (*ListType) Unmarshal

func (l *ListType) Unmarshal(reader string) *Statement

Unmarshal returns a statement which represent the code needed to read from a reader "reader" of type io.Reader and returns both the value read and an error.

type MapType

type MapType struct {
	// contains filtered or unexported fields
}

MapType represents a map.

func NewMapType

func NewMapType(key, value Type) *MapType

NewMapType is a contructor for the representation of a map.

func (*MapType) Marshal

func (m *MapType) Marshal(mapID string, writer string) *Statement

Marshal returns a statement which represent the code needed to put the variable "id" into the io.Writer "writer" while returning an error.

func (*MapType) Reader

func (m *MapType) Reader() TypeReader

Reader returns a map TypeReader.

func (*MapType) RegisterTo

func (m *MapType) RegisterTo(s *TypeSet)

RegisterTo adds the type to the TypeSet.

func (*MapType) Signature

func (m *MapType) Signature() string

Signature returns "{<signature key><signature value>}" where <signature key> is the signature of the key and <signature value> the signature of the value.

func (*MapType) SignatureIDL

func (m *MapType) SignatureIDL() string

SignatureIDL returns "map<key><value>" where "key" is the IDL signature of the key and "value" the IDL signature of the value.

func (*MapType) Type

func (m *MapType) Type() reflect.Type

Type returns the Go representation of the type.

func (*MapType) TypeDeclaration

func (m *MapType) TypeDeclaration(file *jen.File)

TypeDeclaration writes the type declaration into file.

func (*MapType) TypeName

func (m *MapType) TypeName() *Statement

TypeName returns a statement to be inserted when the type is to be declared.

func (*MapType) Unmarshal

func (m *MapType) Unmarshal(reader string) *Statement

Unmarshal returns a statement which represent the code needed to read from a reader "reader" of type io.Reader and returns both the value read and an error.

type MemberType

type MemberType struct {
	Name string
	Type Type
}

MemberType a field in a struct.

func NewMemberType

func NewMemberType(name string, value Type) MemberType

NewMemberType is a contructor for the representation of a field in a struct.

func (MemberType) Title

func (m MemberType) Title() string

Title is the public name of the field.

type Node

type Node = parsec.ParsecNode

Node is an alias to parsec.ParsecNode

type Statement

type Statement = jen.Statement

Statement is a short version for jen.Statement.

type StructType

type StructType struct {
	Name    string
	Members []MemberType
}

StructType represents a struct.

func NewStructType

func NewStructType(name string, members []MemberType) *StructType

NewStructType is a contructor for the representation of a struct.

func (*StructType) Marshal

func (s *StructType) Marshal(structID string, writer string) *Statement

Marshal returns a statement which represent the code needed to put the variable "id" into the io.Writer "writer" while returning an error.

func (*StructType) Reader

func (s *StructType) Reader() TypeReader

Reader returns a struct TypeReader.

func (*StructType) RegisterTo

func (s *StructType) RegisterTo(set *TypeSet)

RegisterTo adds the type to the TypeSet. Structure name is updated if needed after collision resolution. Register search if a type is in the TypeSet under a given name. If the same name and signature is already present it does nothing. otherwise it adds the type and search for a new which does not conflict with the names already present.

func (*StructType) Signature

func (s *StructType) Signature() string

Signature returns the signature of the struct.

func (*StructType) SignatureIDL

func (s *StructType) SignatureIDL() string

SignatureIDL returns the idl signature of the struct.

func (*StructType) Type

func (s *StructType) Type() reflect.Type

Type returns the Go representation of the type.

func (*StructType) TypeDeclaration

func (s *StructType) TypeDeclaration(file *jen.File)

TypeDeclaration writes the type declaration into file.

func (*StructType) TypeName

func (s *StructType) TypeName() *Statement

TypeName returns a statement to be inserted when the type is to be declared.

func (*StructType) Unmarshal

func (s *StructType) Unmarshal(reader string) *Statement

Unmarshal returns a statement which represent the code needed to read from a reader "reader" of type io.Reader and returns both the value read and an error.

type TupleType

type TupleType struct {
	Members []MemberType
}

TupleType a list of a parameter of a method.

func NewTupleType

func NewTupleType(values []Type) *TupleType

NewTupleType is a contructor for the representation of a series of types. Used to describe a method parameters list.

func (*TupleType) ConvertMetaObjects

func (t *TupleType) ConvertMetaObjects()

ConvertMetaObjects replace any element type which has the same signature as MetaObject with an element of the type object.MetaObject. This is required to generate proxy services which implements the object.Object interface and avoid a circular dependency.

func (*TupleType) Marshal

func (t *TupleType) Marshal(tupleID string, writer string) *Statement

Marshal returns a statement which represent the code needed to put the variable "id" into the io.Writer "writer" while returning an error.

func (*TupleType) ParamIDL

func (t *TupleType) ParamIDL() string

ParamIDL returns "name1 signature1, name2 signature2" where signatureX is the signature of the elements.

func (*TupleType) Params

func (t *TupleType) Params() *Statement

Params returns a statement representing the list of parameter of a method.

func (*TupleType) Reader

func (t *TupleType) Reader() TypeReader

Reader returns a map TypeReader.

func (*TupleType) RegisterTo

func (t *TupleType) RegisterTo(s *TypeSet)

RegisterTo adds the type to the TypeSet.

func (*TupleType) Signature

func (t *TupleType) Signature() string

Signature returns "(<signature 1><signature 2>...)" where <signature X> is the signature of the elements.

func (*TupleType) SignatureIDL

func (t *TupleType) SignatureIDL() string

SignatureIDL returns "Tuple<signature1,signature2>" where signatureX is the signature of the elements.

func (*TupleType) Type

func (t *TupleType) Type() reflect.Type

Type returns the Go representation of the type.

func (*TupleType) TypeDeclaration

func (t *TupleType) TypeDeclaration(*jen.File)

TypeDeclaration writes the type declaration into file.

func (*TupleType) TypeName

func (t *TupleType) TypeName() *Statement

TypeName returns a statement to be inserted when the type is to be declared.

func (*TupleType) Unmarshal

func (t *TupleType) Unmarshal(reader string) *Statement

Unmarshal returns a statement which represent the code needed to read from a reader "reader" of type io.Reader and returns both the value read and an error.

type Type

type Type interface {
	Signature() string
	SignatureIDL() string
	TypeName() *Statement
	TypeDeclaration(*jen.File)
	RegisterTo(s *TypeSet)
	Marshal(id string, writer string) *Statement // returns an error
	Unmarshal(reader string) *Statement          // returns (type, err)
	Reader() TypeReader
	Type() reflect.Type
}

Type represents a type of a signature or a type embedded inside a signature. Type represents types for primitive types (int, long, float, string), vectors of a type, associative maps and structures.

func NewBoolType

func NewBoolType() Type

NewBoolType is a contructor for the representation of a bool.

func NewDoubleType

func NewDoubleType() Type

NewDoubleType is a contructor for the representation of a float32.

func NewEnumType

func NewEnumType(name string, values map[string]int) Type

NewEnumType returns an enum type

func NewFloatType

func NewFloatType() Type

NewFloatType is a contructor for the representation of a float32.

func NewInt16Type

func NewInt16Type() Type

NewInt16Type is a contructor for the representation of a uint64.

func NewInt8Type

func NewInt8Type() Type

NewInt8Type is a contructor for the representation of a uint64.

func NewIntType

func NewIntType() Type

NewIntType is a contructor for the representation of an int32.

func NewLongType

func NewLongType() Type

NewLongType is a contructor for the representation of a uint64.

func NewMetaObjectType

func NewMetaObjectType() Type

NewMetaObjectType is a contructor for the representation of an object.

func NewObjectType

func NewObjectType() Type

NewObjectType is a contructor for the representation of a Value.

func NewStringType

func NewStringType() Type

NewStringType is a contructor for the representation of a string.

func NewULongType

func NewULongType() Type

NewULongType is a contructor for the representation of a uint64.

func NewUint16Type

func NewUint16Type() Type

NewUint16Type is a contructor for the representation of a uint64.

func NewUint8Type

func NewUint8Type() Type

NewUint8Type is a contructor for the representation of a uint64.

func NewUintType

func NewUintType() Type

NewUIntType is a contructor for the representation of an uint32.

func NewUnknownType

func NewUnknownType() Type

NewUnknownType is a contructor for an unknown type.

func NewValueType

func NewValueType() Type

NewValueType is a contructor for the representation of a Value.

func NewVoidType

func NewVoidType() Type

NewVoidType is a contructor for the representation of the absence of a return type. Only used in the context of a returned type.

func Parse

func Parse(input string) (Type, error)

Parse reads a signature contained in a string and constructs its type representation.

type TypeReader

type TypeReader interface {
	Read(r io.Reader) ([]byte, error)
}

TypeReader reads from r the bytes representing the type

func MakeReader

func MakeReader(sig string) (TypeReader, error)

MakeReader parse the signature and returns its associated Reader.

type TypeSet

type TypeSet struct {
	Names []string
	Types []Type
}

TypeSet is a container which contains exactly one instance of each Type currently generated. It is used to generate the type declaration only once.

func NewTypeSet

func NewTypeSet() *TypeSet

NewTypeSet construct a new TypeSet.

func (*TypeSet) Declare

func (s *TypeSet) Declare(f *jen.File)

Declare writes all the registered Type into the jen.File.

func (*TypeSet) ResolveCollision

func (s *TypeSet) ResolveCollision(originalName, signature string) string

ResolveCollision returns a type name not already present in the set. If name if not present, returns name, else it returns a new string derived from name.

func (*TypeSet) Search

func (s *TypeSet) Search(name string) Type

Search returns a Type if a name is associated.

type UnknownReader

type UnknownReader string

UnknownReader is a TypeReader which returns an error.

func (UnknownReader) Read

func (v UnknownReader) Read(r io.Reader) ([]byte, error)

Jump to

Keyboard shortcuts

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