本文整理汇总了Golang中github.com/cronosun/buranv1/ares/encoding.Cbor函数的典型用法代码示例。如果您正苦于以下问题:Golang Cbor函数的具体用法?Golang Cbor怎么用?Golang Cbor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Cbor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: directoryGet
func directoryGet(ctx *restContext, dirHash []byte, filename string) (
entry *directoryEntry,
found bool,
status retcode.Status) {
getEntry := &operations.BucketGetIn{
BucketOperation: operations.BucketOperation{
BucketId: ctx.caprica.GlobalDirectoryId(),
},
Key: [][]byte{dirHash, []byte(filename)},
}
var out interface{}
out, status = ctx.execute(getEntry, operations.BucketGet)
if !status.IsOk() {
return
}
if status.Code == retcode.OkNotFound {
return
}
found = true
getEntryReturn := out.(operations.BucketGetOut)
value := getEntryReturn.Value.([][]byte)
var targetHash []byte
err := encoding.Cbor().Decode(value[0], &targetHash)
if err != nil {
status = retcode.NewStatusFmt(retcode.ErrorServer, "Unable to decode hash")
return
}
entry = new(directoryEntry)
entry.targetHash = targetHash
if len(value) == 1 {
// Directory
entry.isDirectory = true
} else {
entry.isDirectory = false
// Mime
var mime string
err := encoding.Cbor().Decode(value[1], &mime)
if err != nil {
status = retcode.NewStatusFmt(retcode.ErrorServer, "Unable to decode mime")
return
}
entry.mimeType = mime
}
status = retcode.NewStatusOk()
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:51,代码来源:dirget.go
示例2: indexDirectory
func (self *directoryBucketInstance) indexDirectory(operation *operations.Put,
state *minos.OperationState,
hash []byte,
directory *directoryStruct) (ret bucket.BucketReturn) {
var status retcode.Status
mimeTypes := directory.mimeEntries
for _, dirEntry := range directory.fileEntries {
key := types.Key{hash, []byte(dirEntry.name)}
cborTargetHash, err := encoding.Cbor().Encode(dirEntry.hashPointer)
if err != nil {
status = retcode.NewStatusFmt(retcode.ErrorServer, "Error cbor encoding: %v",
err)
ret = &operations.GenericReturn{status}
return
}
var value types.Array
if dirEntry.mimePointer == -1 {
// It's a directory
value = types.Array{cborTargetHash}
} else {
mimeEntry := mimeTypes[dirEntry.mimePointer]
cborMimeType, err := encoding.Cbor().Encode(mimeEntry.typeName)
if err != nil {
status = retcode.NewStatusFmt(retcode.ErrorServer, "Error cbor encoding: %v",
err)
ret = &operations.GenericReturn{status}
return
}
value = types.Array{cborTargetHash, cborMimeType}
}
opPut := &operations.Put{
Key: key,
Value: value,
}
putReturn := self.cstore.Op_put(opPut)
if !putReturn.GetCode().IsOk() {
// Error put-ing
ret = &operations.GenericReturn{putReturn.GetStatus()}
return
}
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:48,代码来源:opput.go
示例3: writeInformation
func (self *incubator) writeInformation(state *minos.OperationState,
id string, incState *incubationState) (ret retcode.Status) {
key := self.createInformationKey(state, id)
encodedLength, err := encoding.Cbor().Encode(incState.length)
if err != nil {
ret = retcode.NewStatusError(retcode.ErrorServer, err)
return
}
value := types.Array{incState.hashState, encodedLength}
apiOperation := &operations.Put{
BucketId: self.bucketId,
Key: key,
Value: value,
}
opRet := state.Dispatcher.Perform(state.Context, apiOperation)
if !opRet.GetCode().IsOk() {
// Unable to put
ret = opRet.GetStatus()
return
}
return opRet.GetStatus()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:26,代码来源:incubator.go
示例4: CborArray
func CborArray(payload string, forwarding ForwardingFunction) (data []byte, err error) {
if !strings.HasPrefix(payload, cborArrayPrefix) {
err = errors.New("A cbor array has to start with " + cborArrayPrefix)
return
}
if !strings.HasSuffix(payload, cborArraySuffix) {
err = errors.New("A cbor array has to end with " + cborArraySuffix)
return
}
payload = strings.TrimPrefix(payload, cborArrayPrefix)
payload = strings.TrimSuffix(payload, cborArraySuffix)
splitElements := strings.SplitN(payload, cborArraySeparator, cborArrayMaxElements+1)
if len(splitElements) > cborArrayMaxElements {
err = errors.New("The cbor array can process at max 32 elements. Input has more")
return
}
array := make([][]byte, len(splitElements))
for index, element := range splitElements {
array[index], err = forwarding(element)
if err != nil {
return
}
}
// Now cbor encode that
encodedCbor, err := encoding.Cbor().Encode(array)
if err != nil {
return
}
data = encodedCbor
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:34,代码来源:cbor.go
示例5: PutReceivers
func (self *TypedGetterSetter) PutReceivers() (receivers []bucket.Id, err error) {
binaryValue, err := self.Get(putReceiversKey)
if err != nil {
return
}
if binaryValue == nil || len(binaryValue) == 0 {
return []bucket.Id{}, nil
}
var bucketIdsAsBinaryInterface interface{}
err = encoding.Cbor().Decode(binaryValue, &bucketIdsAsBinaryInterface)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error cbor decoding: %v\n", err))
}
av := bucketIdsAsBinaryInterface.([]interface{})
bucketIds := make([]bucket.Id, len(av))
for index, singleBucket := range av {
typeOf := reflect.TypeOf(singleBucket)
if !reflect.TypeOf([]byte{}).AssignableTo(typeOf) {
return nil, errors.New("Expecting slices of bytes in put receivers")
}
bucketIds[index] = singleBucket.([]byte)
}
return bucketIds, nil
}
开发者ID:cronosun,项目名称:buranv1,代码行数:27,代码来源:typedgettersetter.go
示例6: writeInformation
func (self *public) writeInformation(state *minos.OperationState,
hash []byte, pubState *publicState) (ret retcode.Status) {
key := self.clreatePublicKey(state, hash)
encodedLength, err := encoding.Cbor().Encode(pubState.length)
if err != nil {
ret = retcode.NewStatusError(retcode.ErrorServer, err)
return
}
if pubState.data == nil {
pubState.data = []byte{}
}
value := types.Array{pubState.data, encodedLength}
apiOperation := &operations.Put{
BucketId: self.bucketId,
Key: key,
Value: value,
}
opRet := state.Dispatcher.Perform(state.Context, apiOperation)
if !opRet.GetCode().IsOk() {
// Unable to put
ret = opRet.GetStatus()
return
}
return opRet.GetStatus()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:28,代码来源:public.go
示例7: information
func (self *incubator) information(state *minos.OperationState,
id string) (incState incubationState, ret retcode.Status) {
key := self.createInformationKey(state, id)
apiOperation := &operations.Get{
BucketId: self.bucketId,
Key: key,
}
opRet := state.Dispatcher.Perform(state.Context, apiOperation)
if opRet.GetCode() != retcode.Ok {
// Not found or a different error
ret = opRet.GetStatus()
return
}
// Ok, found it, deserialize
retCast := opRet.(*operations.GetReturn)
value := retCast.Value
incState = incubationState{}
incState.hashState = value[0]
err := encoding.Cbor().Decode(value[1], &incState.length)
if err != nil {
ret = retcode.NewStatusError(retcode.ErrorServer, err)
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:incubator.go
示例8: information
func (self *public) information(state *minos.OperationState,
hash []byte) (pubState publicState, ret retcode.Status) {
key := self.clreatePublicKey(state, hash)
apiOperation := &operations.Get{
BucketId: self.bucketId,
Key: key,
}
opRet := state.Dispatcher.Perform(state.Context, apiOperation)
if opRet.GetCode() != retcode.Ok {
// Not found or a different error
ret = opRet.GetStatus()
return
}
// Ok, found it, deserialize
retCast := opRet.(*operations.GetReturn)
value := retCast.Value
pubState = publicState{}
pubState.data = value[0]
err := encoding.Cbor().Decode(value[1], &pubState.length)
if err != nil {
ret = retcode.NewStatusError(retcode.ErrorServer, err)
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:public.go
示例9: PrepareAndEncode
func (self *EncodableDirectory) PrepareAndEncode() (
data []byte, err error) {
if !self.prepared {
self.prepare()
}
// Entries
var dirEntries []interface{}
for _, srcEntry := range self.Entries {
var mimeValue int16
if srcEntry.TargetIsDirectory {
mimeValue = -1
} else {
mimeValue = self.mimeTypeToArrayEntry[srcEntry.MimeType]
}
targetEntry := []interface{}{mimeValue, srcEntry.TargetHash, srcEntry.Name}
dirEntries = append(dirEntries, targetEntry)
}
topLevelArray := []interface{}{encodableDirectoryMagicNumber,
dirEntries, self.mimeTypes}
data, err = encoding.Cbor().Encode(topLevelArray)
if err != nil {
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:directoryencoder.go
示例10: CborSignedInt
func CborSignedInt(payload string) (data []byte, err error) {
u, err := strconv.ParseInt(payload, 10, 64)
if err != nil {
return
}
return encoding.Cbor().Encode(u)
}
开发者ID:cronosun,项目名称:buranv1,代码行数:8,代码来源:cbor.go
示例11: initializeGlobalDirectoryStore
func (self *capricaStruct) initializeGlobalDirectoryStore() (err error) {
sysstorage := self.buran.SystemStorage()
valuePtr, err := sysstorage.Get(globaldirectory_key)
if err != nil {
return
}
if valuePtr == nil {
// First get the global blob
globalBlobId := self.globalBlobStoreId
if globalBlobId == nil || len(globalBlobId) == 0 {
err = errors.New("The global directory depends on the global blob store. So need " +
"to create that first.")
return
}
var globalBlobIdCbor []byte
globalBlobIdCbor, err = encoding.Cbor().Encode(globalBlobId)
if err != nil {
return
}
// Need to create the global blob store
operation := operations.CreateBucket{
TypeId: bucket.TypeId_Directory,
Metadata: metadata.MemoryMetadata{
"const.forwarder.blob": globalBlobIdCbor,
},
}
// TODO: Real context
context := ares.Context{
UserId: user.Id([]byte("Test")),
}
ret := self.buran.Perform(&context, &operation)
if !ret.GetCode().IsOk() {
// Error
err = errors.New(fmt.Sprintf("Error creating "+
"the global directory: %v", ret.GetText()))
return
}
retCast := ret.(*operations.CreateBucketReturn)
self.globalDirectoryId = retCast.Id
// Store it - so we have the same on next start
err = self.buran.SystemStorage().Put(globaldirectory_key, retCast.Id)
if err != nil {
return
}
} else {
// Already have a global blob store
self.globalDirectoryId = bucket.Id(*valuePtr)
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:53,代码来源:globaldirectory.go
示例12: SetCreator
func (self *TypedGetterSetter) SetCreator(creator user.Id) (err error) {
userIdAsBytes := []byte(creator)
userIdEncoded, err := encoding.Cbor().Encode(userIdAsBytes)
if err != nil {
return
}
err = self.Set(creatorKey, userIdEncoded)
if err != nil {
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:13,代码来源:typedgettersetter.go
示例13: SetTypeId
func (self *TypedGetterSetter) SetTypeId(typeId bucket.TypeId) (err error) {
var typeIdAsUint8 uint8
typeIdAsUint8 = uint8(typeId)
encodedTypeId, err := encoding.Cbor().Encode(typeIdAsUint8)
if err != nil {
return
}
err = self.Set(typeIdKey, encodedTypeId)
if err != nil {
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:13,代码来源:typedgettersetter.go
示例14: Download
func Download(t btesting.T, bucketId typing.BucketId, hash []byte,
writer io.Writer) (entireLength uint64) {
var skip int = 0
var limit int = readerBlockSize
var entireLengthProcessed bool
for {
var err error
skipEncoded := encoding.UIntToUVarInt(uint64(skip))
limitEncoded := encoding.UIntToUVarInt(uint64(limit))
//hash/[HASH]/content/VUI(skip_optional)/VUI(limit_optional)
key := typing.Key{[]byte("hash"), hash, []byte("content"), skipEncoded, limitEncoded}
value := operations.Get(t, bucketId, key, true)
// value = [data, CBOR(entire_length)]
if len(value) != 2 {
t.Errorf("Got invalid get from bucket / expecting 2 elements in value. Have %v",
len(value))
return
}
data := value[0]
// Set entire length
if !entireLengthProcessed {
entireLengthEncoded := value[1]
err = encoding.Cbor().Decode(entireLengthEncoded, &entireLength)
entireLengthProcessed = true
if err != nil {
t.Errorf("Error decoding entire length %v", err)
return
}
}
_, err = writer.Write(data)
if err != nil {
t.Errorf("Unable to write to writer: %v", err)
return
}
skip += readerBlockSize
// Next one? End if we got less than requested or would exceed entire length
if uint64(len(data)) < readerBlockSize || uint64(skip) >= entireLength {
// No, end here
return
}
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:49,代码来源:blob.go
示例15: SetForwarder
func (self *TypedGetterSetter) SetForwarder(constant bool,
key string, bucketId bucket.Id) (err error) {
var bucketIdAsBinary []byte
bucketIdAsBinary = []byte(bucketId)
bucketIdEncoded, err := encoding.Cbor().Encode(bucketIdAsBinary)
if err != nil {
return
}
err = self.Set(generateKeyForForwarder(constant, key), bucketIdEncoded)
if err != nil {
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:16,代码来源:typedgettersetter.go
示例16: decodeToDirectoryStruct
func decodeToDirectoryStruct(data []byte) (
directory directoryStruct, err error) {
var encoded interface{}
err = encoding.Cbor().Decode(data, &encoded)
if err != nil {
return
}
encodedArray, ok := encoded.([]interface{})
if !ok {
err = errors.New("Top level is not a array")
return
}
topLevelLength := len(encodedArray)
if topLevelLength != 3 {
err = errors.New("Expecting 2 entries in the top level array")
return
}
magicNumber, err := encoding.NumberToInt64(encodedArray[0])
if err != nil {
err = errors.New(fmt.Sprintf("Expecting magic number top level array at index 0. %v",
err))
return
}
if magicNumber != directoryStructMagicNumber {
err = errors.New(fmt.Sprintf("Magic number should be %v but is %v",
directoryStructMagicNumber, magicNumber))
}
fileEntries, highestMimePtr, err := decodeToFileEntries(encodedArray[1])
if err != nil {
return
}
directory.fileEntries = fileEntries
mimeEntries, err := decodeMimeEntries(encodedArray[2], highestMimePtr)
if err != nil {
return
}
directory.mimeEntries = mimeEntries
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:47,代码来源:directorydecoder.go
示例17: SetPutReceiver
func SetPutReceiver(t btesting.T, bucketId typing.BucketId, receivers ...typing.BucketId) {
// Now configure bucket "one" to forward the puts to bucket "two"
putReceivers := make([][]byte, len(receivers))
for index, receiver := range receivers {
putReceivers[index] = []byte(receiver)
}
newPutReceiversEncoded, err := encoding.Cbor().Encode(putReceivers)
if err != nil {
t.Errorf("%v", err)
return
}
Put(t, bucketId.ToMetadataBucketId(),
typing.KeyFromStringPanic("system.put_receivers"),
typing.ValueFromInterfacePanic([][]byte{newPutReceiversEncoded}))
}
开发者ID:cronosun,项目名称:buranv1,代码行数:17,代码来源:putforwarding.go
示例18: TypeId
func (self *TypedGetterSetter) TypeId() (typeId bucket.TypeId, err error) {
binaryValue, err := self.Get(typeIdKey)
if err != nil {
return
}
if binaryValue == nil || len(binaryValue) == 0 {
err = errors.New("No type ID stored in metadata")
return
}
var typeIdAsUint8 uint8
err = encoding.Cbor().Decode(binaryValue, &typeIdAsUint8)
if err != nil {
err = errors.New(fmt.Sprintf("Error cbor decoding: %v\n", err))
return
}
return bucket.TypeId(typeIdAsUint8), nil
}
开发者ID:cronosun,项目名称:buranv1,代码行数:18,代码来源:typedgettersetter.go
示例19: SetPutReceivers
func (self *TypedGetterSetter) SetPutReceivers(receivers []bucket.Id) (err error) {
var arrayOfBytes [][]byte
arrayOfBytes = make([][]byte, len(receivers))
for index, receiver := range receivers {
arrayOfBytes[index] = []byte(receiver)
}
encodedArrayOfBytes, err := encoding.Cbor().Encode(arrayOfBytes)
if err != nil {
return
}
err = self.Set(putReceiversKey, encodedArrayOfBytes)
if err != nil {
return
}
return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:18,代码来源:typedgettersetter.go
示例20: Creator
func (self *TypedGetterSetter) Creator() (creator user.Id, err error) {
binaryValue, err := self.Get(creatorKey)
if err != nil {
return
}
if binaryValue == nil || len(binaryValue) == 0 {
err = errors.New("No user ID stored in metadata")
return
}
var userIdAsBytes []byte
err = encoding.Cbor().Decode(binaryValue, &userIdAsBytes)
if err != nil {
err = errors.New(fmt.Sprintf("Error cbor decoding: %v\n", err))
return
}
return user.Id(userIdAsBytes), nil
}
开发者ID:cronosun,项目名称:buranv1,代码行数:19,代码来源:typedgettersetter.go
注:本文中的github.com/cronosun/buranv1/ares/encoding.Cbor函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论