* [COMPLIANCE] Update Copyright and License Headers * chore: make gen to generate files with copyright headers * chore: update missed copyright headers --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
// Copyright IBM Corp. 2020, 2025
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package bsr
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/boundary/internal/bsr/internal/is"
|
|
)
|
|
|
|
// EndChunk identifies the end of the chunks in a BSR data file.
|
|
// An EndChunk in a bsr data file is represented as:
|
|
//
|
|
// uint32 length 4 bytes
|
|
// uint32 protocol 4 bytes
|
|
// uint32 chunk_type 4 bytes
|
|
// uint8 direction 1 byte
|
|
// timest timestamp 12 bytes
|
|
// data 0 bytes
|
|
// uint32 crc 4 bytes
|
|
type EndChunk struct {
|
|
*BaseChunk
|
|
}
|
|
|
|
// MarshalData returns an empty byte slice.
|
|
func (c *EndChunk) MarshalData(_ context.Context) ([]byte, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
// NewEnd creates an EndChunk.
|
|
func NewEnd(ctx context.Context, p Protocol, d Direction, t *Timestamp) (*EndChunk, error) {
|
|
const op = "bsr.NewEnd"
|
|
|
|
bc, err := NewBaseChunk(ctx, p, d, t, ChunkEnd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &EndChunk{
|
|
BaseChunk: bc,
|
|
}, nil
|
|
}
|
|
|
|
// DecodeEnd will decode an EndChunk.
|
|
func DecodeEnd(_ context.Context, bc *BaseChunk, data []byte) (Chunk, error) {
|
|
const op = "bsr.DecodeEnd"
|
|
|
|
if is.Nil(bc) {
|
|
return nil, fmt.Errorf("%s: nil base chunk: %w", op, ErrInvalidParameter)
|
|
}
|
|
if bc.Type != ChunkEnd {
|
|
return nil, fmt.Errorf("%s: invalid chunk type %s", op, bc.Type)
|
|
}
|
|
if len(data) != 0 {
|
|
return nil, fmt.Errorf("%s: %w", op, ErrEndChunkNotEmpty)
|
|
}
|
|
return &EndChunk{BaseChunk: bc}, nil
|
|
}
|