repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/pubcomp.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/pubcomp.go#L43-L45
go
train
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket
func (pc *PubcompPacket) Details() Details
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket func (pc *PubcompPacket) Details() Details
{ return Details{Qos: pc.Qos, MessageID: pc.MessageID} }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/packets.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/packets.go#L101-L131
go
train
//ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts //to read an MQTT packet from the stream. It returns a ControlPacket //representing the decoded MQTT packet and an error. One of these returns will //always be nil, a nil ControlPacket indicating an error occurred.
func ReadPacket(r io.Reader) (ControlPacket, error)
//ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts //to read an MQTT packet from the stream. It returns a ControlPacket //representing the decoded MQTT packet and an error. One of these returns will //always be nil, a nil ControlPacket indicating an error occurred. func ReadPacket(r io.Reade...
{ var fh FixedHeader b := make([]byte, 1) _, err := io.ReadFull(r, b) if err != nil { return nil, err } err = fh.unpack(b[0], r) if err != nil { return nil, err } cp, err := NewControlPacketWithHeader(fh) if err != nil { return nil, err } packetBytes := make([]byte, fh.RemainingLength) n, err :=...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/packets.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/packets.go#L174-L206
go
train
//NewControlPacketWithHeader is used to create a new ControlPacket of the type //specified within the FixedHeader that is passed to the function. //The newly created ControlPacket is empty and a pointer is returned.
func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error)
//NewControlPacketWithHeader is used to create a new ControlPacket of the type //specified within the FixedHeader that is passed to the function. //The newly created ControlPacket is empty and a pointer is returned. func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error)
{ switch fh.MessageType { case Connect: return &ConnectPacket{FixedHeader: fh}, nil case Connack: return &ConnackPacket{FixedHeader: fh}, nil case Disconnect: return &DisconnectPacket{FixedHeader: fh}, nil case Publish: return &PublishPacket{FixedHeader: fh}, nil case Puback: return &PubackPacket{Fixed...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L88-L117
go
train
// NewClientOptions will create a new ClientClientOptions type with some // default values. // Port: 1883 // CleanSession: True // Order: True // KeepAlive: 30 (seconds) // ConnectTimeout: 30 (seconds) // MaxReconnectInterval 10 (minutes) // AutoReconnect: True
func NewClientOptions() *ClientOptions
// NewClientOptions will create a new ClientClientOptions type with some // default values. // Port: 1883 // CleanSession: True // Order: True // KeepAlive: 30 (seconds) // ConnectTimeout: 30 (seconds) // MaxReconnectInterval 10 (minutes) // AutoReconnect: True func NewClientOptions() *ClientOptions
{ o := &ClientOptions{ Servers: nil, ClientID: "", Username: "", Password: "", CleanSession: true, Order: true, WillEnabled: false, WillTopic: "", WillPayload: nil, WillQ...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L127-L141
go
train
// AddBroker adds a broker URI to the list of brokers to be used. The format should be // scheme://host:port // Where "scheme" is one of "tcp", "ssl", or "ws", "host" is the ip-address (or hostname) // and "port" is the port on which the broker is accepting connections. // // Default values for hostname is "127.0.0.1",...
func (o *ClientOptions) AddBroker(server string) *ClientOptions
// AddBroker adds a broker URI to the list of brokers to be used. The format should be // scheme://host:port // Where "scheme" is one of "tcp", "ssl", or "ws", "host" is the ip-address (or hostname) // and "port" is the port on which the broker is accepting connections. // // Default values for hostname is "127.0.0.1",...
{ if len(server) > 0 && server[0] == ':' { server = "127.0.0.1" + server } if !strings.Contains(server, "://") { server = "tcp://" + server } brokerURI, err := url.Parse(server) if err != nil { ERROR.Println(CLI, "Failed to parse %q broker address: %s", server, err) return o } o.Servers = append(o.Serv...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L145-L148
go
train
// SetResumeSubs will enable resuming of stored (un)subscribe messages when connecting // but not reconnecting if CleanSession is false. Otherwise these messages are discarded.
func (o *ClientOptions) SetResumeSubs(resume bool) *ClientOptions
// SetResumeSubs will enable resuming of stored (un)subscribe messages when connecting // but not reconnecting if CleanSession is false. Otherwise these messages are discarded. func (o *ClientOptions) SetResumeSubs(resume bool) *ClientOptions
{ o.ResumeSubs = resume return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L153-L156
go
train
// SetClientID will set the client id to be used by this client when // connecting to the MQTT broker. According to the MQTT v3.1 specification, // a client id mus be no longer than 23 characters.
func (o *ClientOptions) SetClientID(id string) *ClientOptions
// SetClientID will set the client id to be used by this client when // connecting to the MQTT broker. According to the MQTT v3.1 specification, // a client id mus be no longer than 23 characters. func (o *ClientOptions) SetClientID(id string) *ClientOptions
{ o.ClientID = id return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L161-L164
go
train
// SetUsername will set the username to be used by this client when connecting // to the MQTT broker. Note: without the use of SSL/TLS, this information will // be sent in plaintext accross the wire.
func (o *ClientOptions) SetUsername(u string) *ClientOptions
// SetUsername will set the username to be used by this client when connecting // to the MQTT broker. Note: without the use of SSL/TLS, this information will // be sent in plaintext accross the wire. func (o *ClientOptions) SetUsername(u string) *ClientOptions
{ o.Username = u return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L169-L172
go
train
// SetPassword will set the password to be used by this client when connecting // to the MQTT broker. Note: without the use of SSL/TLS, this information will // be sent in plaintext accross the wire.
func (o *ClientOptions) SetPassword(p string) *ClientOptions
// SetPassword will set the password to be used by this client when connecting // to the MQTT broker. Note: without the use of SSL/TLS, this information will // be sent in plaintext accross the wire. func (o *ClientOptions) SetPassword(p string) *ClientOptions
{ o.Password = p return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L178-L181
go
train
// SetCredentialsProvider will set a method to be called by this client when // connecting to the MQTT broker that provide the current username and password. // Note: without the use of SSL/TLS, this information will be sent // in plaintext accross the wire.
func (o *ClientOptions) SetCredentialsProvider(p CredentialsProvider) *ClientOptions
// SetCredentialsProvider will set a method to be called by this client when // connecting to the MQTT broker that provide the current username and password. // Note: without the use of SSL/TLS, this information will be sent // in plaintext accross the wire. func (o *ClientOptions) SetCredentialsProvider(p CredentialsP...
{ o.CredentialsProvider = p return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L189-L192
go
train
// SetCleanSession will set the "clean session" flag in the connect message // when this client connects to an MQTT broker. By setting this flag, you are // indicating that no messages saved by the broker for this client should be // delivered. Any messages that were going to be sent by this client before // diconnecti...
func (o *ClientOptions) SetCleanSession(clean bool) *ClientOptions
// SetCleanSession will set the "clean session" flag in the connect message // when this client connects to an MQTT broker. By setting this flag, you are // indicating that no messages saved by the broker for this client should be // delivered. Any messages that were going to be sent by this client before // diconnecti...
{ o.CleanSession = clean return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L198-L201
go
train
// SetOrderMatters will set the message routing to guarantee order within // each QoS level. By default, this value is true. If set to false, // this flag indicates that messages can be delivered asynchronously // from the client to the application and possibly arrive out of order.
func (o *ClientOptions) SetOrderMatters(order bool) *ClientOptions
// SetOrderMatters will set the message routing to guarantee order within // each QoS level. By default, this value is true. If set to false, // this flag indicates that messages can be delivered asynchronously // from the client to the application and possibly arrive out of order. func (o *ClientOptions) SetOrderMatte...
{ o.Order = order return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L206-L209
go
train
// SetTLSConfig will set an SSL/TLS configuration to be used when connecting // to an MQTT broker. Please read the official Go documentation for more // information.
func (o *ClientOptions) SetTLSConfig(t *tls.Config) *ClientOptions
// SetTLSConfig will set an SSL/TLS configuration to be used when connecting // to an MQTT broker. Please read the official Go documentation for more // information. func (o *ClientOptions) SetTLSConfig(t *tls.Config) *ClientOptions
{ o.TLSConfig = t return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L215-L218
go
train
// SetStore will set the implementation of the Store interface // used to provide message persistence in cases where QoS levels // QoS_ONE or QoS_TWO are used. If no store is provided, then the // client will use MemoryStore by default.
func (o *ClientOptions) SetStore(s Store) *ClientOptions
// SetStore will set the implementation of the Store interface // used to provide message persistence in cases where QoS levels // QoS_ONE or QoS_TWO are used. If no store is provided, then the // client will use MemoryStore by default. func (o *ClientOptions) SetStore(s Store) *ClientOptions
{ o.Store = s return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L224-L227
go
train
// SetKeepAlive will set the amount of time (in seconds) that the client // should wait before sending a PING request to the broker. This will // allow the client to know that a connection has not been lost with the // server.
func (o *ClientOptions) SetKeepAlive(k time.Duration) *ClientOptions
// SetKeepAlive will set the amount of time (in seconds) that the client // should wait before sending a PING request to the broker. This will // allow the client to know that a connection has not been lost with the // server. func (o *ClientOptions) SetKeepAlive(k time.Duration) *ClientOptions
{ o.KeepAlive = int64(k / time.Second) return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L232-L235
go
train
// SetPingTimeout will set the amount of time (in seconds) that the client // will wait after sending a PING request to the broker, before deciding // that the connection has been lost. Default is 10 seconds.
func (o *ClientOptions) SetPingTimeout(k time.Duration) *ClientOptions
// SetPingTimeout will set the amount of time (in seconds) that the client // will wait after sending a PING request to the broker, before deciding // that the connection has been lost. Default is 10 seconds. func (o *ClientOptions) SetPingTimeout(k time.Duration) *ClientOptions
{ o.PingTimeout = k return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L239-L245
go
train
// SetProtocolVersion sets the MQTT version to be used to connect to the // broker. Legitimate values are currently 3 - MQTT 3.1 or 4 - MQTT 3.1.1
func (o *ClientOptions) SetProtocolVersion(pv uint) *ClientOptions
// SetProtocolVersion sets the MQTT version to be used to connect to the // broker. Legitimate values are currently 3 - MQTT 3.1 or 4 - MQTT 3.1.1 func (o *ClientOptions) SetProtocolVersion(pv uint) *ClientOptions
{ if (pv >= 3 && pv <= 4) || (pv > 0x80) { o.ProtocolVersion = pv o.protocolVersionExplicit = true } return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L257-L260
go
train
// SetWill accepts a string will message to be set. When the client connects, // it will give this will message to the broker, which will then publish the // provided payload (the will) to any clients that are subscribed to the provided // topic.
func (o *ClientOptions) SetWill(topic string, payload string, qos byte, retained bool) *ClientOptions
// SetWill accepts a string will message to be set. When the client connects, // it will give this will message to the broker, which will then publish the // provided payload (the will) to any clients that are subscribed to the provided // topic. func (o *ClientOptions) SetWill(topic string, payload string, qos byte, r...
{ o.SetBinaryWill(topic, []byte(payload), qos, retained) return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L266-L273
go
train
// SetBinaryWill accepts a []byte will message to be set. When the client connects, // it will give this will message to the broker, which will then publish the // provided payload (the will) to any clients that are subscribed to the provided // topic.
func (o *ClientOptions) SetBinaryWill(topic string, payload []byte, qos byte, retained bool) *ClientOptions
// SetBinaryWill accepts a []byte will message to be set. When the client connects, // it will give this will message to the broker, which will then publish the // provided payload (the will) to any clients that are subscribed to the provided // topic. func (o *ClientOptions) SetBinaryWill(topic string, payload []byte,...
{ o.WillEnabled = true o.WillTopic = topic o.WillPayload = payload o.WillQos = qos o.WillRetained = retained return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L277-L280
go
train
// SetDefaultPublishHandler sets the MessageHandler that will be called when a message // is received that does not match any known subscriptions.
func (o *ClientOptions) SetDefaultPublishHandler(defaultHandler MessageHandler) *ClientOptions
// SetDefaultPublishHandler sets the MessageHandler that will be called when a message // is received that does not match any known subscriptions. func (o *ClientOptions) SetDefaultPublishHandler(defaultHandler MessageHandler) *ClientOptions
{ o.DefaultPublishHandler = defaultHandler return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L284-L287
go
train
// SetOnConnectHandler sets the function to be called when the client is connected. Both // at initial connection time and upon automatic reconnect.
func (o *ClientOptions) SetOnConnectHandler(onConn OnConnectHandler) *ClientOptions
// SetOnConnectHandler sets the function to be called when the client is connected. Both // at initial connection time and upon automatic reconnect. func (o *ClientOptions) SetOnConnectHandler(onConn OnConnectHandler) *ClientOptions
{ o.OnConnect = onConn return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L291-L294
go
train
// SetConnectionLostHandler will set the OnConnectionLost callback to be executed // in the case where the client unexpectedly loses connection with the MQTT broker.
func (o *ClientOptions) SetConnectionLostHandler(onLost ConnectionLostHandler) *ClientOptions
// SetConnectionLostHandler will set the OnConnectionLost callback to be executed // in the case where the client unexpectedly loses connection with the MQTT broker. func (o *ClientOptions) SetConnectionLostHandler(onLost ConnectionLostHandler) *ClientOptions
{ o.OnConnectionLost = onLost return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L298-L301
go
train
// SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a // timeout error. A duration of 0 never times out. Default 30 seconds
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions
// SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a // timeout error. A duration of 0 never times out. Default 30 seconds func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions
{ o.WriteTimeout = t return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L306-L309
go
train
// SetConnectTimeout limits how long the client will wait when trying to open a connection // to an MQTT server before timeing out and erroring the attempt. A duration of 0 never times out. // Default 30 seconds. Currently only operational on TCP/TLS connections.
func (o *ClientOptions) SetConnectTimeout(t time.Duration) *ClientOptions
// SetConnectTimeout limits how long the client will wait when trying to open a connection // to an MQTT server before timeing out and erroring the attempt. A duration of 0 never times out. // Default 30 seconds. Currently only operational on TCP/TLS connections. func (o *ClientOptions) SetConnectTimeout(t time.Duratio...
{ o.ConnectTimeout = t return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L313-L316
go
train
// SetMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts // when connection is lost
func (o *ClientOptions) SetMaxReconnectInterval(t time.Duration) *ClientOptions
// SetMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts // when connection is lost func (o *ClientOptions) SetMaxReconnectInterval(t time.Duration) *ClientOptions
{ o.MaxReconnectInterval = t return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L321-L324
go
train
// SetAutoReconnect sets whether the automatic reconnection logic should be used // when the connection is lost, even if disabled the ConnectionLostHandler is still // called
func (o *ClientOptions) SetAutoReconnect(a bool) *ClientOptions
// SetAutoReconnect sets whether the automatic reconnection logic should be used // when the connection is lost, even if disabled the ConnectionLostHandler is still // called func (o *ClientOptions) SetAutoReconnect(a bool) *ClientOptions
{ o.AutoReconnect = a return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L330-L333
go
train
// SetMessageChannelDepth sets the size of the internal queue that holds messages while the // client is temporairily offline, allowing the application to publish when the client is // reconnecting. This setting is only valid if AutoReconnect is set to true, it is otherwise // ignored.
func (o *ClientOptions) SetMessageChannelDepth(s uint) *ClientOptions
// SetMessageChannelDepth sets the size of the internal queue that holds messages while the // client is temporairily offline, allowing the application to publish when the client is // reconnecting. This setting is only valid if AutoReconnect is set to true, it is otherwise // ignored. func (o *ClientOptions) SetMessag...
{ o.MessageChannelDepth = s return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options.go#L337-L340
go
train
// SetHTTPHeaders sets the additional HTTP headers that will be sent in the WebSocket // opening handshake.
func (o *ClientOptions) SetHTTPHeaders(h http.Header) *ClientOptions
// SetHTTPHeaders sets the additional HTTP headers that will be sent in the WebSocket // opening handshake. func (o *ClientOptions) SetHTTPHeaders(h http.Header) *ClientOptions
{ o.HTTPHeaders = h return o }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
net.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/net.go#L123-L161
go
train
// actually read incoming messages off the wire // send Message object into ibound channel
func incoming(c *client)
// actually read incoming messages off the wire // send Message object into ibound channel func incoming(c *client)
{ var err error var cp packets.ControlPacket defer c.workers.Done() DEBUG.Println(NET, "incoming started") for { if cp, err = packets.ReadPacket(c.conn); err != nil { break } DEBUG.Println(NET, "Received Message") select { case c.ibound <- cp: // Notify keepalive logic that we recently received...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
net.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/net.go#L233-L314
go
train
// receive Message objects on ibound // store messages if necessary // send replies on obound // delete messages from store if necessary
func alllogic(c *client)
// receive Message objects on ibound // store messages if necessary // send replies on obound // delete messages from store if necessary func alllogic(c *client)
{ defer c.workers.Done() DEBUG.Println(NET, "logic started") for { DEBUG.Println(NET, "logic waiting for msg on ibound") select { case msg := <-c.ibound: DEBUG.Println(NET, "logic got msg on ibound") persistInbound(c.persist, msg) switch m := msg.(type) { case *packets.PingrespPacket: DEBUG....
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
token.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/token.go#L66-L81
go
train
// WaitTimeout takes a time.Duration to wait for the flow associated with the // Token to complete, returns true if it returned before the timeout or // returns false if the timeout occurred. In the case of a timeout the Token // does not have an error set in case the caller wishes to wait again
func (b *baseToken) WaitTimeout(d time.Duration) bool
// WaitTimeout takes a time.Duration to wait for the flow associated with the // Token to complete, returns true if it returned before the timeout or // returns false if the timeout occurred. In the case of a timeout the Token // does not have an error set in case the caller wishes to wait again func (b *baseToken) Wai...
{ b.m.Lock() defer b.m.Unlock() timer := time.NewTimer(d) select { case <-b.complete: if !timer.Stop() { <-timer.C } return true case <-timer.C: } return false }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
token.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/token.go#L130-L134
go
train
// ReturnCode returns the acknowlegement code in the connack sent // in response to a Connect()
func (c *ConnectToken) ReturnCode() byte
// ReturnCode returns the acknowlegement code in the connack sent // in response to a Connect() func (c *ConnectToken) ReturnCode() byte
{ c.m.RLock() defer c.m.RUnlock() return c.returnCode }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
token.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/token.go#L138-L142
go
train
// SessionPresent returns a bool representing the value of the // session present field in the connack sent in response to a Connect()
func (c *ConnectToken) SessionPresent() bool
// SessionPresent returns a bool representing the value of the // session present field in the connack sent in response to a Connect() func (c *ConnectToken) SessionPresent() bool
{ c.m.RLock() defer c.m.RUnlock() return c.sessionPresent }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
token.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/token.go#L168-L172
go
train
// Result returns a map of topics that were subscribed to along with // the matching return code from the broker. This is either the Qos // value of the subscription or an error code.
func (s *SubscribeToken) Result() map[string]byte
// Result returns a map of topics that were subscribed to along with // the matching return code from the broker. This is either the Qos // value of the subscription or an error code. func (s *SubscribeToken) Result() map[string]byte
{ s.m.RLock() defer s.m.RUnlock() return s.subResult }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/unsuback.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/unsuback.go#L34-L39
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (ua *UnsubackPacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (ua *UnsubackPacket) Unpack(b io.Reader) error
{ var err error ua.MessageID, err = decodeUint16(b) return err }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
options_reader.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/options_reader.go#L30-L39
go
train
//Servers returns a slice of the servers defined in the clientoptions
func (r *ClientOptionsReader) Servers() []*url.URL
//Servers returns a slice of the servers defined in the clientoptions func (r *ClientOptionsReader) Servers() []*url.URL
{ s := make([]*url.URL, len(r.options.Servers)) for i, u := range r.options.Servers { nu := *u s[i] = &nu } return s }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L35-L41
go
train
// NewMemoryStore returns a pointer to a new instance of // MemoryStore, the instance is not initialized and ready to // use until Open() has been called on it.
func NewMemoryStore() *MemoryStore
// NewMemoryStore returns a pointer to a new instance of // MemoryStore, the instance is not initialized and ready to // use until Open() has been called on it. func NewMemoryStore() *MemoryStore
{ store := &MemoryStore{ messages: make(map[string]packets.ControlPacket), opened: false, } return store }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L44-L49
go
train
// Open initializes a MemoryStore instance.
func (store *MemoryStore) Open()
// Open initializes a MemoryStore instance. func (store *MemoryStore) Open()
{ store.Lock() defer store.Unlock() store.opened = true DEBUG.Println(STR, "memorystore initialized") }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L53-L61
go
train
// Put takes a key and a pointer to a Message and stores the // message.
func (store *MemoryStore) Put(key string, message packets.ControlPacket)
// Put takes a key and a pointer to a Message and stores the // message. func (store *MemoryStore) Put(key string, message packets.ControlPacket)
{ store.Lock() defer store.Unlock() if !store.opened { ERROR.Println(STR, "Trying to use memory store, but not open") return } store.messages[key] = message }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L65-L80
go
train
// Get takes a key and looks in the store for a matching Message // returning either the Message pointer or nil.
func (store *MemoryStore) Get(key string) packets.ControlPacket
// Get takes a key and looks in the store for a matching Message // returning either the Message pointer or nil. func (store *MemoryStore) Get(key string) packets.ControlPacket
{ store.RLock() defer store.RUnlock() if !store.opened { ERROR.Println(STR, "Trying to use memory store, but not open") return nil } mid := mIDFromKey(key) m := store.messages[key] if m == nil { CRITICAL.Println(STR, "memorystore get: message", mid, "not found") } else { DEBUG.Println(STR, "memorystore...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L84-L96
go
train
// All returns a slice of strings containing all the keys currently // in the MemoryStore.
func (store *MemoryStore) All() []string
// All returns a slice of strings containing all the keys currently // in the MemoryStore. func (store *MemoryStore) All() []string
{ store.RLock() defer store.RUnlock() if !store.opened { ERROR.Println(STR, "Trying to use memory store, but not open") return nil } keys := []string{} for k := range store.messages { keys = append(keys, k) } return keys }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
memstore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/memstore.go#L100-L115
go
train
// Del takes a key, searches the MemoryStore and if the key is found // deletes the Message pointer associated with it.
func (store *MemoryStore) Del(key string)
// Del takes a key, searches the MemoryStore and if the key is found // deletes the Message pointer associated with it. func (store *MemoryStore) Del(key string)
{ store.Lock() defer store.Unlock() if !store.opened { ERROR.Println(STR, "Trying to use memory store, but not open") return } mid := mIDFromKey(key) m := store.messages[key] if m == nil { WARN.Println(STR, "memorystore del: message", mid, "not found") } else { delete(store.messages, key) DEBUG.Print...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/pubrec.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/pubrec.go#L34-L39
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (pr *PubrecPacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (pr *PubrecPacket) Unpack(b io.Reader) error
{ var err error pr.MessageID, err = decodeUint16(b) return err }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/pubrec.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/pubrec.go#L43-L45
go
train
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket
func (pr *PubrecPacket) Details() Details
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket func (pr *PubrecPacket) Details() Details
{ return Details{Qos: pr.Qos, MessageID: pr.MessageID} }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L122-L147
go
train
// NewClient will create an MQTT v3.1.1 client with all of the options specified // in the provided ClientOptions. The client must have the Connect method called // on it before it may be used. This is to make sure resources (such as a net // connection) are created before the application is actually ready.
func NewClient(o *ClientOptions) Client
// NewClient will create an MQTT v3.1.1 client with all of the options specified // in the provided ClientOptions. The client must have the Connect method called // on it before it may be used. This is to make sure resources (such as a net // connection) are created before the application is actually ready. func NewCli...
{ c := &client{} c.options = *o if c.options.Store == nil { c.options.Store = NewMemoryStore() } switch c.options.ProtocolVersion { case 3, 4: c.options.protocolVersionExplicit = true case 0x83, 0x84: c.options.protocolVersionExplicit = true default: c.options.ProtocolVersion = 4 c.options.protocolV...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L152-L156
go
train
// AddRoute allows you to add a handler for messages on a specific topic // without making a subscription. For example having a different handler // for parts of a wildcard subscription
func (c *client) AddRoute(topic string, callback MessageHandler)
// AddRoute allows you to add a handler for messages on a specific topic // without making a subscription. For example having a different handler // for parts of a wildcard subscription func (c *client) AddRoute(topic string, callback MessageHandler)
{ if callback != nil { c.msgRouter.addRoute(topic, callback) } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L160-L172
go
train
// IsConnected returns a bool signifying whether // the client is connected or not.
func (c *client) IsConnected() bool
// IsConnected returns a bool signifying whether // the client is connected or not. func (c *client) IsConnected() bool
{ c.RLock() defer c.RUnlock() status := atomic.LoadUint32(&c.status) switch { case status == connected: return true case c.options.AutoReconnect && status > connecting: return true default: return false } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L176-L186
go
train
// IsConnectionOpen return a bool signifying whether the client has an active // connection to mqtt broker, i.e not in disconnected or reconnect mode
func (c *client) IsConnectionOpen() bool
// IsConnectionOpen return a bool signifying whether the client has an active // connection to mqtt broker, i.e not in disconnected or reconnect mode func (c *client) IsConnectionOpen() bool
{ c.RLock() defer c.RUnlock() status := atomic.LoadUint32(&c.status) switch { case status == connected: return true default: return false } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L208-L335
go
train
// Connect will create a connection to the message broker, by default // it will attempt to connect at v3.1.1 and auto retry at v3.1 if that // fails
func (c *client) Connect() Token
// Connect will create a connection to the message broker, by default // it will attempt to connect at v3.1.1 and auto retry at v3.1 if that // fails func (c *client) Connect() Token
{ var err error t := newToken(packets.Connect).(*ConnectToken) DEBUG.Println(CLI, "Connect()") c.obound = make(chan *PacketAndToken, c.options.MessageChannelDepth) c.oboundP = make(chan *PacketAndToken, c.options.MessageChannelDepth) c.ibound = make(chan packets.ControlPacket) go func() { c.persist.Open() ...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L338-L434
go
train
// internal function used to reconnect the client when it loses its connection
func (c *client) reconnect()
// internal function used to reconnect the client when it loses its connection func (c *client) reconnect()
{ DEBUG.Println(CLI, "enter reconnect") var ( err error rc = byte(1) sleep = time.Duration(1 * time.Second) ) for rc != 0 && atomic.LoadUint32(&c.status) != disconnected { for _, broker := range c.options.Servers { cm := newConnectMsgFromOptions(&c.options, broker) DEBUG.Println(CLI, "about to w...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L440-L461
go
train
// This function is only used for receiving a connack // when the connection is first started. // This prevents receiving incoming data while resume // is in progress if clean session is false.
func (c *client) connect() (byte, bool)
// This function is only used for receiving a connack // when the connection is first started. // This prevents receiving incoming data while resume // is in progress if clean session is false. func (c *client) connect() (byte, bool)
{ DEBUG.Println(NET, "connect started") ca, err := packets.ReadPacket(c.conn) if err != nil { ERROR.Println(NET, "connect got error", err) return packets.ErrNetworkError, false } if ca == nil { ERROR.Println(NET, "received nil packet") return packets.ErrNetworkError, false } msg, ok := ca.(*packets.Co...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L466-L484
go
train
// Disconnect will end the connection with the server, but not before waiting // the specified number of milliseconds to wait for existing work to be // completed.
func (c *client) Disconnect(quiesce uint)
// Disconnect will end the connection with the server, but not before waiting // the specified number of milliseconds to wait for existing work to be // completed. func (c *client) Disconnect(quiesce uint)
{ status := atomic.LoadUint32(&c.status) if status == connected { DEBUG.Println(CLI, "disconnecting") c.setConnected(disconnected) dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket) dt := newToken(packets.Disconnect) c.oboundP <- &PacketAndToken{p: dm, t: dt} // wait for wor...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L568-L605
go
train
// Publish will publish a message with the specified QoS and content // to the specified topic. // Returns a token to track delivery of the message to the broker
func (c *client) Publish(topic string, qos byte, retained bool, payload interface{}) Token
// Publish will publish a message with the specified QoS and content // to the specified topic. // Returns a token to track delivery of the message to the broker func (c *client) Publish(topic string, qos byte, retained bool, payload interface{}) Token
{ token := newToken(packets.Publish).(*PublishToken) DEBUG.Println(CLI, "enter Publish") switch { case !c.IsConnected(): token.setError(ErrNotConnected) return token case c.connectionStatus() == reconnecting && qos == 0: token.flowComplete() return token } pub := packets.NewControlPacket(packets.Publish...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L669-L723
go
train
// Load all stored messages and resend them // Call this to ensure QOS > 1,2 even after an application crash
func (c *client) resume(subscription bool)
// Load all stored messages and resend them // Call this to ensure QOS > 1,2 even after an application crash func (c *client) resume(subscription bool)
{ storedKeys := c.persist.All() for _, key := range storedKeys { packet := c.persist.Get(key) if packet == nil { continue } details := packet.Details() if isKeyOutbound(key) { switch packet.(type) { case *packets.SubscribePacket: if subscription { DEBUG.Println(STR, fmt.Sprintf("loaded p...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
client.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/client.go#L750-L753
go
train
// OptionsReader returns a ClientOptionsReader which is a copy of the clientoptions // in use by the client.
func (c *client) OptionsReader() ClientOptionsReader
// OptionsReader returns a ClientOptionsReader which is a copy of the clientoptions // in use by the client. func (c *client) OptionsReader() ClientOptionsReader
{ r := ClientOptionsReader{options: &c.options} return r }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
topic.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/topic.go#L52-L64
go
train
// Topic Names and Topic Filters // The MQTT v3.1.1 spec clarifies a number of ambiguities with regard // to the validity of Topic strings. // - A Topic must be between 1 and 65535 bytes. // - A Topic is case sensitive. // - A Topic may contain whitespace. // - A Topic containing a leading forward slash is different th...
func validateSubscribeMap(subs map[string]byte) ([]string, []byte, error)
// Topic Names and Topic Filters // The MQTT v3.1.1 spec clarifies a number of ambiguities with regard // to the validity of Topic strings. // - A Topic must be between 1 and 65535 bytes. // - A Topic is case sensitive. // - A Topic may contain whitespace. // - A Topic containing a leading forward slash is different th...
{ var topics []string var qoss []byte for topic, qos := range subs { if err := validateTopicAndQos(topic, qos); err != nil { return nil, nil, err } topics = append(topics, topic) qoss = append(qoss, qos) } return topics, qoss, nil }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/pubrel.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/pubrel.go#L43-L45
go
train
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket
func (pr *PubrelPacket) Details() Details
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket func (pr *PubrelPacket) Details() Details
{ return Details{Qos: pr.Qos, MessageID: pr.MessageID} }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/suback.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/suback.go#L39-L54
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (sa *SubackPacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (sa *SubackPacket) Unpack(b io.Reader) error
{ var qosBuffer bytes.Buffer var err error sa.MessageID, err = decodeUint16(b) if err != nil { return err } _, err = qosBuffer.ReadFrom(b) if err != nil { return err } sa.ReturnCodes = qosBuffer.Bytes() return nil }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/connack.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/connack.go#L40-L49
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (ca *ConnackPacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (ca *ConnackPacket) Unpack(b io.Reader) error
{ flags, err := decodeByte(b) if err != nil { return err } ca.SessionPresent = 1&flags > 0 ca.ReturnCode, err = decodeByte(b) return err }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/unsubscribe.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/unsubscribe.go#L41-L53
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (u *UnsubscribePacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (u *UnsubscribePacket) Unpack(b io.Reader) error
{ var err error u.MessageID, err = decodeUint16(b) if err != nil { return err } for topic, err := decodeString(b); err == nil && topic != ""; topic, err = decodeString(b) { u.Topics = append(u.Topics, topic) } return err }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/subscribe.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/subscribe.go#L44-L66
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (s *SubscribePacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (s *SubscribePacket) Unpack(b io.Reader) error
{ var err error s.MessageID, err = decodeUint16(b) if err != nil { return err } payloadLength := s.FixedHeader.RemainingLength - 2 for payloadLength > 0 { topic, err := decodeString(b) if err != nil { return err } s.Topics = append(s.Topics, topic) qos, err := decodeByte(b) if err != nil { re...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/publish.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/publish.go#L46-L70
go
train
//Unpack decodes the details of a ControlPacket after the fixed //header has been read
func (p *PublishPacket) Unpack(b io.Reader) error
//Unpack decodes the details of a ControlPacket after the fixed //header has been read func (p *PublishPacket) Unpack(b io.Reader) error
{ var payloadLength = p.FixedHeader.RemainingLength var err error p.TopicName, err = decodeString(b) if err != nil { return err } if p.Qos > 0 { p.MessageID, err = decodeUint16(b) if err != nil { return err } payloadLength -= len(p.TopicName) + 4 } else { payloadLength -= len(p.TopicName) + 2 }...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/publish.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/publish.go#L76-L82
go
train
//Copy creates a new PublishPacket with the same topic and payload //but an empty fixed header, useful for when you want to deliver //a message with different properties such as Qos but the same //content
func (p *PublishPacket) Copy() *PublishPacket
//Copy creates a new PublishPacket with the same topic and payload //but an empty fixed header, useful for when you want to deliver //a message with different properties such as Qos but the same //content func (p *PublishPacket) Copy() *PublishPacket
{ newP := NewControlPacket(Publish).(*PublishPacket) newP.TopicName = p.TopicName newP.Payload = p.Payload return newP }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
packets/publish.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/packets/publish.go#L86-L88
go
train
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket
func (p *PublishPacket) Details() Details
//Details returns a Details struct containing the Qos and //MessageID of this ControlPacket func (p *PublishPacket) Details() Details
{ return Details{Qos: p.Qos, MessageID: p.MessageID} }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L46-L52
go
train
// NewFileStore will create a new FileStore which stores its messages in the // directory provided.
func NewFileStore(directory string) *FileStore
// NewFileStore will create a new FileStore which stores its messages in the // directory provided. func NewFileStore(directory string) *FileStore
{ store := &FileStore{ directory: directory, opened: false, } return store }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L55-L72
go
train
// Open will allow the FileStore to be used.
func (store *FileStore) Open()
// Open will allow the FileStore to be used. func (store *FileStore) Open()
{ store.Lock() defer store.Unlock() // if no store directory was specified in ClientOpts, by default use the // current working directory if store.directory == "" { store.directory, _ = os.Getwd() } // if store dir exists, great, otherwise, create it if !exists(store.directory) { perms := os.FileMode(0770...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L84-L96
go
train
// Put will put a message into the store, associated with the provided // key value.
func (store *FileStore) Put(key string, m packets.ControlPacket)
// Put will put a message into the store, associated with the provided // key value. func (store *FileStore) Put(key string, m packets.ControlPacket)
{ store.Lock() defer store.Unlock() if !store.opened { ERROR.Println(STR, "Trying to use file store, but not open") return } full := fullpath(store.directory, key) write(store.directory, key, m) if !exists(full) { ERROR.Println(STR, "file not created:", full) } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L100-L124
go
train
// Get will retrieve a message from the store, the one associated with // the provided key value.
func (store *FileStore) Get(key string) packets.ControlPacket
// Get will retrieve a message from the store, the one associated with // the provided key value. func (store *FileStore) Get(key string) packets.ControlPacket
{ store.RLock() defer store.RUnlock() if !store.opened { ERROR.Println(STR, "Trying to use file store, but not open") return nil } filepath := fullpath(store.directory, key) if !exists(filepath) { return nil } mfile, oerr := os.Open(filepath) chkerr(oerr) msg, rerr := packets.ReadPacket(mfile) chkerr(...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L128-L132
go
train
// All will provide a list of all of the keys associated with messages // currenly residing in the FileStore.
func (store *FileStore) All() []string
// All will provide a list of all of the keys associated with messages // currenly residing in the FileStore. func (store *FileStore) All() []string
{ store.RLock() defer store.RUnlock() return store.all() }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L136-L140
go
train
// Del will remove the persisted message associated with the provided // key from the FileStore.
func (store *FileStore) Del(key string)
// Del will remove the persisted message associated with the provided // key from the FileStore. func (store *FileStore) Del(key string)
{ store.Lock() defer store.Unlock() store.del(key) }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L143-L150
go
train
// Reset will remove all persisted messages from the FileStore.
func (store *FileStore) Reset()
// Reset will remove all persisted messages from the FileStore. func (store *FileStore) Reset()
{ store.Lock() defer store.Unlock() WARN.Println(STR, "FileStore Reset") for _, key := range store.all() { store.del(key) } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L153-L177
go
train
// lockless
func (store *FileStore) all() []string
// lockless func (store *FileStore) all() []string
{ var err error var keys []string var files fileInfos if !store.opened { ERROR.Println(STR, "Trying to use file store, but not open") return nil } files, err = ioutil.ReadDir(store.directory) chkerr(err) sort.Sort(files) for _, f := range files { DEBUG.Println(STR, "file in All():", f.Name()) name :...
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
filestore.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/filestore.go#L221-L231
go
train
// create file called "X.[messageid].tmp" located in the store // the contents of the file is the bytes of the message, then // rename it to "X.[messageid].msg", overwriting any existing // message with the same id // X will be 'i' for inbound messages, and O for outbound messages
func write(store, key string, m packets.ControlPacket)
// create file called "X.[messageid].tmp" located in the store // the contents of the file is the bytes of the message, then // rename it to "X.[messageid].msg", overwriting any existing // message with the same id // X will be 'i' for inbound messages, and O for outbound messages func write(store, key string, m packet...
{ temppath := tmppath(store, key) f, err := os.Create(temppath) chkerr(err) werr := m.Write(f) chkerr(werr) cerr := f.Close() chkerr(cerr) rerr := os.Rename(temppath, fullpath(store, key)) chkerr(rerr) }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L38-L61
go
train
// match takes a slice of strings which represent the route being tested having been split on '/' // separators, and a slice of strings representing the topic string in the published message, similarly // split. // The function determines if the topic string matches the route according to the MQTT topic rules // and re...
func match(route []string, topic []string) bool
// match takes a slice of strings which represent the route being tested having been split on '/' // separators, and a slice of strings representing the topic string in the published message, similarly // split. // The function determines if the topic string matches the route according to the MQTT topic rules // and re...
{ if len(route) == 0 { if len(topic) == 0 { return true } return false } if len(topic) == 0 { if route[0] == "#" { return true } return false } if route[0] == "#" { return true } if (route[0] == "+") || (route[0] == topic[0]) { return match(route[1:], topic[1:]) } return false }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L69-L77
go
train
// removes $share and sharename when splitting the route to allow // shared subscription routes to correctly match the topic
func routeSplit(route string) []string
// removes $share and sharename when splitting the route to allow // shared subscription routes to correctly match the topic func routeSplit(route string) []string
{ var result []string if strings.HasPrefix(route, "$share") { result = strings.Split(route, "/")[2:] } else { result = strings.Split(route, "/") } return result }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L81-L83
go
train
// match takes the topic string of the published message and does a basic compare to the // string of the current Route, if they match it returns true
func (r *route) match(topic string) bool
// match takes the topic string of the published message and does a basic compare to the // string of the current Route, if they match it returns true func (r *route) match(topic string) bool
{ return r.topic == topic || routeIncludesTopic(r.topic, topic) }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L95-L99
go
train
// newRouter returns a new instance of a Router and channel which can be used to tell the Router // to stop
func newRouter() (*router, chan bool)
// newRouter returns a new instance of a Router and channel which can be used to tell the Router // to stop func newRouter() (*router, chan bool)
{ router := &router{routes: list.New(), messages: make(chan *packets.PublishPacket), stop: make(chan bool)} stop := router.stop return router, stop }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L104-L115
go
train
// addRoute takes a topic string and MessageHandler callback. It looks in the current list of // routes to see if there is already a matching Route. If there is it replaces the current // callback with the new one. If not it add a new entry to the list of Routes.
func (r *router) addRoute(topic string, callback MessageHandler)
// addRoute takes a topic string and MessageHandler callback. It looks in the current list of // routes to see if there is already a matching Route. If there is it replaces the current // callback with the new one. If not it add a new entry to the list of Routes. func (r *router) addRoute(topic string, callback Message...
{ r.Lock() defer r.Unlock() for e := r.routes.Front(); e != nil; e = e.Next() { if e.Value.(*route).match(topic) { r := e.Value.(*route) r.callback = callback return } } r.routes.PushBack(&route{topic: topic, callback: callback}) }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L119-L128
go
train
// deleteRoute takes a route string, looks for a matching Route in the list of Routes. If // found it removes the Route from the list.
func (r *router) deleteRoute(topic string)
// deleteRoute takes a route string, looks for a matching Route in the list of Routes. If // found it removes the Route from the list. func (r *router) deleteRoute(topic string)
{ r.Lock() defer r.Unlock() for e := r.routes.Front(); e != nil; e = e.Next() { if e.Value.(*route).match(topic) { r.routes.Remove(e) return } } }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L132-L136
go
train
// setDefaultHandler assigns a default callback that will be called if no matching Route // is found for an incoming Publish.
func (r *router) setDefaultHandler(handler MessageHandler)
// setDefaultHandler assigns a default callback that will be called if no matching Route // is found for an incoming Publish. func (r *router) setDefaultHandler(handler MessageHandler)
{ r.Lock() defer r.Unlock() r.defaultHandler = handler }
eclipse/paho.mqtt.golang
adca289fdcf8c883800aafa545bc263452290bae
router.go
https://github.com/eclipse/paho.mqtt.golang/blob/adca289fdcf8c883800aafa545bc263452290bae/router.go#L142-L187
go
train
// matchAndDispatch takes a channel of Message pointers as input and starts a go routine that // takes messages off the channel, matches them against the internal route list and calls the // associated callback (or the defaultHandler, if one exists and no other route matched). If // anything is sent down the stop chann...
func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order bool, client *client)
// matchAndDispatch takes a channel of Message pointers as input and starts a go routine that // takes messages off the channel, matches them against the internal route list and calls the // associated callback (or the defaultHandler, if one exists and no other route matched). If // anything is sent down the stop chann...
{ go func() { for { select { case message := <-messages: sent := false r.RLock() m := messageFromPublish(message, client.ackFunc(message)) handlers := []MessageHandler{} for e := r.routes.Front(); e != nil; e = e.Next() { if e.Value.(*route).match(message.TopicName) { if order {...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L61-L73
go
train
// NewEncodedConn will wrap an existing Connection and utilize the appropriate registered // encoder.
func NewEncodedConn(c *Conn, encType string) (*EncodedConn, error)
// NewEncodedConn will wrap an existing Connection and utilize the appropriate registered // encoder. func NewEncodedConn(c *Conn, encType string) (*EncodedConn, error)
{ if c == nil { return nil, errors.New("nats: Nil Connection") } if c.IsClosed() { return nil, ErrConnectionClosed } ec := &EncodedConn{Conn: c, Enc: EncoderForType(encType)} if ec.Enc == nil { return nil, fmt.Errorf("no encoder registered for '%s'", encType) } return ec, nil }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L76-L80
go
train
// RegisterEncoder will register the encType with the given Encoder. Useful for customization.
func RegisterEncoder(encType string, enc Encoder)
// RegisterEncoder will register the encType with the given Encoder. Useful for customization. func RegisterEncoder(encType string, enc Encoder)
{ encLock.Lock() defer encLock.Unlock() encMap[encType] = enc }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L83-L87
go
train
// EncoderForType will return the registered Encoder for the encType.
func EncoderForType(encType string) Encoder
// EncoderForType will return the registered Encoder for the encType. func EncoderForType(encType string) Encoder
{ encLock.Lock() defer encLock.Unlock() return encMap[encType] }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L91-L97
go
train
// Publish publishes the data argument to the given subject. The data argument // will be encoded using the associated encoder.
func (c *EncodedConn) Publish(subject string, v interface{}) error
// Publish publishes the data argument to the given subject. The data argument // will be encoded using the associated encoder. func (c *EncodedConn) Publish(subject string, v interface{}) error
{ b, err := c.Enc.Encode(subject, v) if err != nil { return err } return c.Conn.publish(subject, _EMPTY_, b) }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L102-L108
go
train
// PublishRequest will perform a Publish() expecting a response on the // reply subject. Use Request() for automatically waiting for a response // inline.
func (c *EncodedConn) PublishRequest(subject, reply string, v interface{}) error
// PublishRequest will perform a Publish() expecting a response on the // reply subject. Use Request() for automatically waiting for a response // inline. func (c *EncodedConn) PublishRequest(subject, reply string, v interface{}) error
{ b, err := c.Enc.Encode(subject, v) if err != nil { return err } return c.Conn.publish(subject, reply, b) }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L113-L129
go
train
// Request will create an Inbox and perform a Request() call // with the Inbox reply for the data v. A response will be // decoded into the vPtrResponse.
func (c *EncodedConn) Request(subject string, v interface{}, vPtr interface{}, timeout time.Duration) error
// Request will create an Inbox and perform a Request() call // with the Inbox reply for the data v. A response will be // decoded into the vPtrResponse. func (c *EncodedConn) Request(subject string, v interface{}, vPtr interface{}, timeout time.Duration) error
{ b, err := c.Enc.Encode(subject, v) if err != nil { return err } m, err := c.Conn.Request(subject, b, timeout) if err != nil { return err } if reflect.TypeOf(vPtr) == emptyMsgType { mPtr := vPtr.(*Msg) *mPtr = *m } else { err = c.Enc.Decode(m.Subject, m.Data, vPtr) } return err }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L156-L166
go
train
// Dissect the cb Handler's signature
func argInfo(cb Handler) (reflect.Type, int)
// Dissect the cb Handler's signature func argInfo(cb Handler) (reflect.Type, int)
{ cbType := reflect.TypeOf(cb) if cbType.Kind() != reflect.Func { panic("nats: Handler needs to be a func") } numArgs := cbType.NumIn() if numArgs == 0 { return nil, numArgs } return cbType.In(numArgs - 1), numArgs }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L173-L175
go
train
// Subscribe will create a subscription on the given subject and process incoming // messages using the specified Handler. The Handler should be a func that matches // a signature from the description of Handler from above.
func (c *EncodedConn) Subscribe(subject string, cb Handler) (*Subscription, error)
// Subscribe will create a subscription on the given subject and process incoming // messages using the specified Handler. The Handler should be a func that matches // a signature from the description of Handler from above. func (c *EncodedConn) Subscribe(subject string, cb Handler) (*Subscription, error)
{ return c.subscribe(subject, _EMPTY_, cb) }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L180-L182
go
train
// QueueSubscribe will create a queue subscription on the given subject and process // incoming messages using the specified Handler. The Handler should be a func that // matches a signature from the description of Handler from above.
func (c *EncodedConn) QueueSubscribe(subject, queue string, cb Handler) (*Subscription, error)
// QueueSubscribe will create a queue subscription on the given subject and process // incoming messages using the specified Handler. The Handler should be a func that // matches a signature from the description of Handler from above. func (c *EncodedConn) QueueSubscribe(subject, queue string, cb Handler) (*Subscriptio...
{ return c.subscribe(subject, queue, cb) }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L185-L238
go
train
// Internal implementation that all public functions will use.
func (c *EncodedConn) subscribe(subject, queue string, cb Handler) (*Subscription, error)
// Internal implementation that all public functions will use. func (c *EncodedConn) subscribe(subject, queue string, cb Handler) (*Subscription, error)
{ if cb == nil { return nil, errors.New("nats: Handler required for EncodedConn Subscription") } argType, numArgs := argInfo(cb) if argType == nil { return nil, errors.New("nats: Handler requires at least one argument") } cbValue := reflect.ValueOf(cb) wantsRaw := (argType == emptyMsgType) natsCB := func...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/enc.go#L241-L243
go
train
// FlushTimeout allows a Flush operation to have an associated timeout.
func (c *EncodedConn) FlushTimeout(timeout time.Duration) (err error)
// FlushTimeout allows a Flush operation to have an associated timeout. func (c *EncodedConn) FlushTimeout(timeout time.Duration) (err error)
{ return c.Conn.FlushTimeout(timeout) }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
encoders/builtin/default_enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/encoders/builtin/default_enc.go#L38-L58
go
train
// Encode
func (je *DefaultEncoder) Encode(subject string, v interface{}) ([]byte, error)
// Encode func (je *DefaultEncoder) Encode(subject string, v interface{}) ([]byte, error)
{ switch arg := v.(type) { case string: bytes := *(*[]byte)(unsafe.Pointer(&arg)) return bytes, nil case []byte: return arg, nil case bool: if arg { return trueB, nil } else { return falseB, nil } case nil: return nilB, nil default: var buf bytes.Buffer fmt.Fprintf(&buf, "%+v", arg) ret...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
encoders/builtin/default_enc.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/encoders/builtin/default_enc.go#L61-L117
go
train
// Decode
func (je *DefaultEncoder) Decode(subject string, data []byte, vPtr interface{}) error
// Decode func (je *DefaultEncoder) Decode(subject string, data []byte, vPtr interface{}) error
{ // Figure out what it's pointing to... sData := *(*string)(unsafe.Pointer(&data)) switch arg := vPtr.(type) { case *string: *arg = sData return nil case *[]byte: *arg = data return nil case *int: n, err := strconv.ParseInt(sData, 10, 64) if err != nil { return err } *arg = int(n) return ni...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
parser.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/parser.go#L73-L401
go
train
// parse is the fast protocol parser engine.
func (nc *Conn) parse(buf []byte) error
// parse is the fast protocol parser engine. func (nc *Conn) parse(buf []byte) error
{ var i int var b byte // Move to loop instead of range syntax to allow jumping of i for i = 0; i < len(buf); i++ { b = buf[i] switch nc.ps.state { case OP_START: switch b { case 'M', 'm': nc.ps.state = OP_M case 'P', 'p': nc.ps.state = OP_P case '+': nc.ps.state = OP_PLUS case '...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
parser.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/parser.go#L405-L413
go
train
// cloneMsgArg is used when the split buffer scenario has the pubArg in the existing read buffer, but // we need to hold onto it into the next read.
func (nc *Conn) cloneMsgArg()
// cloneMsgArg is used when the split buffer scenario has the pubArg in the existing read buffer, but // we need to hold onto it into the next read. func (nc *Conn) cloneMsgArg()
{ nc.ps.argBuf = nc.ps.scratch[:0] nc.ps.argBuf = append(nc.ps.argBuf, nc.ps.ma.subject...) nc.ps.argBuf = append(nc.ps.argBuf, nc.ps.ma.reply...) nc.ps.ma.subject = nc.ps.argBuf[:len(nc.ps.ma.subject)] if nc.ps.ma.reply != nil { nc.ps.ma.reply = nc.ps.argBuf[len(nc.ps.ma.subject):] } }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
parser.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/parser.go#L470-L481
go
train
// parseInt64 expects decimal positive numbers. We // return -1 to signal error
func parseInt64(d []byte) (n int64)
// parseInt64 expects decimal positive numbers. We // return -1 to signal error func parseInt64(d []byte) (n int64)
{ if len(d) == 0 { return -1 } for _, dec := range d { if dec < ascii_0 || dec > ascii_9 { return -1 } n = n*10 + (int64(dec) - ascii_0) } return n }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
nats.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L117-L129
go
train
// GetDefaultOptions returns default configuration options for the client.
func GetDefaultOptions() Options
// GetDefaultOptions returns default configuration options for the client. func GetDefaultOptions() Options
{ return Options{ AllowReconnect: true, MaxReconnect: DefaultMaxReconnect, ReconnectWait: DefaultReconnectWait, Timeout: DefaultTimeout, PingInterval: DefaultPingInterval, MaxPingsOut: DefaultMaxPingOut, SubChanLen: DefaultMaxChanLen, ReconnectBufSize: DefaultReconnect...
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
nats.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L515-L526
go
train
// Connect will attempt to connect to the NATS system. // The url can contain username/password semantics. e.g. nats://derek:pass@localhost:4222 // Comma separated arrays are also supported, e.g. urlA, urlB. // Options start with the defaults but can be overridden.
func Connect(url string, options ...Option) (*Conn, error)
// Connect will attempt to connect to the NATS system. // The url can contain username/password semantics. e.g. nats://derek:pass@localhost:4222 // Comma separated arrays are also supported, e.g. urlA, urlB. // Options start with the defaults but can be overridden. func Connect(url string, options ...Option) (*Conn, er...
{ opts := GetDefaultOptions() opts.Servers = processUrlString(url) for _, opt := range options { if opt != nil { if err := opt(&opts); err != nil { return nil, err } } } return opts.Connect() }
nats-io/go-nats
36d30b0ba7aa260ae25b4f3d312b2a700106fd78
nats.go
https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L531-L536
go
train
// Options that can be passed to Connect. // Name is an Option to set the client name.
func Name(name string) Option
// Options that can be passed to Connect. // Name is an Option to set the client name. func Name(name string) Option
{ return func(o *Options) error { o.Name = name return nil } }