Improve doc comments
This commit is contained in:
parent
585c8038d3
commit
02dbcacd28
12
dial.go
12
dial.go
@ -5,23 +5,19 @@ import "context"
|
|||||||
import "crypto/tls"
|
import "crypto/tls"
|
||||||
import "github.com/quic-go/quic-go"
|
import "github.com/quic-go/quic-go"
|
||||||
|
|
||||||
// TODO: dial should be super simple like it is now, and there should be a
|
// Dial opens a connection to a server. The network must be one of "quic",
|
||||||
// "dialer" which the dial function dial configures automaticaly, but the dialer
|
// "quic4", (IPv4-only) "quic6" (IPv6-only), or "unix".
|
||||||
// should offer much more options when used directlym
|
|
||||||
|
|
||||||
// Dial opens a connection to a server. The network must be one of "udp",
|
|
||||||
// "udp4", "udp6", or "unixgram".
|
|
||||||
func Dial(ctx context.Context, network, address string) (Conn, error) {
|
func Dial(ctx context.Context, network, address string) (Conn, error) {
|
||||||
return (Dialer { }).Dial(ctx, network, address)
|
return (Dialer { }).Dial(ctx, network, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: export when there are options here
|
// Dialer allows for further configuration of the dialing process.
|
||||||
type Dialer struct {
|
type Dialer struct {
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dial opens a connection to a server. The network must be one of "quic",
|
// Dial opens a connection to a server. The network must be one of "quic",
|
||||||
// "quic4", "quic6", or "unix".
|
// "quic4", (IPv4-only) "quic6" (IPv6-only), or "unix".
|
||||||
func (diale Dialer) Dial(ctx context.Context, network, address string) (Conn, error) {
|
func (diale Dialer) Dial(ctx context.Context, network, address string) (Conn, error) {
|
||||||
switch network {
|
switch network {
|
||||||
case "quic", "quic4", "quic6": return diale.dialQUIC(ctx, network, address)
|
case "quic", "quic4", "quic6": return diale.dialQUIC(ctx, network, address)
|
||||||
|
20
message.go
20
message.go
@ -4,8 +4,10 @@ import "fmt"
|
|||||||
import "encoding"
|
import "encoding"
|
||||||
import "git.tebibyte.media/sashakoshka/hopp/tape"
|
import "git.tebibyte.media/sashakoshka/hopp/tape"
|
||||||
|
|
||||||
// Message is any object that is both a binary marshaler and unmarshaler.
|
// Message is any object that can be sent or received over a HOPP connection.
|
||||||
type Message interface {
|
type Message interface {
|
||||||
|
// Method returns the method number of the message. This must be unique
|
||||||
|
// within the protocol, and should not change between calls.
|
||||||
Method() uint16
|
Method() uint16
|
||||||
encoding.BinaryMarshaler
|
encoding.BinaryMarshaler
|
||||||
encoding.BinaryUnmarshaler
|
encoding.BinaryUnmarshaler
|
||||||
@ -13,12 +15,14 @@ type Message interface {
|
|||||||
|
|
||||||
var _ Message = new(MessageData)
|
var _ Message = new(MessageData)
|
||||||
|
|
||||||
// MessageData can hold the structure of any message. It can be used to alter
|
// MessageData represents a message that organizes its data into table pairs. It
|
||||||
// a protocol at runtime, transmit data with arbitrary keys, etc. Bear in mind
|
// can be used to alter a protocol at runtime, transmit data with arbitrary
|
||||||
// that is less performant than generating code because it has to make extra
|
// keys, etc. Bear in mind that is less performant than generating code because
|
||||||
// memory allocations.
|
// it has to make extra memory allocations and such.
|
||||||
type MessageData struct {
|
type MessageData struct {
|
||||||
|
// Methd holds the method number. This should only be set once.
|
||||||
Methd uint16
|
Methd uint16
|
||||||
|
// Pairs maps tags to values.
|
||||||
Pairs map[uint16] []byte
|
Pairs map[uint16] []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,14 +31,16 @@ func (this *MessageData) Method() uint16 {
|
|||||||
return this.Methd
|
return this.Methd
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalBinary implements the [encoding.BinaryMarshaler] interface.
|
// MarshalBinary implements the [encoding.BinaryMarshaler] interface. The
|
||||||
|
// message is encoded using TAPE (Table Pair Encoding).
|
||||||
func (this *MessageData) MarshalBinary() ([]byte, error) {
|
func (this *MessageData) MarshalBinary() ([]byte, error) {
|
||||||
buffer, err := tape.EncodePairs(this.Pairs)
|
buffer, err := tape.EncodePairs(this.Pairs)
|
||||||
if err != nil { return nil, fmt.Errorf("marshaling MessageData: %w", err) }
|
if err != nil { return nil, fmt.Errorf("marshaling MessageData: %w", err) }
|
||||||
return buffer, nil
|
return buffer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalBinary implements the [encoding.BinaryUnmarshaler] interface.
|
// UnmarshalBinary implements the [encoding.BinaryUnmarshaler] interface. The
|
||||||
|
// message is decoded using TAPE (Table Pair Encoding).
|
||||||
func (this *MessageData) UnmarshalBinary(buffer []byte) error {
|
func (this *MessageData) UnmarshalBinary(buffer []byte) error {
|
||||||
this.Pairs = make(map[uint16] []byte)
|
this.Pairs = make(map[uint16] []byte)
|
||||||
pairs, err := tape.DecodePairs(buffer)
|
pairs, err := tape.DecodePairs(buffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user