storj/lib/uplinkc/convert.go

44 lines
1.4 KiB
Go
Raw Normal View History

2019-06-15 12:23:12 +01:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
// #include "uplink_definitions.h"
import "C"
import (
"storj.io/storj/pkg/storj"
)
// newBucketInfo returns a C bucket struct converted from a go bucket struct.
func newBucketInfo(bucket *storj.Bucket) C.BucketInfo {
return C.BucketInfo{
name: C.CString(bucket.Name),
created: C.time_t(bucket.Created.Unix()),
path_cipher: C.uint8_t(bucket.PathCipher),
segment_size: C.uint64_t(bucket.SegmentsSize),
encryption_parameters: convertEncryptionParameters(&bucket.EncryptionParameters),
redundancy_scheme: convertRedundancyScheme(&bucket.RedundancyScheme),
}
}
// convertEncryptionParameters converts Go EncryptionParameters to C.
func convertEncryptionParameters(goParams *storj.EncryptionParameters) C.EncryptionParameters {
return C.EncryptionParameters{
cipher_suite: C.uint8_t(goParams.CipherSuite),
block_size: C.int32_t(goParams.BlockSize),
}
}
// convertRedundancyScheme converts Go RedundancyScheme to C.
func convertRedundancyScheme(scheme *storj.RedundancyScheme) C.RedundancyScheme {
return C.RedundancyScheme{
algorithm: C.uint8_t(scheme.Algorithm),
share_size: C.int32_t(scheme.ShareSize),
required_shares: C.int16_t(scheme.RequiredShares),
repair_shares: C.int16_t(scheme.RepairShares),
optimal_shares: C.int16_t(scheme.OptimalShares),
total_shares: C.int16_t(scheme.TotalShares),
}
}