github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/object/service-delete-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 DeleteService = deleteService{ 13 Service: service.New("urn:giti:object.protocol:service:delete", "", protocol.ServiceStatePreAlpha, 1587282740). 14 SetDetail(protocol.LanguageEnglish, "Delete Object", 15 `Delete 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 delete object history or indexes associate to it!`, 18 []string{}). 19 SetAuthorization(protocol.CRUDDelete, protocol.UserTypeApp).Expired(0, ""), 20 } 21 22 type deleteService struct { 23 service.Service 24 } 25 26 func (ser *deleteService) DoSRPC(req DeleteRequest) (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 delete(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 deleteRequest interface { 46 RequestType() RequestType 47 ObjectID() [32]byte 48 ObjectStructureID() uint64 49 } 50 51 /* 52 Service Request 53 */ 54 55 // DeleteRequest is request structure of Delete() 56 type DeleteRequest struct { 57 requestType RequestType 58 objectID [32]byte 59 objectStructureID uint64 60 } 61 62 // methods to implements deleteRequest interface 63 func (req *DeleteRequest) RequestType() RequestType { return req.requestType } 64 func (req *DeleteRequest) ObjectID() [32]byte { return req.objectID } 65 func (req *DeleteRequest) ObjectStructureID() uint64 { return req.objectStructureID } 66 func (req *DeleteRequest) SetRequestType(rt RequestType) { req.requestType = rt } 67 func (req *DeleteRequest) SetObjectID(id [32]byte) { req.objectID = id } 68 func (req *DeleteRequest) SetObjectStructureID(sID uint64) { req.objectStructureID = sID } 69 70 // methods to implements protocol.Syllab interface 71 func (req *DeleteRequest) CheckSyllab(payload []byte) (err protocol.Error) { 72 if len(payload) < int(req.LenOfSyllabStack()) { 73 err = syllab.ErrShortArrayDecode 74 } 75 return 76 } 77 func (req *DeleteRequest) 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 *DeleteRequest) 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 *DeleteRequest) LenAsSyllab() uint64 { return 41 } 90 func (req *DeleteRequest) LenOfSyllabStack() uint32 { return 41 } 91 func (req *DeleteRequest) LenOfSyllabHeap() (ln uint32) { return } 92 93 type deleteRequestSyllab []byte 94 95 // methods to implements deleteRequest interface 96 func (req deleteRequestSyllab) RequestType() RequestType { return RequestType(syllab.GetUInt8(req, 0)) } 97 func (req deleteRequestSyllab) ObjectID() (objectID [32]byte) { copy(objectID[:], req[1:]); return } 98 func (req deleteRequestSyllab) ObjectStructureID() (osID uint64) { return syllab.GetUInt64(req, 33) } 99 func (req deleteRequestSyllab) SetRequestType(rt RequestType) { syllab.SetUInt8(req, 0, uint8(rt)) } 100 101 // methods to implements protocol.Syllab interface 102 func (req deleteRequestSyllab) CheckSyllab(payload []byte) (err protocol.Error) { 103 if len(req) < int(req.LenOfSyllabStack()) { 104 err = syllab.ErrShortArrayDecode 105 } 106 return 107 } 108 func (req deleteRequestSyllab) FromSyllab(payload []byte, stackIndex uint32) { 109 // err = ErrSourceNotChangeable 110 } 111 func (req deleteRequestSyllab) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) { 112 copy(payload[stackIndex:], req) 113 return heapIndex 114 } 115 func (req deleteRequestSyllab) LenAsSyllab() uint64 { return 41 } 116 func (req deleteRequestSyllab) LenOfSyllabStack() uint32 { return 41 } 117 func (req deleteRequestSyllab) LenOfSyllabHeap() (ln uint32) { return }