func NewFile(reader io.Reader, metadata Metadata, logger ax.Logger) *File { return &File{ reader: reader, metadata: metadata, Logger: ax.Wrap(ax.Use(logger), ax.NewPrefixLogger("[smpm] ")), ByteOrder: binary.BigEndian, } }
// Creates a new Reader for the given io.Reader. // // Readers are the core for parsing bytes in the minecraft protocol. // It uses a NewPackerStructer to determine the packet type (from the opcode), // then utilizes the DataReaders to parse the appropriate packet. // // The Reader can accept a logger to use debugging internals. // // The last two arguments are optional, passing nil will use their default values: // DefaultDataReaders and NullLogger. func NewReader(stream io.Reader, m NewPacketStructer, r DataReaders, l ax.Logger) *Reader { if r == nil { r = DefaultDataReaders } if m == nil { panic(fmt.Errorf("I got a null NewPacketStructer: %#v", m)) } return &Reader{ stream: stream, readers: r, mapper: m, Logger: ax.Wrap(ax.Use(l), ax.NewPrefixLogger("[protocol] ")), } }
// Creates a new writer that can write packets into the given io.Writer. // // Writers are the core for parsing bytes in the minecraft protocol. // It uses a GetPacketTyper to determine the opcode (from the Packet struct), // then utilizes the DataWriters to parse the appropriate packet. // // The Reader can accept a logger to use debugging internals. // // The last two arguments are optional, passing nil will use their default values: // DefaultDataWriters and NullLogger. func NewWriter(stream io.Writer, m GetPacketTyper, w DataWriters, l ax.Logger) *Writer { if w == nil { w = DefaultDataWriters } if m == nil { panic(fmt.Errorf("I got a null NewPacketStructer: %#v", m)) } return &Writer{ stream: stream, writers: w, mapper: m, Logger: ax.Wrap(ax.Use(l), ax.NewPrefixLogger("[protocol] ")), } }