rpc

package
v0.0.0-...-6719cd2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package rpc contains ProtoBuf-generated types for the messages communicated between Akutan servers. It also contains some related types, such as FactSink and KGObject.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkReadyCallback

type ChunkReadyCallback func(*LookupChunk) error

ChunkReadyCallback will be called when the LookupSink has ready chunks to pass along This signature matches various grpc streaming endpoints

type FactSink

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

FactSink accumulates facts and sends them to the destination in large chunks.

func NewFactSink

func NewFactSink(readyCallback ChunkReadyCallback, flushAtSize int) *FactSink

NewFactSink constructs a new LookupSink, once 'flustAtSize' items have been accumulated the readyCallback function will be called with the new chunk

func (*FactSink) Flush

func (b *FactSink) Flush() error

Flush sends a chunk of facts to the destination, if needed. It returns nil on success, or an error if sending the chunk failed.

func (*FactSink) Write

func (b *FactSink) Write(offset int, fact Fact) error

Write accumulates the fact to send to the destination. It may also flush a chunk of facts. offset is the index into the lookups slice in the request for which this fact matches. Write returns nil on success, or an error if flushing failed.

type KGObject

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

KGObject represents a value of the Object field of a fact, this can be a KID i.e. another node in the graph, or it can be a typed literal value. String literals can also have a Language ID set (LangID) other literal types can have a Units ID set (UnitID). KGObject is safe to use as a key in a map. The zero value for KGObject maps to the KtNil ObjectType

func ABool

func ABool(v bool, unitID uint64) KGObject

ABool returns an new KGObject instance containing a Boolean value and Units ID.

func AFloat64

func AFloat64(fv float64, unitID uint64) KGObject

AFloat64 returns a new KGObject instance containing the supplied float and Units ID.

func AInt64

func AInt64(v int64, unitID uint64) KGObject

AInt64 returns a new KGObject instance containing the supplied int and Units ID.

func AKID

func AKID(kid uint64) KGObject

AKID returns an new KGObject instance containing a KID value.

func AString

func AString(s string, langID uint64) KGObject

AString returns a new KGObject instance containing the supplied string and language ID.

func ATimestamp

func ATimestamp(v time.Time, p logentry.TimestampPrecision, unitID uint64) KGObject

ATimestamp returns a new KGObject instance containing a Timestamp for the supplied dateTime, precision and Units ID.

func ATimestampY

func ATimestampY(year int, unitID uint64) KGObject

ATimestampY returns a new KGObject instance containing a Timestamp for the specified year and Units ID.

func ATimestampYM

func ATimestampYM(year int, month int, unitID uint64) KGObject

ATimestampYM returns a new KGObject instance containing a Timestamp for the specified year, month and Units ID.

func ATimestampYMD

func ATimestampYMD(year int, month int, day int, unitID uint64) KGObject

ATimestampYMD returns a new KGObject instance containing a Timestamp for the specified year, month, day and Units ID.

func ATimestampYMDH

func ATimestampYMDH(year, month, day, hour int, unitID uint64) KGObject

ATimestampYMDH returns a new KGObject instance containing a Timestamp for the specified year, month, day, hour and Units ID.

func ATimestampYMDHM

func ATimestampYMDHM(year, month, day, hour, minute int, unitID uint64) KGObject

ATimestampYMDHM returns a new KGObject instance containing a Timestamp for the specified year, month, day, hour, minutes and Units ID.

func ATimestampYMDHMS

func ATimestampYMDHMS(year, month, day, hour, minute, second int, unitID uint64) KGObject

ATimestampYMDHMS returns a new KGObject instance containing a Timestamp for the specified year, month, day, hour, minutes, seconds and Units ID.

func ATimestampYMDHMSN

func ATimestampYMDHMSN(year, month, day, hour, minute, second, nsec int, unitID uint64) KGObject

ATimestampYMDHMSN returns a new KGObject instance containing a Timestamp for the specified year, month, day, hour, minutes, seconds, nanoseonds, and Units ID.

func KGObjectFromAPI

func KGObjectFromAPI(from api.KGObject) KGObject

KGObjectFromAPI returns a new KGObject instance that is equivilent to the supplied API representation of a KGObject. The rpc.KGObject encapsulates a binary encoding of the KGObject

func KGObjectFromBytes

func KGObjectFromBytes(data []byte) (KGObject, error)

KGObjectFromBytes constructs a new KGObject instance from the provided serialized state it may return an error if it doesn't contain a valid encoded KGObject state.

func (*KGObject) AsBytes

func (o *KGObject) AsBytes() []byte

AsBytes returns a serialized state of this KGObject. You can take these bytes and pass them to KGObjectFromBytes to re-hydrate a KGObject instance

func (KGObject) AsString

func (o KGObject) AsString() string

AsString returns a serialized state of this KGObject as a non-printable string.

func (KGObject) Equal

func (o KGObject) Equal(other KGObject) bool

Equal returns true if 'other' & 'o' contain the same value

func (KGObject) IsType

func (o KGObject) IsType(t KGObjectType) bool

IsType returns true if this KGObject contains the indicated type

func (KGObject) Key

func (o KGObject) Key(b *strings.Builder)

Key implements cmp.Key; it writes the identity key for the object to the given strings.Builder. This key has two properties. First, two KGObjects are equal if and only if their Key output is equal. Second, the Key output is human-readable. Note that the current String() method does not currently have the first property (is "2018" a timestamp or an int64?), and the binary encoding clearly doesn't have the second property.

func (KGObject) LangID

func (o KGObject) LangID() uint64

LangID returns the Language ID if the contained type is KtString, otherwise it returns 0

func (KGObject) Less

func (o KGObject) Less(right KGObject) bool

Less returns true if 'o' is lexicographically smaller than 'right' When 'o' & 'right' are of different types, the types are compared in a consistent order

func (*KGObject) Marshal

func (o *KGObject) Marshal() ([]byte, error)

Marshal will return the bytes required to later unmarshal an instance of this KGObject back into the same value. This never returns an error.

func (*KGObject) MarshalTo

func (o *KGObject) MarshalTo(data []byte) (n int, err error)

MarshalTo will copy a serialized version of this KGObject into the supplied 'data' byte slice. The number of bytes copied are returned, if the supplied slice is too small, it'll end up with just the prefix that fits. This never returns an error.

func (*KGObject) Size

func (o *KGObject) Size() int

Size returns the number of bytes required to serialize an instance of this KGObject

func (KGObject) String

func (o KGObject) String() string

String returns a human readable representation of the contained value to aid in debugging. TODO: this should match the format used in the query language?

func (KGObject) ToAPIObject

func (o KGObject) ToAPIObject() api.KGObject

ToAPIObject will take this KGObject and return an KGObject in the external API format

func (KGObject) TypePrefix

func (o KGObject) TypePrefix() []byte

TypePrefix returns a byte slice that contain a prefix of the encoding that contains the type. This will contain the type indicator, and for types that have units, will also contain the units ID.

func (KGObject) UnitID

func (o KGObject) UnitID() uint64

UnitID returns the Units ID for the contained types that have units (bool, int, float, timestamp) otherwise it returns 0

func (*KGObject) Unmarshal

func (o *KGObject) Unmarshal(data []byte) error

Unmarshal will update this KGObject with marshaled value in the supplied 'data' bytes.

func (KGObject) ValBool

func (o KGObject) ValBool() bool

ValBool returns the contained bool value if the type is KtBool otherwise it returns false

func (KGObject) ValFloat64

func (o KGObject) ValFloat64() float64

ValFloat64 returns the contained Float64 value if the type is KtFloat64. otherwise it returns 0

func (KGObject) ValInt64

func (o KGObject) ValInt64() int64

ValInt64 returns the contained Int64 value if the type is KtInt64 otherwise it returns 0

func (KGObject) ValKID

func (o KGObject) ValKID() uint64

ValKID returns the contained KID value if the type is KtKID otherwise it returns 0

func (KGObject) ValString

func (o KGObject) ValString() string

ValString returns the contained string value if the type is KtString otherwise it returns "" Don't get this confused with String() which returns a human readable representation of the Object.

func (KGObject) ValTimestamp

func (o KGObject) ValTimestamp() logentry.KGTimestamp

ValTimestamp returns the contained Timestamp if the type is KtTimestamp otherwise it returns an empty/zero value KGTimestamp

func (KGObject) ValueType

func (o KGObject) ValueType() KGObjectType

ValueType returns the contained KGObject type.

func (KGObject) WriteTo

func (o KGObject) WriteTo(buff *bytes.Buffer, opts WriteOpts)

WriteTo will write all or some prefix of the encoded data that describes this KGObject, the 'opts' can be used to control exactly what is written

type KGObjectType

type KGObjectType uint8

KGObjectType is used to describethe contained type within an KGObject. Instances of KGObjectType are encoded into the serialization format and so you should not change the values for existing types.

const (
	// KtNil indicates the KGObject has no type.
	KtNil KGObjectType = 0

	// KtString indicates the KGObject contains an arbitrary unicode string.
	KtString KGObjectType = 1

	// KtFloat64 indicates the KGObject contains an 8 byte double precision float.
	KtFloat64 KGObjectType = 2

	// KtInt64 indicates the KGObject contains an 8 byte signed integer.
	KtInt64 KGObjectType = 3

	// KtTimestamp indicates the KGObject contains a KGTimestamp, which consists
	// of a point in time and a precision indication that says which fields to
	// pay attention to.
	KtTimestamp KGObjectType = 4

	// KtBool indicates the KGObject contains a boolean.
	KtBool KGObjectType = 5

	// KtKID indicates the KGObject contains a KID (a Knowledge Graph ID), aka a node in the graph
	// rather than a literal value.
	KtKID KGObjectType = 6
)

type MockChunkStream

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

MockChunkStream is designed to be used as a LookupChunkReadyCallback to collect all chunks flushed out of the LookupSink into a set. This is for writing tests.

func (*MockChunkStream) ByOffset

func (s *MockChunkStream) ByOffset() [][]Fact

ByOffset will return a slice of lists of facts, each index into the slice equals the offset that was set in the Fact, at each index, there is a list facts in the order they were recieved for that offset.

func (*MockChunkStream) Chunks

func (s *MockChunkStream) Chunks() []*LookupChunk

Chunks returns the list of chunks accumulated, each LookupChunk was from a callback to Send

func (*MockChunkStream) Flatten

func (s *MockChunkStream) Flatten() *LookupChunk

Flatten returns all the facts previously sent into one big chunk.

func (*MockChunkStream) Reset

func (s *MockChunkStream) Reset()

Reset will discard all collected chunks and reset nextErr

func (*MockChunkStream) Send

func (s *MockChunkStream) Send(chunk *LookupChunk) error

Send implements LookupChunkReadyCallback so that this can be a destination of a LookupSink

func (*MockChunkStream) SetNextError

func (s *MockChunkStream) SetNextError(err error)

SetNextError will cause the next callback (and only the next callback) to Send to return an error

type WriteOpts

type WriteOpts struct {
	// NoLangID Will skip writing the null separator and LanguageID for
	// KGObjects of type string.
	NoLangID bool
}

WriteOpts contains options that control the data written out by the KGObject.WriteTo method.

Jump to

Keyboard shortcuts

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