本文整理匯總了Golang中github.com/ikravets/errs.PassE函數的典型用法代碼示例。如果您正苦於以下問題:Golang PassE函數的具體用法?Golang PassE怎麽用?Golang PassE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了PassE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteMessage
func WriteMessage(w io.Writer, m Message) (err error) {
defer errs.PassE(&err)
errs.CheckE(m.encodePayload())
var mt MessageType
switch m.(type) {
case *MessageDebug:
mt = TypeDebug
case *MessageLoginAccepted:
mt = TypeLoginAccepted
case *MessageLoginRejected:
mt = TypeLoginRejected
case *MessageSequencedData:
mt = TypeSequencedData
case *MessageHeartbeat:
mt = TypeHeartbeat
case *MessageEnd:
mt = TypeEnd
case *MessageLoginRequest:
mt = TypeLoginRequest
case *MessageUnsequencedData:
mt = TypeUnsequencedData
case *MessageClientHeartbeat:
mt = TypeClientHeartbeat
case *MessageLogout:
mt = TypeLogout
}
errs.CheckE(m.getCommon().setHeader(mt))
errs.CheckE(binary.Write(w, binary.BigEndian, m.getHeader()))
n, err := w.Write(m.getCommon().Payload)
errs.CheckE(err)
errs.Check(n == len(m.getCommon().Payload))
return
}
示例2: ReadMessage
func ReadMessage(r io.Reader) (m Message, err error) {
defer errs.PassE(&err)
var mc MessageCommon
errs.CheckE(binary.Read(r, binary.BigEndian, &mc.Header))
mc.Payload = make([]byte, mc.Header.Length-1)
n, err := r.Read(mc.Payload)
errs.CheckE(err)
errs.Check(n == len(mc.Payload), n, len(mc.Payload))
switch mc.Header.Type {
case TypeDebug:
m = &MessageDebug{}
case TypeLoginAccepted:
m = &MessageLoginAccepted{}
case TypeLoginRejected:
m = &MessageLoginRejected{}
case TypeSequencedData:
m = &MessageSequencedData{}
case TypeHeartbeat:
m = &MessageHeartbeat{}
case TypeEnd:
m = &MessageEnd{}
case TypeLoginRequest:
m = &MessageLoginRequest{}
case TypeUnsequencedData:
m = &MessageUnsequencedData{}
case TypeClientHeartbeat:
m = &MessageClientHeartbeat{}
case TypeLogout:
m = &MessageLogout{}
}
*m.getCommon() = mc
errs.CheckE(m.decodePayload())
return
}
示例3: SubscribeFromReader
func (s *Subscr) SubscribeFromReader(rd io.Reader) (err error) {
defer errs.PassE(&err)
sc := bufio.NewScanner(rd)
for sc.Scan() {
text := sc.Text()
var v uint64
var b byte
if _, err := fmt.Sscanf(text, "%c%v", &b, &v); err != nil {
_, err = fmt.Sscanf(text, "%v", &v)
errs.CheckE(err)
}
oid := packet.OptionIdFromUint64(v)
if b == 'U' || b == 'u' || b == '!' {
if s.autoSubscribe {
s.stoplist[oid] = struct{}{}
} else {
s.Unsubscribe(oid)
}
} else {
s.Subscribe(oid)
}
}
errs.CheckE(sc.Err())
return
}
示例4: WriteMessageSimple
func (c *conn) WriteMessageSimple(m Message) (err error) {
defer errs.PassE(&err)
c.pw.SyncStart()
errs.CheckE(c.pw.WriteMessage(m))
errs.CheckE(c.pw.Flush())
return
}
示例5: Dump
func (c *Config) Dump() (yamlDoc string, err error) {
defer errs.PassE(&err)
buf, err := yaml.Marshal(c.ast)
errs.CheckE(err)
yamlDoc = string(buf)
return
}
示例6: setHeader
func (mc *MessageCommon) setHeader(Type MessageType) (err error) {
defer errs.PassE(&err)
mc.Header.Type = Type
mc.Header.Length = uint8(MessageLength[Type])
errs.Check(mc.Header.Length != 0)
return
}
示例7: createMoldPacket
func createMoldPacket(startSeqNum, count int) (bs []byte, err error) {
defer errs.PassE(&err)
type moldUDP64 struct {
Session string `struc:"[10]byte"`
SequenceNumber uint64
MessageCount uint16
}
type moldUDP64MessageBlock struct {
MessageLength int16 `struc:"sizeof=Payload"`
Payload []uint8
}
errs.Check(startSeqNum >= 0)
errs.Check(count >= 0 && count < 1000)
mh := moldUDP64{
Session: "00TestSess",
SequenceNumber: uint64(startSeqNum),
MessageCount: uint16(count),
}
var bb bytes.Buffer
errs.CheckE(struc.Pack(&bb, &mh))
for i := 0; i < count; i++ {
mb := moldUDP64MessageBlock{
Payload: generateIttoMessage(startSeqNum + i),
}
errs.CheckE(struc.Pack(&bb, &mb))
}
bs = bb.Bytes()
return
}
示例8: addOne
func (m *memh2pcap) addOne(r io.Reader) (err error) {
defer errs.PassE(&err)
m.data.Reset()
scanner := bufio.NewScanner(r)
for i := 0; scanner.Scan(); i++ {
v, err := strconv.ParseUint(scanner.Text(), 16, 64)
errs.CheckE(err)
line := make([]byte, 8)
binary.LittleEndian.PutUint64(line, v)
if i == 0 {
// skip pseudo header (2 bytes)
line = line[2:]
}
_, err = m.data.Write(line)
errs.CheckE(err)
}
m.sb.Clear()
b, err := m.sb.AppendBytes(m.data.Len())
errs.CheckE(err)
copy(b, m.data.Bytes())
for _, l := range m.layers {
errs.CheckE(l.SerializeTo(m.sb, m.so))
}
ci := gopacket.CaptureInfo{
Timestamp: time.Unix(int64(m.mold.SequenceNumber), 1),
CaptureLength: len(m.sb.Bytes()),
Length: len(m.sb.Bytes()),
}
errs.CheckE(m.pw.WritePacket(ci, m.sb.Bytes()))
m.mold.SequenceNumber++
return
}
示例9: UnmarshalFlag
func (o *optionId) UnmarshalFlag(value string) (err error) {
defer errs.PassE(&err)
v, err := strconv.ParseUint(value, 0, 64)
errs.CheckE(err)
o.OptionId = packet.OptionIdFromUint64(v)
return
}
示例10: ReadRegister
func (_ *efh_toolDevice) ReadRegister(bar int, addr uint64, size int) (value uint64, err error) {
errs.PassE(&err)
v, err := (exec.Command("efh_tool", "read", fmt.Sprint(bar), fmt.Sprintf("%0#16x", addr), fmt.Sprint(size))).Output()
errs.CheckE(err)
_, err = fmt.Sscan(string(v), &value)
return
}
示例11: ReadMessage
func (c *conn) ReadMessage() (m Message, err error) {
defer errs.PassE(&err)
for c.messageReader.N == 0 {
errs.CheckE(c.readBsuHeader())
}
c.rbuf.Reset()
var b [2]byte
var n int
_, err = io.ReadFull(&c.messageReader, b[:])
errs.CheckE(err)
log.Printf("rcv bytes %v", b)
n, err = c.rbuf.Write(b[:])
errs.CheckE(err)
errs.Check(n == len(b))
h := MessageHeader{
Length: uint8(b[0]),
Type: MessageType(b[1]),
}
log.Printf("rcv header %#v", h)
io.CopyN(&c.rbuf, &c.messageReader, int64(h.Length)-2)
f := MessageFactory[h.Type]
errs.Check(f != nil)
m = f()
errs.CheckE(binary.Read(&c.rbuf, binary.LittleEndian, m))
log.Printf("rcv %#v\n", m)
return
}
示例12: PrintMessage
func (s *SimLogger) PrintMessage(m efhMessage) (err error) {
defer errs.PassE(&err)
var bb bytes.Buffer
errs.CheckE(binary.Write(&bb, binary.LittleEndian, m))
if r := bb.Len() % 8; r > 0 {
// pad to multiple of 8 bytes
z := make([]byte, 8)
_, err = bb.Write(z[0 : 8-r])
errs.CheckE(err)
}
for {
var qw uint64
if err := binary.Read(&bb, binary.LittleEndian, &qw); err != nil {
if err == io.EOF {
break
}
errs.CheckE(err)
} else {
s.printfln("DMATOHOST_DATA %016x", qw)
}
}
s.printfln("DMATOHOST_TRAILER 00656e696c616b45")
return
}
示例13: SerializeTo
func (m *IttoMessageSeconds) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
defer errs.PassE(&err)
errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
buf, err := b.AppendBytes(4)
errs.CheckE(err)
binary.BigEndian.PutUint32(buf, m.Second)
return
}
示例14: decodeMach
func decodeMach(data []byte, p gopacket.PacketBuilder) (err error) {
panic("FIXME")
defer errs.PassE(&err)
m := &Mach{}
errs.CheckE(m.DecodeFromBytes(data, p))
p.AddLayer(m)
return p.NextDecoder(m.NextLayerType())
}
示例15: WriteMessage
func (p *packetWriter) WriteMessage(m Message) (err error) {
defer errs.PassE(&err)
m.getCommon().setHeader(m.Type())
errs.CheckE(binary.Write(&p.mb, binary.LittleEndian, m))
p.bh.Count++
errs.Check(p.bh.Count != 0)
return
}