package trace
import (
)
type timestamp uint64
type batch struct {
time timestamp
gen uint64
data []byte
}
func ( []byte) (batch, uint64, error) {
if len() == 0 {
return batch{}, 0, fmt.Errorf("batch is empty")
}
:= make([]byte, len())
copy(, )
if := tracev2.EventType([0]); == tracev2.EvEndOfGeneration {
if len() != 1 {
return batch{}, 1, fmt.Errorf("unexpected end of generation in batch of size >1")
}
return batch{data: }, 1, nil
}
if := tracev2.EventType([0]); != tracev2.EvEventBatch && != tracev2.EvExperimentalBatch {
return batch{}, 1, fmt.Errorf("expected batch event, got event %d", )
}
:= 1
= [1:]
, , := readUvarint()
if != nil {
return batch{}, uint64( + ), fmt.Errorf("error reading batch gen: %w", )
}
+=
= [:]
_, , = readUvarint()
if != nil {
return batch{}, uint64( + ), fmt.Errorf("error reading batch M ID: %w", )
}
+=
= [:]
, , := readUvarint()
if != nil {
return batch{}, uint64( + ), fmt.Errorf("error reading batch timestamp: %w", )
}
+=
= [:]
, , := readUvarint()
if != nil {
return batch{}, uint64( + ), fmt.Errorf("error reading batch size: %w", )
}
if > tracev2.MaxBatchSize {
return batch{}, uint64( + ), fmt.Errorf("invalid batch size %d, maximum is %d", , tracev2.MaxBatchSize)
}
+=
+= int()
if != len() {
return batch{}, uint64(), fmt.Errorf("expected complete batch")
}
= [:]
return batch{
gen: ,
time: timestamp(),
data: ,
}, uint64(), nil
}