statusproto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypePublicGroup  = "public-group-user-message"
	MessageTypePrivate      = "user-message"
	MessageTypePrivateGroup = "group-user-message"
)

Message types.

View Source
const (
	// ContentTypeTextPlain means that the message contains plain text.
	ContentTypeTextPlain = "text/plain"
)

Variables

View Source
var (
	// ErrInvalidDecodedValue means that the decoded message is of wrong type.
	// This might mean that the status message serialization tag changed.
	ErrInvalidDecodedValue = errors.New("invalid decoded value type")
)

Functions

func CalcMessageClock

func CalcMessageClock(lastObservedValue int64, timeInMs TimestampInMs) int64

CalcMessageClock calculates a new clock value for Message. It is used to properly sort messages and accomodate the fact that time might be different on each device.

func EncodeMessage

func EncodeMessage(value Message) ([]byte, error)

EncodeMessage encodes a Message using Transit serialization.

func EncodePairMessage

func EncodePairMessage(value PairMessage) ([]byte, error)

EncodePairMessage encodes a PairMessage using Transit serialization.

func MessageID

func MessageID(author *ecdsa.PublicKey, data []byte) []byte

MessageID calculates the messageID, by appending the sha3-256 to the compress pubkey

func NewMessageDecoder

func NewMessageDecoder(r io.Reader) *transit.Decoder

NewMessageDecoder returns a new Transit decoder that can deserialize Message structs. More about Transit: https://github.com/cognitect/transit-format

func NewMessageEncoder

func NewMessageEncoder(w io.Writer) *transit.Encoder

NewMessageEncoder returns a new Transit encoder that can encode Message values. More about Transit: https://github.com/cognitect/transit-format

func WrapMessageV1

func WrapMessageV1(payload []byte, identity *ecdsa.PrivateKey) ([]byte, error)

WrapMessageV1 wraps a payload into a protobuf message and signs it if an identity is provided

Types

type Content

type Content struct {
	ChatID string `json:"chat_id"`
	Text   string `json:"text"`
}

Content contains the chat ID and the actual text of a message.

type Flags

type Flags uint64

Flags define various boolean properties of a message.

const (
	MessageRead Flags = 1 << iota
)

A list of Message flags. By default, a message is unread.

func (*Flags) Clear

func (f *Flags) Clear(val Flags)

func (Flags) Has

func (f Flags) Has(val Flags) bool

func (*Flags) Set

func (f *Flags) Set(val Flags)

func (*Flags) Toggle

func (f *Flags) Toggle(val Flags)

type Message

type Message struct {
	Text      string        `json:"text"` // TODO: why is this duplicated?
	ContentT  string        `json:"content_type"`
	MessageT  string        `json:"message_type"`
	Clock     int64         `json:"clock"` // lamport timestamp; see CalcMessageClock for more details
	Timestamp TimestampInMs `json:"timestamp"`
	Content   Content       `json:"content"`

	Flags     Flags            `json:"-"`
	ID        []byte           `json:"-"`
	SigPubKey *ecdsa.PublicKey `json:"-"`
}

Message is a chat message sent by an user.

func CreatePrivateTextMessage

func CreatePrivateTextMessage(data []byte, lastClock int64, chatID string) Message

CreatePrivateTextMessage creates a public text Message.

func CreatePublicTextMessage

func CreatePublicTextMessage(data []byte, lastClock int64, chatID string) Message

CreatePublicTextMessage creates a public text Message.

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (Message) Unread added in v0.1.0

func (m Message) Unread() bool

type PairMessage

type PairMessage struct {
	InstallationID string `json:"installationId"`
	// The type of the device
	DeviceType string `json:"deviceType"`
	// Name the user set name
	Name string `json:"name"`
	// The FCMToken for mobile platforms
	FCMToken string `json:"fcmToken"`

	// not protocol defined fields
	ID []byte `json:"-"`
}

PairMessage contains all message details.

func CreatePairMessage

func CreatePairMessage(installationID string, name string, deviceType string, fcmToken string) PairMessage

CreatePairMessage creates a PairMessage which is used to pair devices.

func DecodePairMessage

func DecodePairMessage(data []byte) (message PairMessage, err error)

DecodePairMessage decodes a raw payload to Message struct.

func (*PairMessage) MarshalJSON

func (m *PairMessage) MarshalJSON() ([]byte, error)

type StatusMessage

type StatusMessage struct {
	Message   interface{}
	ID        []byte           `json:"-"`
	SigPubKey *ecdsa.PublicKey `json:"-"`
}

StatusMessage is any Status Protocol message.

func DecodeMessage added in v0.1.0

func DecodeMessage(transportPublicKey *ecdsa.PublicKey, data []byte) (message StatusMessage, err error)

DecodeMessage decodes a raw payload to StatusMessage struct.

func (*StatusMessage) MarshalJSON added in v0.1.0

func (m *StatusMessage) MarshalJSON() ([]byte, error)

type StatusProtocolMessage

type StatusProtocolMessage struct {
	Signature            []byte   `protobuf:"bytes,1,opt,name=signature,proto3" json:"signature,omitempty"`
	Payload              []byte   `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*StatusProtocolMessage) Descriptor

func (*StatusProtocolMessage) Descriptor() ([]byte, []int)

func (*StatusProtocolMessage) GetPayload

func (m *StatusProtocolMessage) GetPayload() []byte

func (*StatusProtocolMessage) GetSignature

func (m *StatusProtocolMessage) GetSignature() []byte

func (*StatusProtocolMessage) ProtoMessage

func (*StatusProtocolMessage) ProtoMessage()

func (*StatusProtocolMessage) Reset

func (m *StatusProtocolMessage) Reset()

func (*StatusProtocolMessage) String

func (m *StatusProtocolMessage) String() string

func (*StatusProtocolMessage) XXX_DiscardUnknown

func (m *StatusProtocolMessage) XXX_DiscardUnknown()

func (*StatusProtocolMessage) XXX_Marshal

func (m *StatusProtocolMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StatusProtocolMessage) XXX_Merge

func (m *StatusProtocolMessage) XXX_Merge(src proto.Message)

func (*StatusProtocolMessage) XXX_Size

func (m *StatusProtocolMessage) XXX_Size() int

func (*StatusProtocolMessage) XXX_Unmarshal

func (m *StatusProtocolMessage) XXX_Unmarshal(b []byte) error

type TimestampInMs

type TimestampInMs int64

TimestampInMs is a timestamp in milliseconds.

func TimestampInMsFromTime

func TimestampInMsFromTime(t time.Time) TimestampInMs

TimestampInMsFromTime returns a TimestampInMs from a time.Time instance.

func (TimestampInMs) Time

func (t TimestampInMs) Time() time.Time

Time returns a time.Time instance.

Jump to

Keyboard shortcuts

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