当前位置: 首页>>代码示例>>Golang>>正文


Golang xio.PacketReader类代码示例

本文整理汇总了Golang中github.com/spinlock/xserver/pkg/xserver/xio.PacketReader的典型用法代码示例。如果您正苦于以下问题:Golang PacketReader类的具体用法?Golang PacketReader怎么用?Golang PacketReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PacketReader类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseFlowErrorRequest

func parseFlowErrorRequest(r *xio.PacketReader) (*flowErrorRequest, error) {
	var err error
	fid := uint64(0)
	if fid, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flowerror.read fid")
	}
	return &flowErrorRequest{fid}, nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:8,代码来源:request.go

示例2: parseFlowRequestSlice

func parseFlowRequestSlice(r *xio.PacketReader) (*flowRequestSlice, error) {
	var err error
	flags := uint8(0)
	if flags, err = r.Read8(); err != nil {
		return nil, errors.New("flow.read flags")
	}
	data := r.Bytes()
	return &flowRequestSlice{flags, data}, nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:9,代码来源:request.go

示例3: OnRawMessage

func (h *streamHandler) OnRawMessage(code uint8, r *xio.PacketReader) error {
	if h.fw.closed {
		return errors.New("stream.onRawMessage.closed")
	}
	if flag, err := r.Read16(); err != nil {
		return errors.New("stream.onRawMessage.read flag")
	} else if flag != 0x22 {
		return errors.New("stream.onRawMessage.unknown flag")
	}
	return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:11,代码来源:stream.go

示例4: handleMessage

func handleMessage(h messageHandler, r *xio.PacketReader) error {
	if code, err := r.Read8(); err != nil {
		return errors.New("message.read code")
	} else {
		switch code {
		default:
			return h.OnRawMessage(code, r)
		case 0x11:
			if err := r.Skip(5); err != nil {
				return errors.New("message.skip useless")
			}
			return handleAmfMessage(h, amf0.NewReader(r), true)
		case 0x14:
			if err := r.Skip(4); err != nil {
				return errors.New("message.skip useless")
			}
			return handleAmfMessage(h, amf0.NewReader(r), true)
		case 0x0f:
			if err := r.Skip(5); err != nil {
				return errors.New("message.skip useless")
			}
			return handleAmfMessage(h, amf0.NewReader(r), false)
		}
	}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:25,代码来源:message.go

示例5: parseFlowAckRequest

func parseFlowAckRequest(r *xio.PacketReader) (*flowAckRequest, error) {
	var err error
	fid := uint64(0)
	if fid, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flowack.read fid")
	}
	cnt := uint64(0)
	if cnt, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flowack.read cnt")
	}
	var ack *flowAck
	if ack, err = parseFlowAck(r); err != nil {
		return nil, errors.New("flowack.read ack")
	}
	return &flowAckRequest{fid, cnt, ack}, nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:16,代码来源:request.go

示例6: OnRawMessage

func (h *connHandler) OnRawMessage(code uint8, r *xio.PacketReader) error {
	if h.fw.closed {
		return errors.New("conn.onRawMessage.closed")
	}
	if flag, err := r.Read16(); err != nil {
		return errors.New("conn.onRawMessage.read flag")
	} else if flag != 0x03 {
		return errors.New("conn.onRawMessage.unkonwn flag")
	}
	if sid, err := r.Read32(); err != nil {
		return errors.New("conn.onRawMessage.read sid")
	} else if sid != 0 {
		if err := h.newSetBufferTime(sid); err != nil {
			return errors.New("conn.onRawMessage.setbuffertime response")
		}
	}
	return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:18,代码来源:conn.go

示例7: ParseRequestMessage

func ParseRequestMessage(r *xio.PacketReader) (*RequestMessage, error) {
	var err error
	code := uint8(0)
	if code, err = r.Read8(); err != nil {
		return nil, errors.New("message.read code")
	} else if code == 0xff {
		return nil, EOP
	}
	var size uint16
	if size, err = r.Read16(); err != nil {
		return nil, errors.New("message.read size")
	}
	rlen := r.Len()
	mlen := int(size)
	if rlen < mlen {
		return nil, errors.New("message.bad content length")
	} else {
		data := r.Bytes()[:mlen]
		if err := r.Skip(mlen); err != nil {
			return nil, errors.New("message.skip forward")
		}
		return &RequestMessage{code, xio.NewPacketReader(data)}, nil
	}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:24,代码来源:request.go

示例8: handle

func (h *Handshake) handle(r *xio.PacketReader) (*packet, error) {
	if marker, err := r.Read8(); err != nil {
		return nil, errors.New("packet.read marker")
	} else {
		if _, err := r.Read16(); err != nil {
			return nil, errors.New("packet.read time")
		}
		if marker != 0x0b {
			counts.Count("handshake.marker.unknown", 1)
			return nil, errors.New(fmt.Sprintf("packet.unknown marker = 0x%02x", marker))
		}
	}
	if msg, err := rtmfp.ParseRequestMessage(r); err != nil {
		return nil, err
	} else {
		switch msg.Code {
		default:
			counts.Count("handshake.code.unknown", 1)
			return nil, errors.New(fmt.Sprintf("message.unknown code = 0x%02x", msg.Code))
		case 0x30:
			if rsp, err := h.handleHello(msg.PacketReader); err != nil {
				counts.Count("handshake.hello.error", 1)
				return nil, err
			} else {
				return &packet{0, rsp}, nil
			}
		case 0x38:
			if rsp, yid, err := h.handleAssign(msg.PacketReader); err != nil {
				counts.Count("handshake.assign.error", 1)
				return nil, err
			} else {
				return &packet{yid, rsp}, nil
			}
		}
	}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:36,代码来源:handshake.go

示例9: parseFlowAck

func parseFlowAck(r *xio.PacketReader) (*flowAck, error) {
	if stage, err := r.Read7BitValue64(); err != nil {
		return nil, err
	} else {
		ack := newFlowAck(stage)
		var beg, end uint64
		for r.Len() != 0 {
			if beg, err = r.Read7BitValue64(); err != nil {
				return nil, err
			}
			if end, err = r.Read7BitValue64(); err != nil {
				return nil, err
			}
			beg = beg + stage + 2
			end = end + beg
			ack.AddRange(beg, end)
			stage = end
		}
		return ack, nil
	}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:21,代码来源:flowack.go

示例10: handle

func (s *Session) handle(r *xio.PacketReader) error {
	if marker, err := r.Read8(); err != nil {
		return errors.New("packet.read marker")
	} else {
		if s.stmptime, err = r.Read16(); err != nil {
			return errors.New("packet.read time")
		}
		switch marker | 0xf0 {
		default:
			counts.Count("session.marker.unknown", 1)
			return errors.New(fmt.Sprintf("packet.unknown marker = 0x%02x", marker))
		case 0xfd:
			if _, err = r.Read16(); err != nil {
				return errors.New("packet.read ping time")
			}
		case 0xf9:
		}
	}

	msglist := list.New()
	for r.Len() != 0 {
		if msg, err := rtmfp.ParseRequestMessage(r); err != nil {
			if err != rtmfp.EOP {
				return err
			}
			break
		} else {
			msglist.PushBack(msg)
		}
	}

	var lastreq *flowRequest = nil
	for e := msglist.Front(); e != nil; e = e.Next() {
		msg := e.Value.(*rtmfp.RequestMessage)
		if msg.Code != 0x11 && lastreq != nil {
			if err := s.handleFlowRequest(lastreq); err != nil {
				return err
			}
			lastreq = nil
		}
		switch msg.Code {
		default:
			s.Close()
			counts.Count("session.code.unknown", 1)
			return errors.New(fmt.Sprintf("message.close code = 0x%02x", msg.Code))
		case 0x4c:
			s.Close()
			counts.Count("session.code.close", 1)
			return nil
		case 0x01:
			s.send(newKeepAliveResponse(true))
		case 0x41:
		case 0x5e:
			if req, err := parseFlowErrorRequest(msg.PacketReader); err != nil {
				counts.Count("session.parse5e.error", 1)
				return err
			} else if fw := s.writers[req.fid]; fw != nil {
				fw.reader.handler.OnClose()
			} else {
				xlog.OutLog.Printf("[session]: xid = %d, writer.fid = %d, flow not found 0x5e\n", s.xid, req.fid)
			}
		case 0x51:
			if req, err := parseFlowAckRequest(msg.PacketReader); err != nil {
				counts.Count("session.parse51.error", 1)
				return err
			} else if fw := s.writers[req.fid]; fw != nil {
				fw.CommitAck(req.cnt, req.ack)
			} else {
				xlog.OutLog.Printf("[session]: xid = %d, writer.fid = %d, flow not found 0x51\n", s.xid, req.fid)
			}
		case 0x10:
			if req, err := parseFlowRequest(msg.PacketReader); err != nil {
				counts.Count("session.parse10.error", 1)
				return err
			} else {
				lastreq = req
			}
		case 0x11:
			if req, err := parseFlowRequestSlice(msg.PacketReader); err != nil {
				counts.Count("session.parse11.error", 1)
				return err
			} else if lastreq != nil {
				lastreq.AddSlice(req)
			} else {
				xlog.OutLog.Printf("[session]: xid = %d, not following message\n", s.xid)
			}
		}
	}
	if lastreq != nil {
		return s.handleFlowRequest(lastreq)
	}
	return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:93,代码来源:session.go

示例11: parseFlowRequest

func parseFlowRequest(r *xio.PacketReader) (*flowRequest, error) {
	var err error
	flags := uint8(0)
	if flags, err = r.Read8(); err != nil {
		return nil, errors.New("flow.read flags")
	}
	fid := uint64(0)
	if fid, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flow.read fid")
	}
	stage, delta := uint64(0), uint64(0)
	if stage, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flow.read stage")
	}
	if delta, err = r.Read7BitValue64(); err != nil {
		return nil, errors.New("flow.read delta")
	}
	signature := ""
	if (flags & flagsHeader) != 0 {
		if signature, err = r.ReadString8(); err != nil {
			return nil, errors.New("flow.read signature")
		}
		for {
			if size, err := r.Read8(); err != nil {
				return nil, errors.New("flow.read header content size")
			} else if size == 0 {
				break
			} else if n := int(size); n > r.Len() {
				return nil, errors.New("flows.too big header content size")
			} else if err = r.Skip(n); err != nil {
				return nil, errors.New("flows.skip header")
			}
		}
	}
	data := r.Bytes()
	req := &flowRequest{}
	req.fid = fid
	req.signature = signature
	req.stage = stage
	req.stageack = stage - delta
	req.slices = make([]*flowRequestSlice, 0, 4)
	req.AddSlice(&flowRequestSlice{flags, data})
	return req, nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:44,代码来源:request.go


注:本文中的github.com/spinlock/xserver/pkg/xserver/xio.PacketReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。