MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / Encode

Method Encode

consensus/wal.go:300–329  ·  view source on GitHub ↗

Encode writes the custom encoding of v to the stream. It returns an error if the encoded size of v is greater than 1MB. Any error encountered during the write is also returned.

(v *TimedWALMessage)

Source from the content-addressed store, hash-verified

298// the encoded size of v is greater than 1MB. Any error encountered
299// during the write is also returned.
300func (enc *WALEncoder) Encode(v *TimedWALMessage) error {
301 pbMsg, err := WALToProto(v.Msg)
302 if err != nil {
303 return err
304 }
305 pv := tmcons.TimedWALMessage{
306 Time: v.Time,
307 Msg: pbMsg,
308 }
309
310 data, err := proto.Marshal(&pv)
311 if err != nil {
312 panic(fmt.Errorf("encode timed wall message failure: %w", err))
313 }
314
315 crc := crc32.Checksum(data, crc32c)
316 length := uint32(len(data))
317 if length > maxMsgSizeBytes {
318 return fmt.Errorf("msg is too big: %d bytes, max: %d bytes", length, maxMsgSizeBytes)
319 }
320 totalLength := 8 + int(length)
321
322 msg := make([]byte, totalLength)
323 binary.BigEndian.PutUint32(msg[0:4], crc)
324 binary.BigEndian.PutUint32(msg[4:8], length)
325 copy(msg[8:], data)
326
327 _, err = enc.wr.Write(msg)
328 return err
329}
330
331// IsDataCorruptionError returns true if data has been corrupted inside WAL.
332func IsDataCorruptionError(err error) bool {

Callers 14

mainFunction · 0.95
FuzzFunction · 0.95
TestWALEncoderDecoderFunction · 0.95
benchmarkWalDecodeFunction · 0.95
EncodeArmorFunction · 0.45
SignMethod · 0.45
PubKeyMethod · 0.45
genPrivKeyFunction · 0.45
GenPrivKeyFromSecretFunction · 0.45
rawURIRequestFunction · 0.45
CallMethod · 0.45
WriteMethod · 0.45

Calls 3

WALToProtoFunction · 0.70
WriteMethod · 0.65
MarshalMethod · 0.45

Tested by 3

TestWALEncoderDecoderFunction · 0.76
benchmarkWalDecodeFunction · 0.76
rawURIRequestFunction · 0.36