本文整理匯總了Golang中github.com/FactomProject/factomd/common/primitives.Buffer.Write方法的典型用法代碼示例。如果您正苦於以下問題:Golang Buffer.Write方法的具體用法?Golang Buffer.Write怎麽用?Golang Buffer.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/primitives.Buffer
的用法示例。
在下文中一共展示了Buffer.Write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MarshalBinary
func (b *DirectoryBlock) MarshalBinary() (data []byte, err error) {
var buf primitives.Buffer
b.Sort()
b.BuildBodyMR()
count := uint32(len(b.GetDBEntries()))
b.GetHeader().SetBlockCount(count)
data, err = b.GetHeader().MarshalBinary()
if err != nil {
return
}
buf.Write(data)
for i := uint32(0); i < count; i++ {
data, err = b.GetDBEntries()[i].MarshalBinary()
if err != nil {
return
}
buf.Write(data)
}
return buf.DeepCopyBytes(), err
}
示例2: MarshalBinary
func (m *MissingMsg) MarshalBinary() ([]byte, error) {
var buf primitives.Buffer
binary.Write(&buf, binary.BigEndian, m.Type())
t := m.GetTimestamp()
data, err := t.MarshalBinary()
if err != nil {
return nil, err
}
buf.Write(data)
if m.Asking == nil {
m.Asking = primitives.NewHash(constants.ZERO_HASH)
}
data, err = m.Asking.MarshalBinary()
if err != nil {
return nil, err
}
buf.Write(data)
buf.WriteByte(uint8(m.VMIndex))
binary.Write(&buf, binary.BigEndian, m.DBHeight)
binary.Write(&buf, binary.BigEndian, m.SystemHeight)
binary.Write(&buf, binary.BigEndian, uint32(len(m.ProcessListHeight)))
for _, h := range m.ProcessListHeight {
binary.Write(&buf, binary.BigEndian, h)
}
bb := buf.DeepCopyBytes()
return bb, nil
}
示例3: MarshalBinary
func (s FactoidSignature) MarshalBinary() ([]byte, error) {
var out primitives.Buffer
out.Write(s.Signature[:])
return out.DeepCopyBytes(), nil
}
示例4: MarshalCore
func (m *ServerFault) MarshalCore() (data []byte, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Error marshalling Server Fault Core: %v", r)
}
}()
var buf primitives.Buffer
if d, err := m.ServerID.MarshalBinary(); err != nil {
return nil, err
} else {
buf.Write(d)
}
if d, err := m.AuditServerID.MarshalBinary(); err != nil {
return nil, err
} else {
buf.Write(d)
}
buf.WriteByte(m.VMIndex)
binary.Write(&buf, binary.BigEndian, uint32(m.DBHeight))
binary.Write(&buf, binary.BigEndian, uint32(m.Height))
return buf.DeepCopyBytes(), nil
}
示例5: MarshalBinary
func (a RCD_1) MarshalBinary() ([]byte, error) {
var out primitives.Buffer
out.WriteByte(byte(1)) // The First Authorization method
out.Write(a.PublicKey[:])
return out.DeepCopyBytes(), nil
}
示例6: MarshalBinary
func (e *EndOfMinuteEntry) MarshalBinary() (data []byte, err error) {
var buf primitives.Buffer
buf.Write([]byte{e.Type()})
buf.Write([]byte{e.MinuteNumber})
return buf.DeepCopyBytes(), nil
}
示例7: MarshalBinary
func (e *IncreaseServerCount) MarshalBinary() (data []byte, err error) {
var buf primitives.Buffer
buf.Write([]byte{e.Type()})
buf.Write([]byte{e.Amount})
return buf.DeepCopyBytes(), nil
}
示例8: marshalBodyBinary
// marshalBodyBinary returns a serialized binary Entry Block Body
func (e *EBlock) marshalBodyBinary() ([]byte, error) {
buf := new(primitives.Buffer)
for _, v := range e.Body.EBEntries {
buf.Write(v.Bytes())
}
return buf.DeepCopyBytes(), nil
}
示例9: CustomMarshalText
// Marshal to text. Largely a debugging thing.
func (b FBlock) CustomMarshalText() (text []byte, err error) {
var out primitives.Buffer
out.WriteString("Transaction Block\n")
out.WriteString(" ChainID: ")
out.WriteString(hex.EncodeToString(constants.FACTOID_CHAINID))
keyMR := b.GetKeyMR()
out.WriteString("\n KeyMR (NM): ")
out.WriteString(keyMR.String())
if b.BodyMR == nil {
b.BodyMR = new(primitives.Hash)
}
out.WriteString("\n BodyMR: ")
out.WriteString(b.BodyMR.String())
if b.PrevKeyMR == nil {
b.PrevKeyMR = new(primitives.Hash)
}
out.WriteString("\n PrevKeyMR: ")
out.WriteString(b.PrevKeyMR.String())
if b.PrevLedgerKeyMR == nil {
b.PrevLedgerKeyMR = new(primitives.Hash)
}
out.WriteString("\n PrevLedgerKeyMR: ")
out.WriteString(b.PrevLedgerKeyMR.String())
out.WriteString("\n ExchRate: ")
out.WriteString(fmt.Sprintf("%d.%08d fct, %d factoshis", b.ExchRate/100000000, b.ExchRate%100000000, b.ExchRate))
out.WriteString(fmt.Sprintf("\n DBHeight: %v", b.DBHeight))
out.WriteString("\n Period Marks: ")
for _, mark := range b.endOfPeriod {
out.WriteString(fmt.Sprintf("%d ", mark))
}
out.WriteString("\n #Transactions: ")
primitives.WriteNumber32(&out, uint32(len(b.Transactions)))
transdata, err := b.MarshalTrans()
if err != nil {
return nil, err
}
out.WriteString("\n Body Size: ")
primitives.WriteNumber32(&out, uint32(len(transdata)))
out.WriteString("\n\n")
markPeriod := 0
for i, trans := range b.Transactions {
for markPeriod < 10 && i == b.endOfPeriod[markPeriod] {
out.WriteString(fmt.Sprintf("\n End of Minute %d\n\n", markPeriod+1))
markPeriod++
}
txt, err := trans.CustomMarshalText()
if err != nil {
return nil, err
}
out.Write(txt)
}
return out.DeepCopyBytes(), nil
}
示例10: MarshalBinary
func (m *FactoidTransaction) MarshalBinary() (data []byte, err error) {
var buf primitives.Buffer
buf.Write([]byte{m.Type()})
if d, err := m.Transaction.MarshalBinary(); err != nil {
return nil, err
} else {
buf.Write(d)
}
return buf.DeepCopyBytes(), nil
}
示例11: MarshalBinary
// MarshalBinary. 'nuff said
func (a TransAddress) MarshalBinary() ([]byte, error) {
var out primitives.Buffer
err := primitives.EncodeVarInt(&out, a.Amount)
if err != nil {
return nil, err
}
data, err := a.Address.MarshalBinary()
out.Write(data)
return out.DeepCopyBytes(), err
}
示例12: MarshalBinary
func (b *IncreaseBalance) MarshalBinary() ([]byte, error) {
buf := new(primitives.Buffer)
buf.Write(b.ECPubKey[:])
buf.Write(b.TXID.Bytes())
primitives.EncodeVarInt(buf, b.Index)
primitives.EncodeVarInt(buf, b.NumEC)
return buf.DeepCopyBytes(), nil
}
示例13: MarshalForSignature
func (m *RequestBlock) MarshalForSignature() (data []byte, err error) {
var buf primitives.Buffer
buf.Write([]byte{m.Type()})
if d, err := m.Timestamp.MarshalBinary(); err != nil {
return nil, err
} else {
buf.Write(d)
}
//TODO: expand
return buf.DeepCopyBytes(), nil
}
示例14: MarshalBinary
func (e *RemoveFederatedServer) MarshalBinary() (data []byte, err error) {
var buf primitives.Buffer
buf.Write([]byte{e.Type()})
data, err = e.IdentityChainID.MarshalBinary()
if err != nil {
return nil, err
}
buf.Write(data)
binary.Write(&buf, binary.BigEndian, e.DBHeight)
return buf.DeepCopyBytes(), nil
}
示例15: MarshalForSignature
func (m *CommitEntryMsg) MarshalForSignature() (data []byte, err error) {
var buf primitives.Buffer
binary.Write(&buf, binary.BigEndian, m.Type())
data, err = m.CommitEntry.MarshalBinary()
if err != nil {
return nil, err
}
buf.Write(data)
return buf.DeepCopyBytes(), nil
}