github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/object/service-get-metadata-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 GetMetadataService = getMetadataService{ 13 Service: service.New("urn:giti:object.protocol:service:get-metadata", "", protocol.ServiceStatePreAlpha, 1587282740). 14 SetDetail(protocol.LanguageEnglish, "Get Metadata", 15 `use to get an object by the objectID and structureID! It must send to proper node otherwise get not found error!`, 16 []string{}). 17 SetAuthorization(protocol.CRUDRead, protocol.UserTypeApp).Expired(0, ""), 18 } 19 20 type getMetadataService struct { 21 service.Service 22 } 23 24 func (ser *getMetadataService) DoSRPC(req GetMetadataRequest) (res protocol.ObjectMetadata, err protocol.Error) { 25 var node protocol.ApplicationNode 26 node, err = protocol.App.GetNodeByObjectID(req.objectID) 27 if err != nil { 28 return 29 } 30 31 if node.Status() == protocol.ApplicationStateLocalNode { 32 return getMetadata(&req) 33 } 34 35 var srpcRes srpc.Response 36 srpcRes, err = srpc.HandleOutcomeRequest(node.Conn(), ser, &req) 37 if err != nil { 38 return 39 } 40 res = Metadata(syllab.GetByteArray(srpcRes.Payload(), 0)) 41 return 42 } 43 44 /* 45 Service request and response shape 46 */ 47 48 type getMetadataRequest interface { 49 ObjectID() [32]byte 50 ObjectStructureID() uint64 51 } 52 53 /* 54 Service Request 55 */ 56 57 // GetMetadataRequest is request structure of Object() 58 type GetMetadataRequest struct { 59 objectID [32]byte 60 objectStructureID uint64 61 } 62 63 // methods to implements getRequest interface 64 func (req *GetMetadataRequest) ObjectID() [32]byte { return req.objectID } 65 func (req *GetMetadataRequest) ObjectStructureID() uint64 { return req.objectStructureID } 66 67 // methods to implements protocol.Syllab interface 68 func (req *GetMetadataRequest) CheckSyllab(payload []byte) (err protocol.Error) { 69 if len(payload) < int(req.LenOfSyllabStack()) { 70 err = syllab.ErrShortArrayDecode 71 } 72 return 73 } 74 func (req *GetMetadataRequest) FromSyllab(payload []byte, stackIndex uint32) { 75 copy(req.objectID[:], payload[:]) 76 } 77 func (req *GetMetadataRequest) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) { 78 copy(payload[4:], req.objectID[:]) 79 syllab.SetUInt64(payload, 36, req.objectStructureID) 80 return heapIndex 81 } 82 func (req *GetMetadataRequest) LenAsSyllab() uint64 { return 40 } 83 func (req *GetMetadataRequest) LenOfSyllabStack() uint32 { return 40 } 84 func (req *GetMetadataRequest) LenOfSyllabHeap() (ln uint32) { return }