Add request handling and metadata management to Resource struct; introduce methods for request ID, response status, and hashmap access, while removing deprecated IsCompressed method for cleaner code.
This commit is contained in:
@@ -93,6 +93,10 @@ type Resource struct {
|
|||||||
callback func(*Resource)
|
callback func(*Resource)
|
||||||
progressCallback func(*Resource)
|
progressCallback func(*Resource)
|
||||||
readOffset int64
|
readOffset int64
|
||||||
|
requestID []byte
|
||||||
|
isResponse bool
|
||||||
|
hashmap []byte
|
||||||
|
parts [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(data interface{}, autoCompress bool) (*Resource, error) {
|
func New(data interface{}, autoCompress bool) (*Resource, error) {
|
||||||
@@ -220,12 +224,6 @@ func (r *Resource) GetSegments() uint16 {
|
|||||||
return r.segments
|
return r.segments
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) IsCompressed() bool {
|
|
||||||
r.mutex.RLock()
|
|
||||||
defer r.mutex.RUnlock()
|
|
||||||
return r.compressed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Resource) Cancel() {
|
func (r *Resource) Cancel() {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
@@ -422,3 +420,97 @@ func (r *Resource) GetSize() int64 {
|
|||||||
defer r.mutex.RUnlock()
|
defer r.mutex.RUnlock()
|
||||||
return r.dataSize
|
return r.dataSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resource) HasMetadata() bool {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) IsRequest() bool {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.requestID != nil && !r.isResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) IsResponse() bool {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.isResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetRequestID() []byte {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
if r.requestID == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return append([]byte{}, r.requestID...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) SetRequestID(id []byte) {
|
||||||
|
r.mutex.Lock()
|
||||||
|
defer r.mutex.Unlock()
|
||||||
|
if id == nil {
|
||||||
|
r.requestID = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.requestID = append([]byte{}, id...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) SetIsResponse(isResponse bool) {
|
||||||
|
r.mutex.Lock()
|
||||||
|
defer r.mutex.Unlock()
|
||||||
|
r.isResponse = isResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) getHashmap() []byte {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
if r.hashmap == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return append([]byte{}, r.hashmap...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetRandomHash() []byte {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
if r.randomHash == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return append([]byte{}, r.randomHash...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetOriginalHash() []byte {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
if r.originalHash == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return append([]byte{}, r.originalHash...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetSegmentIndex() uint16 {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.segmentIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetTotalSegments() uint16 {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.totalSegments
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) IsEncrypted() bool {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.encrypted
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) IsSplit() bool {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
return r.split
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user