github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/object/service-wipe-sdk.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package object
     4  
     5  import (
     6  	"../protocol"
     7  	"../service"
     8  	"../srpc"
     9  	"../syllab"
    10  )
    11  
    12  var WipeService = wipeService{
    13  	Service: service.New("urn:giti:object.protocol:service:wipe", "", protocol.ServiceStatePreAlpha, 1587282740).
    14  		SetDetail(protocol.LanguageEnglish, "Wipe Object",
    15  			`Wipe specific object by given ID in all cluster!
    16  We don't suggest use this service, due to we strongly suggest think about data as immutable entity(stream and time)
    17  It won't wipe object history or indexes associate to it!`,
    18  			[]string{}).
    19  		SetAuthorization(protocol.CRUDDelete, protocol.UserTypeApp).Expired(0, ""),
    20  }
    21  
    22  type wipeService struct {
    23  	service.Service
    24  }
    25  
    26  func (ser *wipeService) DoSRPC(req WipeRequest) (err protocol.Error) {
    27  	var node protocol.ApplicationNode
    28  	node, err = protocol.App.GetNodeByObjectID(req.objectID)
    29  	if err != nil {
    30  		return
    31  	}
    32  
    33  	if node.Status() == protocol.ApplicationStateLocalNode {
    34  		return wipe(req)
    35  	}
    36  
    37  	_, err = srpc.HandleOutcomeRequest(node.Conn(), ser, &req)
    38  	return
    39  }
    40  
    41  /*
    42  	Service request and response shape
    43  */
    44  
    45  type wipeRequest interface {
    46  	RequestType() RequestType
    47  	ObjectID() [32]byte
    48  	ObjectStructureID() uint64
    49  }
    50  
    51  /*
    52  	Service Request
    53  */
    54  
    55  // WipeRequest is request structure of Wipe()
    56  type WipeRequest struct {
    57  	requestType       RequestType
    58  	objectID          [32]byte
    59  	objectStructureID uint64
    60  }
    61  
    62  // methods to implements wipeRequest interface
    63  func (req *WipeRequest) RequestType() RequestType        { return req.requestType }
    64  func (req *WipeRequest) ObjectID() [32]byte              { return req.objectID }
    65  func (req *WipeRequest) ObjectStructureID() uint64       { return req.objectStructureID }
    66  func (req *WipeRequest) SetRequestType(rt RequestType)   { req.requestType = rt }
    67  func (req *WipeRequest) SetObjectID(id [32]byte)         { req.objectID = id }
    68  func (req *WipeRequest) SetObjectStructureID(sID uint64) { req.objectStructureID = sID }
    69  
    70  // methods to implements protocol.Syllab interface
    71  func (req *WipeRequest) CheckSyllab(payload []byte) (err protocol.Error) {
    72  	if len(payload) < int(req.LenOfSyllabStack()) {
    73  		err = syllab.ErrShortArrayDecode
    74  	}
    75  	return
    76  }
    77  func (req *WipeRequest) FromSyllab(payload []byte, stackIndex uint32) {
    78  	req.requestType = RequestType(syllab.GetUInt8(payload, 0))
    79  	copy(req.objectID[:], payload[1:])
    80  	req.objectStructureID = syllab.GetUInt64(payload, 33)
    81  	return
    82  }
    83  func (req *WipeRequest) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) {
    84  	syllab.SetUInt8(payload, 0, uint8(req.requestType))
    85  	copy(payload[1:], req.objectID[:])
    86  	syllab.SetUInt64(payload, 33, req.objectStructureID)
    87  	return heapIndex
    88  }
    89  func (req *WipeRequest) LenAsSyllab() uint64          { return 41 }
    90  func (req *WipeRequest) LenOfSyllabStack() uint32     { return 41 }
    91  func (req *WipeRequest) LenOfSyllabHeap() (ln uint32) { return }
    92  
    93  type wipeRequestSyllab []byte
    94  
    95  // methods to implements wipeRequest interface
    96  func (req wipeRequestSyllab) RequestType() RequestType         { return RequestType(syllab.GetUInt8(req, 0)) }
    97  func (req wipeRequestSyllab) ObjectID() (objectID [32]byte)    { copy(objectID[:], req[1:]); return }
    98  func (req wipeRequestSyllab) ObjectStructureID() (osID uint64) { return syllab.GetUInt64(req, 33) }
    99  func (req wipeRequestSyllab) SetRequestType(rt RequestType)    { syllab.SetUInt8(req, 0, uint8(rt)) }
   100  
   101  // methods to implements protocol.Syllab interface
   102  func (req wipeRequestSyllab) CheckSyllab(payload []byte) (err protocol.Error) {
   103  	if len(req) < int(req.LenOfSyllabStack()) {
   104  		err = syllab.ErrShortArrayDecode
   105  	}
   106  	return
   107  }
   108  func (req wipeRequestSyllab) FromSyllab(payload []byte, stackIndex uint32) {
   109  	// err = ErrSourceNotChangeable
   110  }
   111  func (req wipeRequestSyllab) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) {
   112  	copy(payload[stackIndex:], req)
   113  	return heapIndex
   114  }
   115  func (req wipeRequestSyllab) LenAsSyllab() uint64          { return 41 }
   116  func (req wipeRequestSyllab) LenOfSyllabStack() uint32     { return 41 }
   117  func (req wipeRequestSyllab) LenOfSyllabHeap() (ln uint32) { return }