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


Golang encoding.BinaryMarshaler类代码示例

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


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

示例1: Send

func (s *simpleSender) Send(topic string, value encoding.BinaryMarshaler) error {
	buf, err := value.MarshalBinary()
	if err != nil {
		return err
	}
	return s.p.Produce(topic, nil, buf)
}
开发者ID:h12w,项目名称:kpax,代码行数:7,代码来源:sender.go

示例2: mustMarshal

func mustMarshal(v encoding.BinaryMarshaler) []byte {
	res, err := v.MarshalBinary()
	if err != nil {
		panic(err)
	}
	return res
}
开发者ID:ably-forks,项目名称:flynn,代码行数:7,代码来源:compare_test.go

示例3: Delete

// Delete implements KeyValueStore.
func (l *LevelDB) Delete(key encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	return l.storage.Delete(k, l.writeOpts)
}
开发者ID:gitlabuser,项目名称:prometheus,代码行数:8,代码来源:leveldb.go

示例4: Delete

// Delete implements Batch.
func (b *LevelDBBatch) Delete(key encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	b.batch.Delete(k)
	return nil
}
开发者ID:RMeharg,项目名称:prometheus,代码行数:9,代码来源:leveldb.go

示例5: encodeBinaryMarshaler

func (enc *Encoder) encodeBinaryMarshaler(v encoding.BinaryMarshaler) error {
	b, err := v.MarshalBinary()
	if err != nil {
		return err
	}
	_, errr := enc.w.Write(b)
	return errr
}
开发者ID:castaneai,项目名称:go-binstruct,代码行数:8,代码来源:encoder.go

示例6: sendcmd

func sendcmd(conn io.Writer, m encoding.BinaryMarshaler) {
	if bs, err := m.MarshalBinary(); err != nil {
		log.Fatalln(err)
	} else if !*n {
		if _, err := conn.Write(bs); err != nil {
			log.Fatalln(err)
		}
	} else {
		log.Println("ok", m)
	}
}
开发者ID:Reinaesaya,项目名称:go-cuddlebot,代码行数:11,代码来源:main.go

示例7: Put

// Put implements KeyValueStore.
func (l *LevelDB) Put(key, value encoding.BinaryMarshaler) error {
	k, err := key.MarshalBinary()
	if err != nil {
		return err
	}
	v, err := value.MarshalBinary()
	if err != nil {
		return err
	}
	return l.storage.Put(k, v, l.writeOpts)
}
开发者ID:RMeharg,项目名称:prometheus,代码行数:12,代码来源:leveldb.go

示例8: EncodeLV

// EncodeLV encodes v to a binary format and writes the length-value record to w.
func EncodeLV(w io.Writer, v encoding.BinaryMarshaler) error {
	buf, err := v.MarshalBinary()
	if err != nil {
		return err
	}

	if err := WriteLV(w, buf); err != nil {
		return err
	}
	return nil
}
开发者ID:seiflotfy,项目名称:influxdb,代码行数:12,代码来源:service.go

示例9: Write

func (r *Transceiver) Write(msg encoding.BinaryMarshaler) error {
	packet, err := msg.MarshalBinary()
	if err != nil {
		return err
	}

	if _, err := r.stream.Write(packet); err != nil {
		return err
	}

	return nil
}
开发者ID:yebinMoon,项目名称:cherry,代码行数:12,代码来源:transceiver.go

示例10: copyBinary

func copyBinary(t *testing.T, from encoding.BinaryMarshaler, to encoding.BinaryUnmarshaler) {
	data, err := from.MarshalBinary()
	if err != nil {
		t.Errorf(err.Error())
		return
	}

	err = to.UnmarshalBinary(data)
	if err != nil {
		t.Errorf(err.Error())
		return
	}
}
开发者ID:docwalter,项目名称:bitset,代码行数:13,代码来源:bitset_test.go

示例11: Delete

// Delete implements KeyValueStore.
func (l *LevelDB) Delete(key encoding.BinaryMarshaler) (bool, error) {
	k, err := key.MarshalBinary()
	if err != nil {
		return false, err
	}
	err = l.storage.Delete(k, l.writeOpts)
	if err == leveldb.ErrNotFound {
		return false, nil
	}
	if err != nil {
		return false, err
	}
	return true, nil
}
开发者ID:bluecmd,项目名称:prometheus,代码行数:15,代码来源:leveldb.go

示例12: sendPacket

// sendPacket marshals p according to RFC 4234.
func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error {
	bb, err := m.MarshalBinary()
	if err != nil {
		return fmt.Errorf("marshal2(%#v): binary marshaller failed", err)
	}
	l := uint32(len(bb))
	hdr := []byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}
	debug("send packet %T, len: %v", m, l)
	_, err = w.Write(hdr)
	if err != nil {
		return err
	}
	_, err = w.Write(bb)
	return err
}
开发者ID:marete,项目名称:restic,代码行数:16,代码来源:packet.go

示例13: testMarshalExpect

func testMarshalExpect(t *testing.T, m encoding.BinaryMarshaler, expect []byte) {
	subject, err := m.MarshalBinary()
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("Bytes: %v", subject)
	if len(subject) != len(expect) {
		t.Fatalf("Expected %d bytes, got %d", len(expect), len(subject))
	}
	for i, v := range subject {
		if v != expect[i] {
			t.Fatal("Bytes did not match expected")
		}
	}
}
开发者ID:Reinaesaya,项目名称:go-cuddlebot,代码行数:15,代码来源:msgtype_test.go

示例14: Marshaler

//  Marshaler encodes a encoding.BinaryMarshaler into buffer
func (e *Enc) Marshaler(x encoding.BinaryMarshaler) {
	if e.err != nil {
		return
	}
	if x == nil {
		e.err = errEncode
		return
	}
	var buf []byte
	buf, e.err = x.MarshalBinary()
	if e.err != nil {
		return
	}
	e.ByteSlice(buf)
}
开发者ID:mrkovec,项目名称:encdec,代码行数:16,代码来源:encdec.go

示例15: Get

// Get implements KeyValueStore.
func (l *LevelDB) Get(key encoding.BinaryMarshaler, value encoding.BinaryUnmarshaler) (bool, error) {
	k, err := key.MarshalBinary()
	if err != nil {
		return false, err
	}
	raw, err := l.storage.Get(k, l.readOpts)
	if err == leveldb.ErrNotFound {
		return false, nil
	}
	if err != nil {
		return false, err
	}
	if value == nil {
		return true, nil
	}
	return true, value.UnmarshalBinary(raw)
}
开发者ID:RMeharg,项目名称:prometheus,代码行数:18,代码来源:leveldb.go


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