Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/command/acknowledge/acknowledge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package acknowledge

import (
"encoding/binary"
"michelprogram/photon-parser/internal/context"
)

Expand All @@ -13,12 +14,12 @@ func Parse(ctx *context.Context) (*Acknowledge, error) {
var ack Acknowledge
var err error

ack.AckReliableSequenceNumber, err = ctx.Reader.ReadUInt32()
ack.AckReliableSequenceNumber, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

ack.AckSentTime, err = ctx.Reader.ReadUInt32()
ack.AckSentTime, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/command/command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"encoding/binary"
"fmt"
"michelprogram/photon-parser/internal/command/acknowledge"
"michelprogram/photon-parser/internal/command/connect"
Expand Down Expand Up @@ -146,12 +147,12 @@ func (s *Command) parseHeader(r *reader.Reader) (types.CommandHeader, error) {
return types.CommandHeader{}, err
}

header.Length, err = r.ReadUInt32()
header.Length, err = r.ReadUInt32(binary.BigEndian)
if err != nil {
return types.CommandHeader{}, err
}

header.ReliableSequenceNumber, err = r.ReadUInt32()
header.ReliableSequenceNumber, err = r.ReadUInt32(binary.BigEndian)
if err != nil {
return types.CommandHeader{}, err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/command/command_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command_test

import (
"encoding/binary"
"michelprogram/photon-parser/internal/command"
"michelprogram/photon-parser/internal/context"
v16 "michelprogram/photon-parser/internal/parameters/v16"
Expand All @@ -14,11 +13,11 @@ func TestParseSession(t *testing.T) {
payload := []byte{0x6, 0x0, 0x1, 0x0,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f1, 0x1, 0x6b, 0x18, 0x74, 0x2, 0x62, 0x1, 0x4, 0x6c, 0x0, 0x0, 0x0, 0x0, 0xae, 0x4b, 0x61, 0x10, 0x5, 0x73, 0x0, 0xf, 0x47, 0x72, 0x7a, 0x65, 0x67, 0x6f, 0x72, 0x7a, 0x4e, 0x69, 0x65, 0x4d, 0x6f, 0x67, 0x65, 0x6, 0x62, 0x2, 0x7, 0x69, 0x1c, 0xa1, 0xfc, 0x7d, 0x8, 0x79, 0x0, 0x3, 0x6b, 0xb, 0x13, 0xb, 0x1d, 0xb, 0x20, 0x9, 0x78, 0x0, 0x0, 0x0, 0x1, 0x12, 0xa, 0x62, 0x0, 0xfc, 0x6b, 0x0, 0x1e, 0x6, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x53, 0x0, 0x0, 0x0, 0x14, 0xf3, 0x4, 0x1, 0x0, 0xb, 0x0, 0x69, 0x0, 0x4, 0x6c, 0xf3, 0x1, 0x6b, 0xf, 0xfc, 0x2, 0x62, 0x1, 0x4, 0x69, 0x48, 0xd9, 0x3c, 0x1, 0x5, 0x73, 0x0, 0xd, 0x53, 0x61, 0x62, 0x65, 0x72, 0x6c, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x31, 0x6, 0x62, 0x2, 0x7, 0x69, 0xf, 0xa8, 0xfd, 0x5e, 0x8, 0x79, 0x0, 0x1, 0x6b, 0xf, 0x10, 0x9, 0x78, 0x0, 0x0, 0x0, 0x1, 0xac, 0xa, 0x62, 0x0, 0xfc, 0x6b, 0x0, 0x1e}

ctx := &context.Context{
Reader: reader.NewReader(payload, reader.Options{
Reader: reader.NewReader(payload),
Decoders: context.Decoders{
ParameterParser: &v16.Parameter{},
ReliableHeaderParameterCount: &v16.ReliableHeaderParameterCountV16{},
BinaryOrder: binary.BigEndian,
}),
},
}

cmd, err := command.Parse(ctx)
Expand Down
17 changes: 9 additions & 8 deletions internal/command/connect/connect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package connect

import (
"encoding/binary"
"michelprogram/photon-parser/internal/context"
)

Expand All @@ -18,35 +19,35 @@ type Connect struct {
func Parse(ctx *context.Context) (*Connect, error) {
var err error
connect := Connect{}
connect.Mtu, err = ctx.Reader.ReadUInt32()
connect.Mtu, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.WindowSize, err = ctx.Reader.ReadUInt32()
connect.WindowSize, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.ChannelCount, err = ctx.Reader.ReadUInt32()
connect.ChannelCount, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.IncomingBandwidth, err = ctx.Reader.ReadUInt32()
connect.IncomingBandwidth, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.OutgoingBandwidth, err = ctx.Reader.ReadUInt32()
connect.OutgoingBandwidth, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.DisconnectThrottle, err = ctx.Reader.ReadUInt32()
connect.DisconnectThrottle, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.PacketThrottleAcceleration, err = ctx.Reader.ReadUInt32()
connect.PacketThrottleAcceleration, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
connect.PacketThrottleDeceleration, err = ctx.Reader.ReadUInt32()
connect.PacketThrottleDeceleration, err = ctx.Reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions internal/command/reliable/fragment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reliable

import (
"encoding/binary"
"michelprogram/photon-parser/internal/context"
"michelprogram/photon-parser/internal/reader"
"michelprogram/photon-parser/internal/types"
Expand Down Expand Up @@ -31,32 +32,32 @@ func parseMetadata(reader *reader.Reader) (*Fragment, error) {
var fragment Fragment
var err error

fragment.ID, err = reader.ReadUInt32()
fragment.ID, err = reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

fragment.Count, err = reader.ReadUInt32()
fragment.Count, err = reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

fragment.Index, err = reader.ReadUInt32()
fragment.Index, err = reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

fragment.Size, err = reader.ReadUInt32()
fragment.Size, err = reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

fragment.Offset, err = reader.ReadUInt32()
fragment.Offset, err = reader.ReadUInt32(binary.BigEndian)
if err != nil {
return nil, err
}

fragment.Data = reader.ReadRest()
fragment.Data = reader.ReadRemaining()

return &fragment, nil

Expand Down
35 changes: 23 additions & 12 deletions internal/command/reliable/reliable.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package reliable

import (
"encoding/binary"
"michelprogram/photon-parser/internal/context"
"michelprogram/photon-parser/internal/errors"
"michelprogram/photon-parser/internal/reader"
"michelprogram/photon-parser/internal/types"
)

// HEADER_SIZE is the size in bytes of a reliable message header (5 bytes).
const HEADER_SIZE = 5

const READED_HEADER_SIZE = 14

// Type represents a Photon reliable message type.
type Type uint8

Expand Down Expand Up @@ -52,7 +54,7 @@ type Reliable struct {
// or an error if any part of parsing fails.
func Parse(ctx *context.Context, length uint32) (*Reliable, error) {
reliable := Reliable{}
header, err := reliable.parseHeader(ctx.Reader, length)
header, err := reliable.parseHeader(ctx, length)
if err != nil {
return nil, err
}
Expand All @@ -70,7 +72,7 @@ func Parse(ctx *context.Context, length uint32) (*Reliable, error) {
reliable.Parameters = make([]types.Parameter, header.ParameterCount)

for i := 0; i < reliable.ParameterCount; i++ {
err := ctx.Reader.ParameterParser.Parse(ctx.Reader, &reliable.Parameters[i], ctx.Hooks)
err := ctx.Decoders.ParameterParser.Parse(ctx.Reader, &reliable.Parameters[i], ctx.Hooks)
if err != nil {
return nil, err
}
Expand All @@ -80,16 +82,16 @@ func Parse(ctx *context.Context, length uint32) (*Reliable, error) {

}

func (r *Reliable) parseHeader(reader *reader.Reader, length uint32) (Header, error) {
func (r *Reliable) parseHeader(ctx *context.Context, length uint32) (Header, error) {
var err error
var header Header

header.Signature, err = reader.ReadUInt8()
header.Signature, err = ctx.Reader.ReadUInt8()
if err != nil {
return Header{}, err
}

b, err := reader.ReadUInt8()
b, err := ctx.Reader.ReadUInt8()
if err != nil {
return Header{}, err
}
Expand All @@ -99,27 +101,36 @@ func (r *Reliable) parseHeader(reader *reader.Reader, length uint32) (Header, er
switch header.Type {
case OperationResponse, OtherOperationResponse:

header.EventCode, err = reader.ReadUInt8()
header.EventCode, err = ctx.Reader.ReadUInt8()
if err != nil {
return Header{}, err
}

//Return code
reader.ReadInt16LittleEndian()
_, err = ctx.Reader.ReadInt16(binary.LittleEndian)
if err != nil {
return Header{}, err
}

//Read debug msg
reader.ReadByte()
_, err = ctx.Reader.ReadByte()
if err != nil {
return Header{}, err
}
case EventDataType, OperationRequest:
header.EventCode, err = reader.ReadUInt8()
header.EventCode, err = ctx.Reader.ReadUInt8()
if err != nil {
return Header{}, err
}
default:
reader.ReadBytes(int(length) - 14)
_, err = ctx.Reader.ReadBytes(int(length) - READED_HEADER_SIZE)
if err != nil {
return Header{}, err
}
return header, nil
Comment thread
Michelprogram marked this conversation as resolved.
}

header.ParameterCount, err = reader.Options.ReliableHeaderParameterCount.Count(reader)
header.ParameterCount, err = ctx.Decoders.ReliableHeaderParameterCount.Count(ctx.Reader)
if err != nil {
return Header{}, err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/command/reliable/reliable_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package reliable_test

import (
"encoding/binary"
"log"
"michelprogram/photon-parser/internal/command/reliable"
"michelprogram/photon-parser/internal/context"
Expand All @@ -15,11 +14,11 @@ func TestReliableParsing(t *testing.T) {
payload := []byte{0xf3, 0x4, 0x1, 0x0, 0x29, 0x0, 0x69, 0x0, 0x4, 0x6c, 0xcb, 0x1,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 0x3d, 0x71, 0x24, 0x69, 0x1, 0x96, 0xbd, 0x53, 0x25, 0x66, 0x47, 0x43, 0x19, 0xf2, 0x26, 0x6c, 0x8, 0xd8, 0xa9, 0xfd, 0x9a, 0xb5, 0x35, 0xc1, 0x27, 0x62, 0x0, 0x28, 0x79, 0x0, 0xa, 0x6b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x1f, 0xb, 0x26, 0x15, 0x97, 0xb, 0xab, 0x0, 0x0, 0x0, 0x0, 0x2b, 0x79, 0x0, 0xe, 0x6b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, 0x5e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x33, 0x73, 0x0, 0x0, 0x35, 0x62, 0x0, 0x36, 0x62, 0x0, 0x37, 0x79, 0x0, 0x7, 0x6b, 0x0, 0xc, 0xff, 0xff, 0x0, 0x33, 0x0, 0xaf, 0x0, 0xf7, 0xff, 0xff, 0x1, 0x43, 0x38, 0x62, 0x4, 0x39, 0x62, 0xc, 0x3f, 0x69, 0x0, 0x0, 0x0, 0x0, 0xfc, 0x6b, 0x0, 0x1d}

ctx := &context.Context{
Reader: reader.NewReader(payload, reader.Options{
Reader: reader.NewReader(payload),
Decoders: context.Decoders{
ParameterParser: &v16.Parameter{},
ReliableHeaderParameterCount: &v16.ReliableHeaderParameterCountV16{},
BinaryOrder: binary.BigEndian,
}),
},
}
sd, err := reliable.Parse(ctx, 0)

Expand Down
4 changes: 3 additions & 1 deletion internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ type Context struct {
Reader *reader.Reader
Assembler *assembler.Assembler
Hooks *hooks.Hooks
Decoders Decoders
}

func NewContext(reader *reader.Reader, assembler *assembler.Assembler, hooks *hooks.Hooks) *Context {
func NewContext(reader *reader.Reader, assembler *assembler.Assembler, hooks *hooks.Hooks, decoders Decoders) *Context {
return &Context{
Reader: reader,
Assembler: assembler,
Hooks: hooks,
Decoders: decoders,
}
}
25 changes: 25 additions & 0 deletions internal/context/decoders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package context

import (
"michelprogram/photon-parser/internal/hooks"
"michelprogram/photon-parser/internal/reader"
"michelprogram/photon-parser/internal/types"
)

// ParameterParser is implemented by each protocol-version parameters package
// (v16, v18).
// It is wired once at Parser construction so the hot path
type ParameterParser interface {
Parse(*reader.Reader, *types.Parameter, *hooks.Hooks) error
}
// ReliableHeaderParameterCount is implemented by each protocol-version reliable header parameter count package
// (v16, v18).
// It is used to count the number of parameters in a reliable header.
type ReliableHeaderParameterCount interface {
Count(*reader.Reader) (int, error)
}

type Decoders struct {
ParameterParser ParameterParser
ReliableHeaderParameterCount ReliableHeaderParameterCount
}
14 changes: 14 additions & 0 deletions internal/errors/erros.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@ import "errors"

var HeaderSize = errors.New("header size too low")
var EncryptedPacket = errors.New("packet is encrypted or unknown: unexpected signature byte")
var NotEnoughBytesInt8 = errors.New("not enough bytes to read int8")
var NotEnoughBytesUInt8 = errors.New("not enough bytes to read uint8")
var NotEnoughBytesInt16 = errors.New("not enough bytes to read int16")
var NotEnoughBytesUInt16 = errors.New("not enough bytes to read uint16")
var NotEnoughBytesInt32 = errors.New("not enough bytes to read int32")
var NotEnoughBytesUInt32 = errors.New("not enough bytes to read uint32")
var NotEnoughBytesInt64 = errors.New("not enough bytes to read int64")
var NotEnoughBytesUInt64 = errors.New("not enough bytes to read uint64")
var NotEnoughBytesFloat32 = errors.New("not enough bytes to read float32")
var NotEnoughBytesFloat64 = errors.New("not enough bytes to read float64")
var InvalidBooleanValue = errors.New("invalid value for boolean: (expected 0 or 1)")
var NotEnoughBytesString = errors.New("not enough bytes to read string")
var NotEnoughBytesByte = errors.New("not enough bytes to read byte")
var NotEnoughBytesBytes = errors.New("not enough bytes to read []byte")
Loading
Loading